Package dev.oak3.sbs4j
Class DeserializerBuffer
- java.lang.Object
-
- dev.oak3.sbs4j.DeserializerBuffer
-
public class DeserializerBuffer extends java.lang.ObjectDeserializing methods- Since:
- 0.1.0
-
-
Constructor Summary
Constructors Constructor Description DeserializerBuffer(byte[] bytes)Initializes buffer with serialized bytes andByteOrder.LITTLE_ENDIANDeserializerBuffer(byte[] bytes, java.nio.ByteOrder byteOrder)Initializes buffer with serialized bytes and byte orderDeserializerBuffer(java.lang.String hexString)Initializes buffer with serialized bytes from hex-encodedStringDeserializerBuffer(java.lang.String hexString, java.nio.ByteOrder byteOrder)Initializes buffer with serialized bytes from hex-encodedString
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.nio.ByteBuffergetBuffer()Retrieves the backing bufferprotected java.math.BigIntegerreadBigInteger()Larger numeric values (e.g., U128, U256, U512) serialize as one byte of the length of the next number, followed by the two’s complement representation with little-endian byte order.java.lang.BooleanreadBool()Reads a Boolean valuebyte[]readByteArray(int length)Reads a byte[] from bufferprotected byte[]readBytes(int length)Reads a specified number of bytesfloatreadF32()Reads a float of 32 bits (4 bytes)doublereadF64()Reads a float of 64 bits (8 bytes)intreadI32()Reads a signed int of 32 bits (4 bytes)longreadI64()Reads a signed int of 64 bits (8 bytes)java.lang.StringreadString()Reads a String value from bufferjava.math.BigIntegerreadU128()Reads an unsigned int of 128 bits (16 bytes) maxjava.math.BigIntegerreadU256()Reads U256 from bufferlongreadU32()Reads an unsigned int of 32 bits (4 bytes)java.math.BigIntegerreadU512()Reads U512 from bufferjava.math.BigIntegerreadU64()Reads an unsigned int of 64 bits (8 bytes)bytereadU8()Reads a byte from buffer
-
-
-
Constructor Detail
-
DeserializerBuffer
public DeserializerBuffer(java.lang.String hexString)
Initializes buffer with serialized bytes from hex-encodedString- Parameters:
hexString- hex-encodedStringto deserialize and read from
-
DeserializerBuffer
public DeserializerBuffer(java.lang.String hexString, java.nio.ByteOrder byteOrder)Initializes buffer with serialized bytes from hex-encodedString- Parameters:
hexString- hex-encodedStringto deserialize and read frombyteOrder- the byte order to be using
-
DeserializerBuffer
public DeserializerBuffer(byte[] bytes)
Initializes buffer with serialized bytes andByteOrder.LITTLE_ENDIAN- Parameters:
bytes- byte array to deserialize and read from
-
DeserializerBuffer
public DeserializerBuffer(byte[] bytes, java.nio.ByteOrder byteOrder)Initializes buffer with serialized bytes and byte order- Parameters:
bytes- byte array to deserialize and read frombyteOrder- the byte order to be using
-
-
Method Detail
-
readBool
public java.lang.Boolean readBool() throws ValueDeserializationExceptionReads a Boolean value- Returns:
- true if 1, while false if 0
- Throws:
ValueDeserializationException- exception holding information of failure to deserialize a value
-
readU8
public byte readU8() throws ValueDeserializationExceptionReads a byte from buffer- Returns:
- the byte
- Throws:
ValueDeserializationException
-
readByteArray
public byte[] readByteArray(int length) throws ValueDeserializationExceptionReads a byte[] from buffer- Parameters:
length- the length of the array- Returns:
- the byte array as byte[]
- Throws:
ValueDeserializationException
-
readF32
public float readF32() throws ValueDeserializationExceptionReads a float of 32 bits (4 bytes)- Returns:
- the number as a float
- Throws:
ValueDeserializationException
-
readF64
public double readF64() throws ValueDeserializationExceptionReads a float of 64 bits (8 bytes)- Returns:
- the number as a double
- Throws:
ValueDeserializationException
-
readI32
public int readI32() throws ValueDeserializationExceptionReads a signed int of 32 bits (4 bytes)- Returns:
- the number as an int
- Throws:
ValueDeserializationException
-
readU32
public long readU32() throws ValueDeserializationExceptionReads an unsigned int of 32 bits (4 bytes)- Returns:
- the number as a long
- Throws:
ValueDeserializationException
-
readI64
public long readI64() throws ValueDeserializationExceptionReads a signed int of 64 bits (8 bytes)- Returns:
- the number as a long
- Throws:
ValueDeserializationException
-
readU64
public java.math.BigInteger readU64() throws ValueDeserializationExceptionReads an unsigned int of 64 bits (8 bytes)- Returns:
- the number as a BigInteger
- Throws:
ValueDeserializationException
-
readU128
public java.math.BigInteger readU128() throws ValueDeserializationExceptionReads an unsigned int of 128 bits (16 bytes) max- Returns:
- the number as a BigInteger
- Throws:
ValueDeserializationException
-
readU256
public java.math.BigInteger readU256() throws ValueDeserializationExceptionReads U256 from buffer- Returns:
- the number as a BigInteger
- Throws:
ValueDeserializationException
-
readU512
public java.math.BigInteger readU512() throws ValueDeserializationExceptionReads U512 from buffer- Returns:
- the number as a BigInteger
- Throws:
ValueDeserializationException
-
readBigInteger
protected java.math.BigInteger readBigInteger()
Larger numeric values (e.g., U128, U256, U512) serialize as one byte of the length of the next number, followed by the two’s complement representation with little-endian byte order.- Returns:
- the number as a BigInteger
-
readString
public java.lang.String readString() throws ValueDeserializationExceptionReads a String value from buffer- Returns:
- the String read
- Throws:
ValueDeserializationException
-
getBuffer
public java.nio.ByteBuffer getBuffer()
Retrieves the backing buffer- Returns:
- the Deserializer ByteBuffer
-
readBytes
protected byte[] readBytes(int length)
Reads a specified number of bytes- Parameters:
length- the number of bytes to read- Returns:
- bytes read
-
-