Package dev.oak3.sbs4j
Class DeserializerBuffer
- java.lang.Object
-
- dev.oak3.sbs4j.DeserializerBuffer
-
public class DeserializerBuffer extends java.lang.Object
Deserializing methods- Since:
- 0.1.0
-
-
Constructor Summary
Constructors Constructor Description DeserializerBuffer(byte[] bytes)
Initializes buffer with serialized bytes andByteOrder.LITTLE_ENDIAN
DeserializerBuffer(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-encodedString
DeserializerBuffer(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.ByteBuffer
getBuffer()
Retrieves the backing bufferprotected 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.java.lang.Boolean
readBool()
Reads a Boolean valuebyte[]
readByteArray(int length)
Reads a byte[] from bufferprotected byte[]
readBytes(int length)
Reads a specified number of bytesfloat
readF32()
Reads a float of 32 bits (4 bytes)double
readF64()
Reads a float of 64 bits (8 bytes)int
readI32()
Reads a signed int of 32 bits (4 bytes)long
readI64()
Reads a signed int of 64 bits (8 bytes)java.lang.String
readString()
Reads a String value from bufferjava.math.BigInteger
readU128()
Reads an unsigned int of 128 bits (16 bytes) maxjava.math.BigInteger
readU256()
Reads U256 from bufferlong
readU32()
Reads an unsigned int of 32 bits (4 bytes)java.math.BigInteger
readU512()
Reads U512 from bufferjava.math.BigInteger
readU64()
Reads an unsigned int of 64 bits (8 bytes)byte
readU8()
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-encodedString
to 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-encodedString
to 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 ValueDeserializationException
Reads 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 ValueDeserializationException
Reads a byte from buffer- Returns:
- the byte
- Throws:
ValueDeserializationException
-
readByteArray
public byte[] readByteArray(int length) throws ValueDeserializationException
Reads a byte[] from buffer- Parameters:
length
- the length of the array- Returns:
- the byte array as byte[]
- Throws:
ValueDeserializationException
-
readF32
public float readF32() throws ValueDeserializationException
Reads a float of 32 bits (4 bytes)- Returns:
- the number as a float
- Throws:
ValueDeserializationException
-
readF64
public double readF64() throws ValueDeserializationException
Reads a float of 64 bits (8 bytes)- Returns:
- the number as a double
- Throws:
ValueDeserializationException
-
readI32
public int readI32() throws ValueDeserializationException
Reads a signed int of 32 bits (4 bytes)- Returns:
- the number as an int
- Throws:
ValueDeserializationException
-
readU32
public long readU32() throws ValueDeserializationException
Reads an unsigned int of 32 bits (4 bytes)- Returns:
- the number as a long
- Throws:
ValueDeserializationException
-
readI64
public long readI64() throws ValueDeserializationException
Reads a signed int of 64 bits (8 bytes)- Returns:
- the number as a long
- Throws:
ValueDeserializationException
-
readU64
public java.math.BigInteger readU64() throws ValueDeserializationException
Reads an unsigned int of 64 bits (8 bytes)- Returns:
- the number as a BigInteger
- Throws:
ValueDeserializationException
-
readU128
public java.math.BigInteger readU128() throws ValueDeserializationException
Reads an unsigned int of 128 bits (16 bytes) max- Returns:
- the number as a BigInteger
- Throws:
ValueDeserializationException
-
readU256
public java.math.BigInteger readU256() throws ValueDeserializationException
Reads U256 from buffer- Returns:
- the number as a BigInteger
- Throws:
ValueDeserializationException
-
readU512
public java.math.BigInteger readU512() throws ValueDeserializationException
Reads 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 ValueDeserializationException
Reads 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
-
-