Class ByteArraySerializer

java.lang.Object
io.servicetalk.serializer.utils.ByteArraySerializer
All Implemented Interfaces:
Deserializer<byte[]>, Serializer<byte[]>, SerializerDeserializer<byte[]>

public final class ByteArraySerializer extends Object implements SerializerDeserializer<byte[]>
Serialize/deserialize byte[].
  • Method Details

    • byteArraySerializer

      public static SerializerDeserializer<byte[]> byteArraySerializer(boolean forceCopy)
      Create a new instance.
      Parameters:
      forceCopy - true means that data will always be copied from Buffer memory. false means that if Buffer.hasArray() is true and the array offsets are aligned the result of serialization doesn't have to be copied.
      Returns:
      A serializer that produces/consumes byte[].
    • deserialize

      public byte[] deserialize(Buffer serializedData, BufferAllocator allocator)
      Description copied from interface: Deserializer
      Deserialize the contents from the Buffer parameter.

      The caller is responsible for assuming the buffer contents contains enough Buffer.readableBytes() to successfully deserialize.

      Specified by:
      deserialize in interface Deserializer<byte[]>
      Parameters:
      serializedData - Buffer whose Buffer.readableBytes() contains a serialized object. The Buffer.readerIndex() will be advanced to indicate the content which has been consumed.
      allocator - Used to allocate intermediate Buffers if required.
      Returns:
      The result of the deserialization.
    • serialize

      public Buffer serialize(byte[] toSerialize, BufferAllocator allocator)
      Description copied from interface: Serializer
      Serialize the Serializer parameter to a Buffer.
      Specified by:
      serialize in interface Serializer<byte[]>
      Parameters:
      toSerialize - The Serializer to serialize.
      allocator - Used to allocate the buffer to serialize to.
      Returns:
      The results of the serialization.
    • serialize

      public void serialize(byte[] toSerialize, BufferAllocator allocator, Buffer buffer)
      Description copied from interface: Serializer
      Serialize the Serializer parameter to the Buffer parameter.
      Specified by:
      serialize in interface Serializer<byte[]>
      Parameters:
      toSerialize - The Serializer to serialize.
      allocator - Used to allocate intermediate Buffers if required.
      buffer - Where the results of the serialization will be written to.