Package dev.oak3.sbs4j
Class SerializerBuffer
- java.lang.Object
-
- dev.oak3.sbs4j.SerializerBuffer
-
public class SerializerBuffer extends java.lang.ObjectSerializing methods- Since:
- 0.1.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.math.BigIntegerMAX_U128static java.math.BigIntegerMAX_U256static java.math.BigIntegerMAX_U512static java.math.BigIntegerMAX_U64static java.math.BigIntegerONEstatic java.math.BigIntegerTWOstatic java.math.BigIntegerZERO
-
Constructor Summary
Constructors Constructor Description SerializerBuffer()Initializes buffer with initial capacity ofINITIAL_CAPACITYin bytes andByteOrder.LITTLE_ENDIANSerializerBuffer(int initialCapacity, java.nio.ByteOrder byteOrder)Initializes buffer with given initial capacity in bytes and byte order.SerializerBuffer(java.nio.ByteOrder byteOrder)Initializes buffer with initial capacity ofINITIAL_CAPACITYand given byte order.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.nio.ByteBuffergetBuffer()Retrieves the backing bufferprotected voidincreaseCapacity(int increaseByteCount)Increases the buffer size and replaces with the new capacity buffer including current buffer databyte[]toByteArray()Gets the full byte array corresponding to serialized dataprotected voidwriteBigInteger(java.math.BigInteger value, int size)Writes a BigInteger/U128-U256-U512 to the value byte buffervoidwriteBool(boolean value)Writes a boolean value to the value byte buffervoidwriteByteArray(byte[] value)Writes a byte array valuevoidwriteF32(float value)Writes a Float/F32 valuevoidwriteF64(double value)Writes a Double/F64 valuevoidwriteI32(int value)Writes an Integer/I32 valuevoidwriteI64(long value)Writes a Long/I64 valuevoidwriteString(java.lang.String value)Writes a String to the value byte buffervoidwriteU128(java.math.BigInteger value)Writes a BigInteger/U128 to the value byte buffervoidwriteU16(short value)Writes a single byte valuevoidwriteU256(java.math.BigInteger value)Writes a BigInteger/U256 to the value byte buffervoidwriteU32(java.lang.Long value)Writes an Unsigned Integer (Long)/U32voidwriteU512(java.math.BigInteger value)Writes a BigInteger/U512 to the value byte buffervoidwriteU64(java.math.BigInteger value)Writes an Unsigned Long (BigInteger)/U64 to the value byte buffervoidwriteU8(byte value)Writes a single byte value
-
-
-
Field Detail
-
ZERO
public static final java.math.BigInteger ZERO
-
ONE
public static final java.math.BigInteger ONE
-
TWO
public static final java.math.BigInteger TWO
-
MAX_U64
public static final java.math.BigInteger MAX_U64
-
MAX_U128
public static final java.math.BigInteger MAX_U128
-
MAX_U256
public static final java.math.BigInteger MAX_U256
-
MAX_U512
public static final java.math.BigInteger MAX_U512
-
-
Constructor Detail
-
SerializerBuffer
public SerializerBuffer()
Initializes buffer with initial capacity ofINITIAL_CAPACITYin bytes andByteOrder.LITTLE_ENDIAN
-
SerializerBuffer
public SerializerBuffer(java.nio.ByteOrder byteOrder)
Initializes buffer with initial capacity ofINITIAL_CAPACITYand given byte order.- Parameters:
byteOrder- the byte order to be using
-
SerializerBuffer
public SerializerBuffer(int initialCapacity, java.nio.ByteOrder byteOrder)Initializes buffer with given initial capacity in bytes and byte order.- Parameters:
initialCapacity- the initial capacity of the bufferbyteOrder- the byte order to be using
-
-
Method Detail
-
writeBool
public void writeBool(boolean value)
Writes a boolean value to the value byte buffer- Parameters:
value- boolean value to serialize
-
writeU8
public void writeU8(byte value)
Writes a single byte value- Parameters:
value- byte value to serialize
-
writeU16
public void writeU16(short value)
Writes a single byte value- Parameters:
value- byte value to serialize
-
writeByteArray
public void writeByteArray(byte[] value)
Writes a byte array value- Parameters:
value- byte array value to serialize
-
writeF32
public void writeF32(float value)
Writes a Float/F32 value- Parameters:
value- F32 value to serialize
-
writeF64
public void writeF64(double value)
Writes a Double/F64 value- Parameters:
value- F64 value to serialize
-
writeI32
public void writeI32(int value)
Writes an Integer/I32 value- Parameters:
value- I32 value to serialize
-
writeU32
public void writeU32(java.lang.Long value)
Writes an Unsigned Integer (Long)/U32- Parameters:
value- U32 value to serialize
-
writeI64
public void writeI64(long value)
Writes a Long/I64 value- Parameters:
value- I64 value to serialize
-
writeU64
public void writeU64(java.math.BigInteger value) throws ValueSerializationExceptionWrites an Unsigned Long (BigInteger)/U64 to the value byte buffer- Parameters:
value- U64 value to serialize error with input/output while reading the byte array- Throws:
ValueSerializationException- exception holding information of failure to serialize a value
-
writeU128
public void writeU128(java.math.BigInteger value) throws ValueSerializationExceptionWrites a BigInteger/U128 to the value byte buffer- Parameters:
value- U128 value to serialize error with input/output while reading the byte array- Throws:
ValueSerializationException- exception holding information of failure to serialize a value
-
writeU256
public void writeU256(java.math.BigInteger value) throws ValueSerializationExceptionWrites a BigInteger/U256 to the value byte buffer- Parameters:
value- U256 value to serialize error with input/output while reading the byte array- Throws:
ValueSerializationException- exception holding information of failure to serialize a value
-
writeU512
public void writeU512(java.math.BigInteger value) throws ValueSerializationExceptionWrites a BigInteger/U512 to the value byte buffer- Parameters:
value- U512 value to serialize error with input/output while reading the byte array- Throws:
ValueSerializationException- exception holding information of failure to serialize a value
-
writeBigInteger
protected void writeBigInteger(java.math.BigInteger value, int size) throws ValueSerializationExceptionWrites a BigInteger/U128-U256-U512 to the value byte buffer- Parameters:
value- BigInteger to serializesize- the bit size of BigInteger error with input/output while reading the byte array- Throws:
ValueSerializationException- exception holding information of failure to serialize a value
-
writeString
public void writeString(java.lang.String value)
Writes a String to the value byte buffer- Parameters:
value- String value to serialize error with input/output while reading the byte array
-
getBuffer
public java.nio.ByteBuffer getBuffer()
Retrieves the backing buffer- Returns:
- the Deserializer ByteBuffer
-
toByteArray
public byte[] toByteArray()
Gets the full byte array corresponding to serialized data- Returns:
- the byte array serialized data
-
increaseCapacity
protected void increaseCapacity(int increaseByteCount) throws java.lang.IllegalArgumentExceptionIncreases the buffer size and replaces with the new capacity buffer including current buffer data- Parameters:
increaseByteCount- the byte count to increase- Throws:
java.lang.IllegalArgumentException- if the parameter is invalid
-
-