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 a byte arrayDeserializerBuffer(java.lang.String hexString)
Initializes buffer with serialized bytes from hex-encodedString
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.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(byte[] bytes)
Initializes buffer with serialized bytes a byte array- Parameters:
bytes
- byte array to deserialize and read from
-
DeserializerBuffer
public DeserializerBuffer(java.lang.String hexString) throws InvalidByteStringException
Initializes buffer with serialized bytes from hex-encodedString
- Parameters:
hexString
- hex-encodedString
to deserialize and read from- Throws:
InvalidByteStringException
- if the byte string is invalid or can't be parsed
-
-
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()
Reads a byte from buffer- Returns:
- the byte
-
readByteArray
public byte[] readByteArray(int length)
Reads a byte[] from buffer- Parameters:
length
- the length of the array- Returns:
- the byte array as byte[]
-
readF32
public float readF32()
Reads a float of 32 bits (4 bytes)- Returns:
- the number as a float
-
readF64
public double readF64()
Reads a float of 64 bits (8 bytes)- Returns:
- the number as a double
-
readI32
public int readI32()
Reads a signed int of 32 bits (4 bytes)- Returns:
- the number as an int
-
readU32
public long readU32()
Reads an unsigned int of 32 bits (4 bytes)- Returns:
- the number as a long
-
readI64
public long readI64()
Reads a signed int of 64 bits (8 bytes)- Returns:
- the number as a long
-
readU64
public java.math.BigInteger readU64()
Reads an unsigned int of 64 bits (8 bytes)- Returns:
- the number as a BigInteger
-
readU128
public java.math.BigInteger readU128()
Reads an unsigned int of 128 bits (16 bytes) max- Returns:
- the number as a BigInteger
-
readU256
public java.math.BigInteger readU256()
Reads U256 from buffer- Returns:
- the number as a BigInteger
-
readU512
public java.math.BigInteger readU512()
Reads U512 from buffer- Returns:
- the number as a BigInteger
-
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()
Reads a String value from buffer- Returns:
- the String read
-
readBytes
protected byte[] readBytes(int length)
Reads a specified number of bytes- Parameters:
length
- the number of bytes to read- Returns:
- bytes read
-
-