Package io.servicetalk.serializer.utils
Class ByteArraySerializer
java.lang.Object
io.servicetalk.serializer.utils.ByteArraySerializer
- All Implemented Interfaces:
Deserializer<byte[]>
,Serializer<byte[]>
,SerializerDeserializer<byte[]>
Serialize/deserialize
byte[]
.-
Method Summary
Modifier and TypeMethodDescriptionstatic SerializerDeserializer<byte[]>
byteArraySerializer
(boolean forceCopy) Create a new instance.byte[]
deserialize
(Buffer serializedData, BufferAllocator allocator) Deserialize the contents from theBuffer
parameter.serialize
(byte[] toSerialize, BufferAllocator allocator) Serialize theSerializer
parameter to aBuffer
.void
serialize
(byte[] toSerialize, BufferAllocator allocator, Buffer buffer) Serialize theSerializer
parameter to theBuffer
parameter.
-
Method Details
-
byteArraySerializer
Create a new instance.- Parameters:
forceCopy
-true
means that data will always be copied fromBuffer
memory.false
means that ifBuffer.hasArray()
istrue
and the array offsets are aligned the result of serialization doesn't have to be copied.- Returns:
- A serializer that produces/consumes
byte[]
.
-
deserialize
Description copied from interface:Deserializer
Deserialize the contents from theBuffer
parameter.The caller is responsible for assuming the buffer contents contains enough
Buffer.readableBytes()
to successfully deserialize.- Specified by:
deserialize
in interfaceDeserializer<byte[]>
- Parameters:
serializedData
-Buffer
whoseBuffer.readableBytes()
contains a serialized object. TheBuffer.readerIndex()
will be advanced to indicate the content which has been consumed.allocator
- Used to allocate intermediateBuffer
s if required.- Returns:
- The result of the deserialization.
-
serialize
Description copied from interface:Serializer
Serialize theSerializer
parameter to aBuffer
.- Specified by:
serialize
in interfaceSerializer<byte[]>
- Parameters:
toSerialize
- TheSerializer
to serialize.allocator
- Used to allocate the buffer to serialize to.- Returns:
- The results of the serialization.
-
serialize
Description copied from interface:Serializer
Serialize theSerializer
parameter to theBuffer
parameter.- Specified by:
serialize
in interfaceSerializer<byte[]>
- Parameters:
toSerialize
- TheSerializer
to serialize.allocator
- Used to allocate intermediateBuffer
s if required.buffer
- Where the results of the serialization will be written to.
-