Package io.servicetalk.serialization.api
Interface Serializer

 All Known Implementing Classes:
DefaultSerializer
public interface Serializer
A contract for serialization and deserialization.


Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> Publisher<T>
deserialize(Publisher<Buffer> source, TypeHolder<T> typeHolder)
Applies a deserializer on the passedPublisher
to convert into aPublisher
of deserialized instances ofSerializer
.<T> Publisher<T>
deserialize(Publisher<Buffer> source, java.lang.Class<T> type)
Applies a deserializer on the passedPublisher
to convert into aPublisher
of deserialized instances ofSerializer
.<T> BlockingIterable<T>
deserialize(BlockingIterable<Buffer> source, TypeHolder<T> typeHolder)
Applies a deserializer on the passedBlockingIterable
to convert into aBlockingIterable
of deserialized instances ofSerializer
.<T> BlockingIterable<T>
deserialize(BlockingIterable<Buffer> source, java.lang.Class<T> type)
Applies a deserializer on the passedBlockingIterable
to convert into aIterable
of deserialized instances ofSerializer
.<T> CloseableIterable<T>
deserialize(java.lang.Iterable<Buffer> source, TypeHolder<T> typeHolder)
Applies a deserializer on the passedIterable
to convert into aIterable
of deserialized instances ofSerializer
.<T> CloseableIterable<T>
deserialize(java.lang.Iterable<Buffer> source, java.lang.Class<T> type)
Applies a deserializer on the passedIterable
to convert into aCloseableIterable
of deserialized instances ofSerializer
.<T> CloseableIterable<T>
deserializeAggregated(Buffer serializedData, TypeHolder<T> typeHolder)
Deserializes the passed encodedBuffer
to zero or more instances ofSerializer
.<T> CloseableIterable<T>
deserializeAggregated(Buffer serializedData, java.lang.Class<T> type)
Deserializes the passed encodedBuffer
to one or more instances ofSerializer
.<T> T
deserializeAggregatedSingle(Buffer serializedData, TypeHolder<T> typeHolder)
Deserializes the passed encodedBuffer
to a single instance ofSerializer
.<T> T
deserializeAggregatedSingle(Buffer serializedData, java.lang.Class<T> type)
Deserializes the passed encodedBuffer
to a single instance ofSerializer
.<T> Publisher<Buffer>
serialize(Publisher<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder)
Transforms the passedPublisher
such that each contained element of typeSerializer
is serialized into aBuffer
.<T> Publisher<Buffer>
serialize(Publisher<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder, java.util.function.IntUnaryOperator bytesEstimator)
Transforms the passedPublisher
such that each contained element of typeSerializer
is serialized into aBuffer
.<T> Publisher<Buffer>
serialize(Publisher<T> source, BufferAllocator allocator, java.lang.Class<T> type)
Transforms the passedPublisher
such that each contained element of typeSerializer
is serialized into aBuffer
.<T> Publisher<Buffer>
serialize(Publisher<T> source, BufferAllocator allocator, java.lang.Class<T> type, java.util.function.IntUnaryOperator bytesEstimator)
Transforms the passedPublisher
such that each contained element of typeSerializer
is serialized into aBuffer
.<T> BlockingIterable<Buffer>
serialize(BlockingIterable<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder)
Transforms the passedBlockingIterable
such that each contained element of typeSerializer
is serialized into aBuffer
.<T> BlockingIterable<Buffer>
serialize(BlockingIterable<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder, java.util.function.IntUnaryOperator bytesEstimator)
Transforms the passedBlockingIterable
such that each contained element of typeSerializer
is serialized into aBuffer
.<T> BlockingIterable<Buffer>
serialize(BlockingIterable<T> source, BufferAllocator allocator, java.lang.Class<T> type)
Transforms the passedBlockingIterable
such that each contained element of typeSerializer
is serialized into aBuffer
.<T> BlockingIterable<Buffer>
serialize(BlockingIterable<T> source, BufferAllocator allocator, java.lang.Class<T> type, java.util.function.IntUnaryOperator bytesEstimator)
Transforms the passedBlockingIterable
such that each contained element of typeSerializer
is serialized into aBuffer
.<T> java.lang.Iterable<Buffer>
serialize(java.lang.Iterable<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder)
Transforms the passedIterable
such that each contained element of typeSerializer
is serialized into aBuffer
.<T> java.lang.Iterable<Buffer>
serialize(java.lang.Iterable<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder, java.util.function.IntUnaryOperator bytesEstimator)
Transforms the passedIterable
such that each contained element of typeSerializer
is serialized into aBuffer
.<T> java.lang.Iterable<Buffer>
serialize(java.lang.Iterable<T> source, BufferAllocator allocator, java.lang.Class<T> type)
Transforms the passedIterable
such that each contained element of typeSerializer
is serialized into aBuffer
.<T> java.lang.Iterable<Buffer>
serialize(java.lang.Iterable<T> source, BufferAllocator allocator, java.lang.Class<T> type, java.util.function.IntUnaryOperator bytesEstimator)
Transforms the passedIterable
such that each contained element of typeSerializer
is serialized into aBuffer
.<T> void
serialize(T toSerialize, Buffer destination)
Serializes the passed objecttoSerialize
to the passedBuffer
.<T> Buffer
serialize(T toSerialize, BufferAllocator allocator)
Serializes the passed objecttoSerialize
to the returnedBuffer
.<T> Buffer
serialize(T toSerialize, BufferAllocator allocator, int bytesEstimate)
Serializes the passed objecttoSerialize
to the returnedBuffer
.



Method Detail

serialize
<T> Publisher<Buffer> serialize(Publisher<T> source, BufferAllocator allocator, java.lang.Class<T> type)
Transforms the passedPublisher
such that each contained element of typeSerializer
is serialized into aBuffer
. Type Parameters:
T
 The data type to serialize. Parameters:
source
Publisher
containing objects to serialize.allocator
 TheBufferAllocator
used to allocateBuffer
s.type
 The class forSerializer
, the object to be serialized. Returns:
 A transformed
Publisher
such that each contained element in the originalPublisher
is transformed from typeSerializer
to aBuffer
.

serialize
<T> java.lang.Iterable<Buffer> serialize(java.lang.Iterable<T> source, BufferAllocator allocator, java.lang.Class<T> type)
Transforms the passedIterable
such that each contained element of typeSerializer
is serialized into aBuffer
. Type Parameters:
T
 The data type to serialize. Parameters:
source
Iterable
containing objects to serialize.allocator
 TheBufferAllocator
used to allocateBuffer
s.type
 The class forSerializer
, the object to be serialized. Returns:
 A transformed
Iterable
such that each contained element in the originalIterable
is transformed from typeSerializer
to aBuffer
.

serialize
<T> BlockingIterable<Buffer> serialize(BlockingIterable<T> source, BufferAllocator allocator, java.lang.Class<T> type)
Transforms the passedBlockingIterable
such that each contained element of typeSerializer
is serialized into aBuffer
. Type Parameters:
T
 The data type to serialize. Parameters:
source
BlockingIterable
containing objects to serialize.allocator
 TheBufferAllocator
used to allocateBuffer
s.type
 The class forSerializer
, the object to be serialized. Returns:
 A transformed
BlockingIterable
such that each contained element in the originalBlockingIterable
is transformed from typeSerializer
to aBuffer
.

serialize
<T> Publisher<Buffer> serialize(Publisher<T> source, BufferAllocator allocator, java.lang.Class<T> type, java.util.function.IntUnaryOperator bytesEstimator)
Transforms the passedPublisher
such that each contained element of typeSerializer
is serialized into aBuffer
. Type Parameters:
T
 The data type to serialize. Parameters:
source
Publisher
containing objects to serialize.allocator
 TheBufferAllocator
used to allocateBuffer
s.type
 The class forSerializer
, the object to be serialized.bytesEstimator
 AnIntUnaryOperator
that given the last serialized size in bytes, estimates the size of the next object to be serialized in bytes. Returns:
 A transformed
Publisher
such that each contained element in the originalPublisher
is transformed from typeSerializer
to aBuffer
.

serialize
<T> java.lang.Iterable<Buffer> serialize(java.lang.Iterable<T> source, BufferAllocator allocator, java.lang.Class<T> type, java.util.function.IntUnaryOperator bytesEstimator)
Transforms the passedIterable
such that each contained element of typeSerializer
is serialized into aBuffer
. Type Parameters:
T
 The data type to serialize. Parameters:
source
Iterable
containing objects to serialize.allocator
 TheBufferAllocator
used to allocateBuffer
s.type
 The class forSerializer
, the object to be serialized.bytesEstimator
 AnIntUnaryOperator
that given the last serialized size in bytes, estimates the size of the next object to be serialized in bytes. Returns:
 A transformed
Iterable
such that each contained element in the originalIterable
is transformed from typeSerializer
to aBuffer
.

serialize
<T> BlockingIterable<Buffer> serialize(BlockingIterable<T> source, BufferAllocator allocator, java.lang.Class<T> type, java.util.function.IntUnaryOperator bytesEstimator)
Transforms the passedBlockingIterable
such that each contained element of typeSerializer
is serialized into aBuffer
. Type Parameters:
T
 The data type to serialize. size of the next object to be serialized in bytes. Parameters:
source
BlockingIterable
containing objects to serialize.allocator
 TheBufferAllocator
used to allocateBuffer
s.type
 The class forSerializer
, the object to be serialized.bytesEstimator
 AnIntUnaryOperator
that given the last serialized size in bytes, estimates the Returns:
 A transformed
BlockingIterable
such that each contained element in the originalBlockingIterable
is transformed from typeSerializer
to aBuffer
.

serialize
<T> Publisher<Buffer> serialize(Publisher<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder)
Transforms the passedPublisher
such that each contained element of typeSerializer
is serialized into aBuffer
. Type Parameters:
T
 The data type to serialize. Parameters:
source
Publisher
containing objects to serialize.allocator
 TheBufferAllocator
used to allocateBuffer
s.typeHolder
TypeHolder
holding theParameterizedType
to be serialized. Returns:
 A transformed
Publisher
such that each contained element in the originalPublisher
is transformed from typeSerializer
to aBuffer
.

serialize
<T> java.lang.Iterable<Buffer> serialize(java.lang.Iterable<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder)
Transforms the passedIterable
such that each contained element of typeSerializer
is serialized into aBuffer
. Type Parameters:
T
 The data type to serialize. Parameters:
source
Iterable
containing objects to serialize.allocator
 TheBufferAllocator
used to allocateBuffer
s.typeHolder
TypeHolder
holding theParameterizedType
to be serialized. Returns:
 A transformed
Iterable
such that each contained element in the originalIterable
is transformed from typeSerializer
to aBuffer
.

serialize
<T> BlockingIterable<Buffer> serialize(BlockingIterable<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder)
Transforms the passedBlockingIterable
such that each contained element of typeSerializer
is serialized into aBuffer
. Type Parameters:
T
 The data type to serialize. Parameters:
source
BlockingIterable
containing objects to serialize.allocator
 TheBufferAllocator
used to allocateBuffer
s.typeHolder
TypeHolder
holding theParameterizedType
to be serialized. Returns:
 A transformed
BlockingIterable
such that each contained element in the originalBlockingIterable
is transformed from typeSerializer
to aBuffer
.

serialize
<T> Publisher<Buffer> serialize(Publisher<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder, java.util.function.IntUnaryOperator bytesEstimator)
Transforms the passedPublisher
such that each contained element of typeSerializer
is serialized into aBuffer
. Type Parameters:
T
 The data type to serialize. Parameters:
source
Publisher
containing objects to serialize.allocator
 TheBufferAllocator
used to allocateBuffer
s.typeHolder
TypeHolder
holding theParameterizedType
to be serialized.bytesEstimator
 AnIntUnaryOperator
that given the last serialized size in bytes, estimates the size of the next object to be serialized in bytes. Returns:
 A transformed
Publisher
such that each contained element in the originalPublisher
is transformed from typeSerializer
to aBuffer
.

serialize
<T> java.lang.Iterable<Buffer> serialize(java.lang.Iterable<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder, java.util.function.IntUnaryOperator bytesEstimator)
Transforms the passedIterable
such that each contained element of typeSerializer
is serialized into aBuffer
. Type Parameters:
T
 The data type to serialize. Parameters:
source
Iterable
containing objects to serialize.allocator
 TheBufferAllocator
used to allocateBuffer
s.typeHolder
TypeHolder
holding theParameterizedType
to be serialized.bytesEstimator
 AnIntUnaryOperator
that given the last serialized size in bytes, estimates the size of the next object to be serialized in bytes. Returns:
 A transformed
Iterable
such that each contained element in the originalIterable
is transformed from typeSerializer
to aBuffer
.

serialize
<T> BlockingIterable<Buffer> serialize(BlockingIterable<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder, java.util.function.IntUnaryOperator bytesEstimator)
Transforms the passedBlockingIterable
such that each contained element of typeSerializer
is serialized into aBuffer
. Type Parameters:
T
 The data type to serialize. Parameters:
source
BlockingIterable
containing objects to serialize.allocator
 TheBufferAllocator
used to allocateBuffer
s.typeHolder
TypeHolder
holding theParameterizedType
to be serialized.bytesEstimator
 AnIntUnaryOperator
that given the last serialized size in bytes, estimates the size of the next object to be serialized in bytes. Returns:
 A transformed
BlockingIterable
such that each contained element in the originalBlockingIterable
is transformed from typeSerializer
to aBuffer
.

serialize
<T> Buffer serialize(T toSerialize, BufferAllocator allocator)
Serializes the passed objecttoSerialize
to the returnedBuffer
. Type Parameters:
T
 The data type to serialize. Parameters:
toSerialize
 Object to serialize.allocator
BufferAllocator
to allocate the returnedBuffer
. Returns:
Buffer
containing the serialized representation oftoSerialize
.

serialize
<T> Buffer serialize(T toSerialize, BufferAllocator allocator, int bytesEstimate)
Serializes the passed objecttoSerialize
to the returnedBuffer
. Type Parameters:
T
 The data type to serialize. Parameters:
toSerialize
 Object to serialize.allocator
BufferAllocator
to allocate the returnedBuffer
.bytesEstimate
 An estimate for the size in bytes of the serialized representation oftoSerialize
. Returns:
Buffer
containing the serialized representation oftoSerialize
.

serialize
<T> void serialize(T toSerialize, Buffer destination)
Serializes the passed objecttoSerialize
to the passedBuffer
. Type Parameters:
T
 The data type to serialize. Parameters:
toSerialize
 Object to serialize.destination
 TheBuffer
to which the serialized representation oftoSerialize
is written.

deserialize
<T> Publisher<T> deserialize(Publisher<Buffer> source, TypeHolder<T> typeHolder)
Applies a deserializer on the passedPublisher
to convert into aPublisher
of deserialized instances ofSerializer
. If thesource
Publisher
terminates with some left over data in a previously emittedBuffer
but not deserialized in an object, then the returnedPublisher
will terminate with an error.If all content has been aggregated into a single
Buffer
,deserializeAggregated(Buffer, Class)
can be used. Type Parameters:
T
 The data type to deserialize. Parameters:
source
Publisher
containingBuffer
s to deserialize.typeHolder
TypeHolder
holding theParameterizedType
to be deserialized. Returns:
 A transformed
Publisher
such that each contained element in the originalPublisher
is transformed from typeBuffer
to an instance ofSerializer
.

deserialize
<T> CloseableIterable<T> deserialize(java.lang.Iterable<Buffer> source, TypeHolder<T> typeHolder)
Applies a deserializer on the passedIterable
to convert into aIterable
of deserialized instances ofSerializer
. If thesource
Iterable
completes with some left over data in a previously emittedBuffer
but not deserialized in an object, thenIterator
from the returnedIterable
will throw anSerializationException
fromIterator.hasNext()
after all deserialized instances are emitted.If all content has been aggregated into a single
Buffer
,deserializeAggregated(Buffer, TypeHolder)
can be used. Type Parameters:
T
 The data type to deserialize. Parameters:
source
Iterable
containingBuffer
s to deserialize.typeHolder
TypeHolder
holding theParameterizedType
to be deserialized. Returns:
 A transformed
CloseableIterable
such that each contained element in the originalIterable
is transformed from typeBuffer
to an instance ofSerializer
.

deserialize
<T> BlockingIterable<T> deserialize(BlockingIterable<Buffer> source, TypeHolder<T> typeHolder)
Applies a deserializer on the passedBlockingIterable
to convert into aBlockingIterable
of deserialized instances ofSerializer
. If thesource
BlockingIterable
completes with some left over data in a previously emittedBuffer
but not deserialized in an object, thenBlockingIterator
from the returnedBlockingIterable
will throw anSerializationException
fromIterator.hasNext()
after all deserialized instances are emitted.If all content has been aggregated into a single
Buffer
,deserializeAggregated(Buffer, Class)
can be used. Type Parameters:
T
 The data type to deserialize. Parameters:
source
BlockingIterable
containingBuffer
s to deserialize.typeHolder
TypeHolder
holding theParameterizedType
to be deserialized. Returns:
 A transformed
BlockingIterable
such that each contained element in the originalBlockingIterable
is transformed from typeBuffer
to an instance ofSerializer
.

deserialize
<T> Publisher<T> deserialize(Publisher<Buffer> source, java.lang.Class<T> type)
Applies a deserializer on the passedPublisher
to convert into aPublisher
of deserialized instances ofSerializer
. If thesource
Publisher
terminates with some left over data in a previously emittedBuffer
but not deserialized in an object, then the returnedPublisher
will terminate with an error.If all content has been aggregated into a single
Buffer
,deserializeAggregated(Buffer, Class)
can be used. Type Parameters:
T
 The data type to deserialize. Parameters:
source
Publisher
containingBuffer
s to deserialize.type
 The class forSerializer
, the object to be deserialized. Returns:
 A transformed
Publisher
such that each contained element in the originalPublisher
is transformed from typeBuffer
to an instance ofSerializer
.

deserialize
<T> CloseableIterable<T> deserialize(java.lang.Iterable<Buffer> source, java.lang.Class<T> type)
Applies a deserializer on the passedIterable
to convert into aCloseableIterable
of deserialized instances ofSerializer
. If thesource
Iterable
completes with some left over data in a previously emittedBuffer
but not deserialized in an object, thenCloseableIterator
from the returnedCloseableIterable
will throw anSerializationException
fromIterator.hasNext()
after all deserialized instances are emitted.If all content has been aggregated into a single
Buffer
,deserializeAggregated(Buffer, Class)
can be used. Type Parameters:
T
 The data type to deserialize. Parameters:
source
Iterable
containingBuffer
s to deserialize.type
 The class forSerializer
, the object to be deserialized. Returns:
 A transformed
CloseableIterable
such that each contained element in the originalIterable
is transformed from typeBuffer
to an instance ofSerializer
.

deserialize
<T> BlockingIterable<T> deserialize(BlockingIterable<Buffer> source, java.lang.Class<T> type)
Applies a deserializer on the passedBlockingIterable
to convert into aIterable
of deserialized instances ofSerializer
. If thesource
BlockingIterable
completes with some left over data in a previously emittedBuffer
but not deserialized in an object, thenBlockingIterator
from the returnedBlockingIterable
will throw anSerializationException
fromIterator.hasNext()
after all deserialized instances are emitted.If all content has been aggregated into a single
Buffer
,deserializeAggregated(Buffer, Class)
can be used. Type Parameters:
T
 The data type to deserialize. Parameters:
source
BlockingIterable
containingBuffer
s to deserialize.type
 The class forSerializer
, the object to be deserialized. Returns:
 A transformed
BlockingIterable
such that each contained element in the originalBlockingIterable
is transformed from typeBuffer
to an instance ofSerializer
.

deserializeAggregated
<T> CloseableIterable<T> deserializeAggregated(Buffer serializedData, java.lang.Class<T> type)
Deserializes the passed encodedBuffer
to one or more instances ofSerializer
.Incomplete data
This method assumes that the passedBuffer
contains exact amount of data required to deserialize into at least one complete instance ofSerializer
. If there is any left over data in theBuffer
after the deserialization is complete,Iterator.hasNext()
andIterator.next()
methods will eventually throw aSerializationException
from theCloseableIterator
returned byCloseableIterable.iterator()
. In such a case, all deserialized data will first be returned from theCloseableIterator
. Type Parameters:
T
 The data type to deserialize. Parameters:
serializedData
 ABuffer
containing serialized representation of one or more instances ofSerializer
.type
 The class forSerializer
, the object to be deserialized. Returns:
 An
CloseableIterable
containing one or more deserialized instances ofSerializer
. If there is any left over data in theBuffer
after the deserialization is complete,Iterator.hasNext()
andIterator.next()
methods will eventually throw aSerializationException
from theCloseableIterator
returned byCloseableIterable.iterator()
. In such a case, all deserialized data will first be returned from theIterator
.

deserializeAggregated
<T> CloseableIterable<T> deserializeAggregated(Buffer serializedData, TypeHolder<T> typeHolder)
Deserializes the passed encodedBuffer
to zero or more instances ofSerializer
.Incomplete data
This method assumes that the passedBuffer
contains exact amount of data required to deserialize into at least one complete instance ofSerializer
. If there is any left over data in theBuffer
after deserialization is complete,Iterator.hasNext()
andIterator.next()
methods will eventually throw aSerializationException
from theCloseableIterator
returned byCloseableIterable.iterator()
. In such a case, all deserialized data will first be returned from theCloseableIterator
. Type Parameters:
T
 The data type to deserialize. Parameters:
serializedData
 ABuffer
containing serialized representation of one or more instances ofSerializer
.typeHolder
TypeHolder
holding theParameterizedType
to be deserialized. Returns:
 An
CloseableIterable
containing one or more deserialized instances ofSerializer
. If there is any left over data in theBuffer
after the deserialization is complete,Iterator.hasNext()
andIterator.next()
methods will eventually throw aSerializationException
from theCloseableIterator
returned byCloseableIterable.iterator()
. In such a case, all deserialized data will first be returned from theCloseableIterator
.

deserializeAggregatedSingle
<T> T deserializeAggregatedSingle(Buffer serializedData, java.lang.Class<T> type)
Deserializes the passed encodedBuffer
to a single instance ofSerializer
. Type Parameters:
T
 The data type to deserialize. Parameters:
serializedData
 ABuffer
containing serialized representation of a single instance ofSerializer
.type
 The class forSerializer
, the object to be deserialized. Returns:
 The deserialized object.
 Throws:
SerializationException
 If the passedBuffer
contains an incomplete object or if there is any left over data in theBuffer
after the deserialization is complete.

deserializeAggregatedSingle
<T> T deserializeAggregatedSingle(Buffer serializedData, TypeHolder<T> typeHolder)
Deserializes the passed encodedBuffer
to a single instance ofSerializer
. Type Parameters:
T
 The data type to deserialize. Parameters:
serializedData
 ABuffer
containing serialized representation of a single instance ofSerializer
.typeHolder
TypeHolder
holding theParameterizedType
to be deserialized. Returns:
 The deserialized object.
 Throws:
SerializationException
 If the passedBuffer
contains an incomplete object or if there is any left over data in theBuffer
after the deserialization is complete.

