Class ByteOps
java.lang.Object
com.github.darksoulq.abyssallib.common.serialization.DynamicOps<byte[]>
com.github.darksoulq.abyssallib.common.serialization.ops.ByteOps
A
DynamicOps implementation that stores serialized values as raw
byte arrays.
Values are encoded using a simple binary format. Variable-length structures such as strings, lists, and maps are prefixed with their length or entry count, while primitive numeric values are stored using their standard binary representation.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbooleanIndicates that this format benefits from compressed map encoding.byte[]copy(byte[] input) Creates a copy of the provided byte array.byte[]createBoolean(boolean value) Encodes a boolean value.byte[]createByte(byte value) Encodes a byte value.byte[]createDouble(double value) Encodes a double value.byte[]createFloat(float value) Encodes a float value.byte[]createInt(int value) Encodes an integer value using big-endian byte order.byte[]createList(List<byte[]> elements) Encodes a list of serialized values.byte[]createLong(long value) Encodes a long value using big-endian byte order.byte[]Encodes a map of serialized key-value pairs.byte[]createShort(short value) Encodes a short value using big-endian byte order.byte[]createString(String value) Encodes a string as UTF-8 bytes prefixed by its length.byte[]empty()Returns the empty value representation for this format.getBooleanValue(byte[] input) Attempts to decode a boolean value.getDoubleValue(byte[] input) Attempts to decode a double value.getFloatValue(byte[] input) Attempts to decode a float value.getIntValue(byte[] input) Attempts to decode an integer value.getKeys(byte[] input) Returns the decoded string keys contained in a serialized map.getList(byte[] input) Attempts to decode a serialized list.getLongValue(byte[] input) Attempts to decode a long value.getMap(byte[] input) Attempts to decode a serialized map.getNumberValue(byte[] input) Attempts to decode a numeric value based on the size of the byte array.getStringValue(byte[] input) Attempts to decode a UTF-8 string from a length-prefixed byte array.size(byte[] input) Returns the number of entries contained in a serialized list or map.
-
Field Details
-
INSTANCE
Shared singleton instance.
-
-
Method Details
-
compressMaps
public boolean compressMaps()Indicates that this format benefits from compressed map encoding.- Overrides:
compressMapsin classDynamicOps<byte[]>- Returns:
true
-
createString
Encodes a string as UTF-8 bytes prefixed by its length.- Specified by:
createStringin classDynamicOps<byte[]>- Parameters:
value- the string to encode- Returns:
- the encoded byte array
-
createByte
public byte[] createByte(byte value) Encodes a byte value.- Specified by:
createBytein classDynamicOps<byte[]>- Parameters:
value- the value to encode- Returns:
- the encoded byte array
-
createShort
public byte[] createShort(short value) Encodes a short value using big-endian byte order.- Specified by:
createShortin classDynamicOps<byte[]>- Parameters:
value- the value to encode- Returns:
- the encoded byte array
-
createInt
public byte[] createInt(int value) Encodes an integer value using big-endian byte order.- Specified by:
createIntin classDynamicOps<byte[]>- Parameters:
value- the value to encode- Returns:
- the encoded byte array
-
createLong
public byte[] createLong(long value) Encodes a long value using big-endian byte order.- Specified by:
createLongin classDynamicOps<byte[]>- Parameters:
value- the value to encode- Returns:
- the encoded byte array
-
createFloat
public byte[] createFloat(float value) Encodes a float value.- Specified by:
createFloatin classDynamicOps<byte[]>- Parameters:
value- the value to encode- Returns:
- the encoded byte array
-
createDouble
public byte[] createDouble(double value) Encodes a double value.- Specified by:
createDoublein classDynamicOps<byte[]>- Parameters:
value- the value to encode- Returns:
- the encoded byte array
-
createBoolean
public byte[] createBoolean(boolean value) Encodes a boolean value.- Specified by:
createBooleanin classDynamicOps<byte[]>- Parameters:
value- the value to encode- Returns:
- a single-byte representation of the boolean
-
createList
Encodes a list of serialized values.The resulting format stores the element count followed by each element prefixed with its length.
- Specified by:
createListin classDynamicOps<byte[]>- Parameters:
elements- the serialized list elements- Returns:
- the encoded list
-
createMap
Encodes a map of serialized key-value pairs.The resulting format stores the entry count followed by each key and value prefixed with its length.
- Specified by:
createMapin classDynamicOps<byte[]>- Parameters:
map- the serialized map entries- Returns:
- the encoded map
-
getStringValue
Attempts to decode a UTF-8 string from a length-prefixed byte array.- Specified by:
getStringValuein classDynamicOps<byte[]>- Parameters:
input- the encoded byte array- Returns:
- the decoded string, if the input is valid
-
getNumberValue
Attempts to decode a numeric value based on the size of the byte array.- Specified by:
getNumberValuein classDynamicOps<byte[]>- Parameters:
input- the encoded byte array- Returns:
- the decoded number, if the input matches a supported numeric size
-
getIntValue
Attempts to decode an integer value.- Specified by:
getIntValuein classDynamicOps<byte[]>- Parameters:
input- the encoded byte array- Returns:
- the decoded integer, if the input contains a valid integer
-
getLongValue
Attempts to decode a long value.- Specified by:
getLongValuein classDynamicOps<byte[]>- Parameters:
input- the encoded byte array- Returns:
- the decoded long, if the input contains a valid long
-
getFloatValue
Attempts to decode a float value.- Specified by:
getFloatValuein classDynamicOps<byte[]>- Parameters:
input- the encoded byte array- Returns:
- the decoded float, if the input contains a valid float
-
getDoubleValue
Attempts to decode a double value.- Specified by:
getDoubleValuein classDynamicOps<byte[]>- Parameters:
input- the encoded byte array- Returns:
- the decoded double, if the input contains a valid double
-
getBooleanValue
Attempts to decode a boolean value.- Specified by:
getBooleanValuein classDynamicOps<byte[]>- Parameters:
input- the encoded byte array- Returns:
- the decoded boolean, if the input contains a valid boolean
-
getList
Attempts to decode a serialized list.- Specified by:
getListin classDynamicOps<byte[]>- Parameters:
input- the encoded byte array- Returns:
- the decoded list, if the input contains a valid list
-
getMap
Attempts to decode a serialized map.- Specified by:
getMapin classDynamicOps<byte[]>- Parameters:
input- the encoded byte array- Returns:
- the decoded map, if the input contains a valid map
-
getKeys
Returns the decoded string keys contained in a serialized map.- Specified by:
getKeysin classDynamicOps<byte[]>- Parameters:
input- the encoded map value- Returns:
- the decoded keys, if the input contains a valid map
-
size
Returns the number of entries contained in a serialized list or map.- Specified by:
sizein classDynamicOps<byte[]>- Parameters:
input- the encoded value- Returns:
- the collection size, if the value is a valid list or map
-
copy
public byte[] copy(byte[] input) Creates a copy of the provided byte array.- Specified by:
copyin classDynamicOps<byte[]>- Parameters:
input- the array to copy- Returns:
- a new array containing the same bytes
-
empty
public byte[] empty()Returns the empty value representation for this format.- Specified by:
emptyin classDynamicOps<byte[]>- Returns:
- an empty byte array
-