Add little endian functionality to Network Element and Factory (#931)

This commit is contained in:
Ben Carman 2019-12-10 08:46:39 -06:00 committed by Chris Stewart
parent 971de61004
commit 69077f8d08
2 changed files with 12 additions and 0 deletions

View file

@ -16,8 +16,14 @@ trait NetworkElement extends Any {
/** The hexadecimal representation of the NetworkElement */
def hex: String = bytes.toHex
/** The hexadecimal representation of the NetworkElement in little endian */
def hexLE: String = bytesLE.toHex
/** The byte representation of the NetworkElement */
def bytes: ByteVector
/** The byte representation of the NetworkElement in little endian */
def bytesLE: ByteVector = bytes.reverse
def logger = BitcoinSLogger.logger
}

View file

@ -12,9 +12,15 @@ abstract class Factory[+T] {
/** Creates a T out of a hex string. */
def fromHex(hex: String): T = fromBytes(BitcoinSUtil.decodeHex(hex))
/** Creates a T out of a hex string in little endian. */
def fromHexLE(hex: String): T = fromBytesLE(BitcoinSUtil.decodeHex(hex))
/** Creates a T out of a sequence of bytes. */
def fromBytes(bytes: ByteVector): T
/** Creates a T out of a sequence of bytes in little endian. */
def fromBytesLE(bytes: ByteVector): T = fromBytes(bytes.reverse)
/** Creates a T out of a sequence of bytes. */
def apply(bytes: ByteVector): T = fromBytes(bytes)