Package io.servicetalk.serialization.api
Interface Serializer
-
- All Known Implementing Classes:
DefaultSerializer
public interface SerializerA 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 passedPublisherto convert into aPublisherof deserialized instances ofSerializer.<T> Publisher<T>deserialize(Publisher<Buffer> source, java.lang.Class<T> type)Applies a deserializer on the passedPublisherto convert into aPublisherof deserialized instances ofSerializer.<T> BlockingIterable<T>deserialize(BlockingIterable<Buffer> source, TypeHolder<T> typeHolder)Applies a deserializer on the passedBlockingIterableto convert into aBlockingIterableof deserialized instances ofSerializer.<T> BlockingIterable<T>deserialize(BlockingIterable<Buffer> source, java.lang.Class<T> type)Applies a deserializer on the passedBlockingIterableto convert into aIterableof deserialized instances ofSerializer.<T> CloseableIterable<T>deserialize(java.lang.Iterable<Buffer> source, TypeHolder<T> typeHolder)Applies a deserializer on the passedIterableto convert into aIterableof deserialized instances ofSerializer.<T> CloseableIterable<T>deserialize(java.lang.Iterable<Buffer> source, java.lang.Class<T> type)Applies a deserializer on the passedIterableto convert into aCloseableIterableof deserialized instances ofSerializer.<T> CloseableIterable<T>deserializeAggregated(Buffer serializedData, TypeHolder<T> typeHolder)Deserializes the passed encodedBufferto zero or more instances ofSerializer.<T> CloseableIterable<T>deserializeAggregated(Buffer serializedData, java.lang.Class<T> type)Deserializes the passed encodedBufferto one or more instances ofSerializer.<T> TdeserializeAggregatedSingle(Buffer serializedData, TypeHolder<T> typeHolder)Deserializes the passed encodedBufferto a single instance ofSerializer.<T> TdeserializeAggregatedSingle(Buffer serializedData, java.lang.Class<T> type)Deserializes the passed encodedBufferto a single instance ofSerializer.<T> Publisher<Buffer>serialize(Publisher<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder)Transforms the passedPublishersuch that each contained element of typeSerializeris serialized into aBuffer.<T> Publisher<Buffer>serialize(Publisher<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder, java.util.function.IntUnaryOperator bytesEstimator)Transforms the passedPublishersuch that each contained element of typeSerializeris serialized into aBuffer.<T> Publisher<Buffer>serialize(Publisher<T> source, BufferAllocator allocator, java.lang.Class<T> type)Transforms the passedPublishersuch that each contained element of typeSerializeris serialized into aBuffer.<T> Publisher<Buffer>serialize(Publisher<T> source, BufferAllocator allocator, java.lang.Class<T> type, java.util.function.IntUnaryOperator bytesEstimator)Transforms the passedPublishersuch that each contained element of typeSerializeris serialized into aBuffer.<T> BlockingIterable<Buffer>serialize(BlockingIterable<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder)Transforms the passedBlockingIterablesuch that each contained element of typeSerializeris serialized into aBuffer.<T> BlockingIterable<Buffer>serialize(BlockingIterable<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder, java.util.function.IntUnaryOperator bytesEstimator)Transforms the passedBlockingIterablesuch that each contained element of typeSerializeris serialized into aBuffer.<T> BlockingIterable<Buffer>serialize(BlockingIterable<T> source, BufferAllocator allocator, java.lang.Class<T> type)Transforms the passedBlockingIterablesuch that each contained element of typeSerializeris serialized into aBuffer.<T> BlockingIterable<Buffer>serialize(BlockingIterable<T> source, BufferAllocator allocator, java.lang.Class<T> type, java.util.function.IntUnaryOperator bytesEstimator)Transforms the passedBlockingIterablesuch that each contained element of typeSerializeris serialized into aBuffer.<T> java.lang.Iterable<Buffer>serialize(java.lang.Iterable<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder)Transforms the passedIterablesuch that each contained element of typeSerializeris 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 passedIterablesuch that each contained element of typeSerializeris serialized into aBuffer.<T> java.lang.Iterable<Buffer>serialize(java.lang.Iterable<T> source, BufferAllocator allocator, java.lang.Class<T> type)Transforms the passedIterablesuch that each contained element of typeSerializeris 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 passedIterablesuch that each contained element of typeSerializeris serialized into aBuffer.<T> voidserialize(T toSerialize, Buffer destination)Serializes the passed objecttoSerializeto the passedBuffer.<T> Bufferserialize(T toSerialize, BufferAllocator allocator)Serializes the passed objecttoSerializeto the returnedBuffer.<T> Bufferserialize(T toSerialize, BufferAllocator allocator, int bytesEstimate)Serializes the passed objecttoSerializeto the returnedBuffer.
-
-
-
Method Detail
-
serialize
<T> Publisher<Buffer> serialize(Publisher<T> source, BufferAllocator allocator, java.lang.Class<T> type)
Transforms the passedPublishersuch that each contained element of typeSerializeris serialized into aBuffer.- Type Parameters:
T- The data type to serialize.- Parameters:
source-Publishercontaining objects to serialize.allocator- TheBufferAllocatorused to allocateBuffers.type- The class forSerializer, the object to be serialized.- Returns:
- A transformed
Publishersuch that each contained element in the originalPublisheris transformed from typeSerializerto aBuffer.
-
serialize
<T> java.lang.Iterable<Buffer> serialize(java.lang.Iterable<T> source, BufferAllocator allocator, java.lang.Class<T> type)
Transforms the passedIterablesuch that each contained element of typeSerializeris serialized into aBuffer.- Type Parameters:
T- The data type to serialize.- Parameters:
source-Iterablecontaining objects to serialize.allocator- TheBufferAllocatorused to allocateBuffers.type- The class forSerializer, the object to be serialized.- Returns:
- A transformed
Iterablesuch that each contained element in the originalIterableis transformed from typeSerializerto aBuffer.
-
serialize
<T> BlockingIterable<Buffer> serialize(BlockingIterable<T> source, BufferAllocator allocator, java.lang.Class<T> type)
Transforms the passedBlockingIterablesuch that each contained element of typeSerializeris serialized into aBuffer.- Type Parameters:
T- The data type to serialize.- Parameters:
source-BlockingIterablecontaining objects to serialize.allocator- TheBufferAllocatorused to allocateBuffers.type- The class forSerializer, the object to be serialized.- Returns:
- A transformed
BlockingIterablesuch that each contained element in the originalBlockingIterableis transformed from typeSerializerto aBuffer.
-
serialize
<T> Publisher<Buffer> serialize(Publisher<T> source, BufferAllocator allocator, java.lang.Class<T> type, java.util.function.IntUnaryOperator bytesEstimator)
Transforms the passedPublishersuch that each contained element of typeSerializeris serialized into aBuffer.- Type Parameters:
T- The data type to serialize.- Parameters:
source-Publishercontaining objects to serialize.allocator- TheBufferAllocatorused to allocateBuffers.type- The class forSerializer, the object to be serialized.bytesEstimator- AnIntUnaryOperatorthat given the last serialized size in bytes, estimates the size of the next object to be serialized in bytes.- Returns:
- A transformed
Publishersuch that each contained element in the originalPublisheris transformed from typeSerializerto 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 passedIterablesuch that each contained element of typeSerializeris serialized into aBuffer.- Type Parameters:
T- The data type to serialize.- Parameters:
source-Iterablecontaining objects to serialize.allocator- TheBufferAllocatorused to allocateBuffers.type- The class forSerializer, the object to be serialized.bytesEstimator- AnIntUnaryOperatorthat given the last serialized size in bytes, estimates the size of the next object to be serialized in bytes.- Returns:
- A transformed
Iterablesuch that each contained element in the originalIterableis transformed from typeSerializerto aBuffer.
-
serialize
<T> BlockingIterable<Buffer> serialize(BlockingIterable<T> source, BufferAllocator allocator, java.lang.Class<T> type, java.util.function.IntUnaryOperator bytesEstimator)
Transforms the passedBlockingIterablesuch that each contained element of typeSerializeris serialized into aBuffer.- Type Parameters:
T- The data type to serialize. size of the next object to be serialized in bytes.- Parameters:
source-BlockingIterablecontaining objects to serialize.allocator- TheBufferAllocatorused to allocateBuffers.type- The class forSerializer, the object to be serialized.bytesEstimator- AnIntUnaryOperatorthat given the last serialized size in bytes, estimates the- Returns:
- A transformed
BlockingIterablesuch that each contained element in the originalBlockingIterableis transformed from typeSerializerto aBuffer.
-
serialize
<T> Publisher<Buffer> serialize(Publisher<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder)
Transforms the passedPublishersuch that each contained element of typeSerializeris serialized into aBuffer.- Type Parameters:
T- The data type to serialize.- Parameters:
source-Publishercontaining objects to serialize.allocator- TheBufferAllocatorused to allocateBuffers.typeHolder-TypeHolderholding theParameterizedTypeto be serialized.- Returns:
- A transformed
Publishersuch that each contained element in the originalPublisheris transformed from typeSerializerto aBuffer.
-
serialize
<T> java.lang.Iterable<Buffer> serialize(java.lang.Iterable<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder)
Transforms the passedIterablesuch that each contained element of typeSerializeris serialized into aBuffer.- Type Parameters:
T- The data type to serialize.- Parameters:
source-Iterablecontaining objects to serialize.allocator- TheBufferAllocatorused to allocateBuffers.typeHolder-TypeHolderholding theParameterizedTypeto be serialized.- Returns:
- A transformed
Iterablesuch that each contained element in the originalIterableis transformed from typeSerializerto aBuffer.
-
serialize
<T> BlockingIterable<Buffer> serialize(BlockingIterable<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder)
Transforms the passedBlockingIterablesuch that each contained element of typeSerializeris serialized into aBuffer.- Type Parameters:
T- The data type to serialize.- Parameters:
source-BlockingIterablecontaining objects to serialize.allocator- TheBufferAllocatorused to allocateBuffers.typeHolder-TypeHolderholding theParameterizedTypeto be serialized.- Returns:
- A transformed
BlockingIterablesuch that each contained element in the originalBlockingIterableis transformed from typeSerializerto aBuffer.
-
serialize
<T> Publisher<Buffer> serialize(Publisher<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder, java.util.function.IntUnaryOperator bytesEstimator)
Transforms the passedPublishersuch that each contained element of typeSerializeris serialized into aBuffer.- Type Parameters:
T- The data type to serialize.- Parameters:
source-Publishercontaining objects to serialize.allocator- TheBufferAllocatorused to allocateBuffers.typeHolder-TypeHolderholding theParameterizedTypeto be serialized.bytesEstimator- AnIntUnaryOperatorthat given the last serialized size in bytes, estimates the size of the next object to be serialized in bytes.- Returns:
- A transformed
Publishersuch that each contained element in the originalPublisheris transformed from typeSerializerto 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 passedIterablesuch that each contained element of typeSerializeris serialized into aBuffer.- Type Parameters:
T- The data type to serialize.- Parameters:
source-Iterablecontaining objects to serialize.allocator- TheBufferAllocatorused to allocateBuffers.typeHolder-TypeHolderholding theParameterizedTypeto be serialized.bytesEstimator- AnIntUnaryOperatorthat given the last serialized size in bytes, estimates the size of the next object to be serialized in bytes.- Returns:
- A transformed
Iterablesuch that each contained element in the originalIterableis transformed from typeSerializerto aBuffer.
-
serialize
<T> BlockingIterable<Buffer> serialize(BlockingIterable<T> source, BufferAllocator allocator, TypeHolder<T> typeHolder, java.util.function.IntUnaryOperator bytesEstimator)
Transforms the passedBlockingIterablesuch that each contained element of typeSerializeris serialized into aBuffer.- Type Parameters:
T- The data type to serialize.- Parameters:
source-BlockingIterablecontaining objects to serialize.allocator- TheBufferAllocatorused to allocateBuffers.typeHolder-TypeHolderholding theParameterizedTypeto be serialized.bytesEstimator- AnIntUnaryOperatorthat given the last serialized size in bytes, estimates the size of the next object to be serialized in bytes.- Returns:
- A transformed
BlockingIterablesuch that each contained element in the originalBlockingIterableis transformed from typeSerializerto aBuffer.
-
serialize
<T> Buffer serialize(T toSerialize, BufferAllocator allocator)
Serializes the passed objecttoSerializeto the returnedBuffer.- Type Parameters:
T- The data type to serialize.- Parameters:
toSerialize- Object to serialize.allocator-BufferAllocatorto allocate the returnedBuffer.- Returns:
Buffercontaining the serialized representation oftoSerialize.
-
serialize
<T> Buffer serialize(T toSerialize, BufferAllocator allocator, int bytesEstimate)
Serializes the passed objecttoSerializeto the returnedBuffer.- Type Parameters:
T- The data type to serialize.- Parameters:
toSerialize- Object to serialize.allocator-BufferAllocatorto allocate the returnedBuffer.bytesEstimate- An estimate for the size in bytes of the serialized representation oftoSerialize.- Returns:
Buffercontaining the serialized representation oftoSerialize.
-
serialize
<T> void serialize(T toSerialize, Buffer destination)Serializes the passed objecttoSerializeto the passedBuffer.- Type Parameters:
T- The data type to serialize.- Parameters:
toSerialize- Object to serialize.destination- TheBufferto which the serialized representation oftoSerializeis written.
-
deserialize
<T> Publisher<T> deserialize(Publisher<Buffer> source, TypeHolder<T> typeHolder)
Applies a deserializer on the passedPublisherto convert into aPublisherof deserialized instances ofSerializer. If thesourcePublisherterminates with some left over data in a previously emittedBufferbut not deserialized in an object, then the returnedPublisherwill 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-PublishercontainingBuffers to deserialize.typeHolder-TypeHolderholding theParameterizedTypeto be deserialized.- Returns:
- A transformed
Publishersuch that each contained element in the originalPublisheris transformed from typeBufferto an instance ofSerializer.
-
deserialize
<T> CloseableIterable<T> deserialize(java.lang.Iterable<Buffer> source, TypeHolder<T> typeHolder)
Applies a deserializer on the passedIterableto convert into aIterableof deserialized instances ofSerializer. If thesourceIterablecompletes with some left over data in a previously emittedBufferbut not deserialized in an object, thenIteratorfrom the returnedIterablewill throw anSerializationExceptionfromIterator.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-IterablecontainingBuffers to deserialize.typeHolder-TypeHolderholding theParameterizedTypeto be deserialized.- Returns:
- A transformed
CloseableIterablesuch that each contained element in the originalIterableis transformed from typeBufferto an instance ofSerializer.
-
deserialize
<T> BlockingIterable<T> deserialize(BlockingIterable<Buffer> source, TypeHolder<T> typeHolder)
Applies a deserializer on the passedBlockingIterableto convert into aBlockingIterableof deserialized instances ofSerializer. If thesourceBlockingIterablecompletes with some left over data in a previously emittedBufferbut not deserialized in an object, thenBlockingIteratorfrom the returnedBlockingIterablewill throw anSerializationExceptionfromIterator.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-BlockingIterablecontainingBuffers to deserialize.typeHolder-TypeHolderholding theParameterizedTypeto be deserialized.- Returns:
- A transformed
BlockingIterablesuch that each contained element in the originalBlockingIterableis transformed from typeBufferto an instance ofSerializer.
-
deserialize
<T> Publisher<T> deserialize(Publisher<Buffer> source, java.lang.Class<T> type)
Applies a deserializer on the passedPublisherto convert into aPublisherof deserialized instances ofSerializer. If thesourcePublisherterminates with some left over data in a previously emittedBufferbut not deserialized in an object, then the returnedPublisherwill 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-PublishercontainingBuffers to deserialize.type- The class forSerializer, the object to be deserialized.- Returns:
- A transformed
Publishersuch that each contained element in the originalPublisheris transformed from typeBufferto an instance ofSerializer.
-
deserialize
<T> CloseableIterable<T> deserialize(java.lang.Iterable<Buffer> source, java.lang.Class<T> type)
Applies a deserializer on the passedIterableto convert into aCloseableIterableof deserialized instances ofSerializer. If thesourceIterablecompletes with some left over data in a previously emittedBufferbut not deserialized in an object, thenCloseableIteratorfrom the returnedCloseableIterablewill throw anSerializationExceptionfromIterator.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-IterablecontainingBuffers to deserialize.type- The class forSerializer, the object to be deserialized.- Returns:
- A transformed
CloseableIterablesuch that each contained element in the originalIterableis transformed from typeBufferto an instance ofSerializer.
-
deserialize
<T> BlockingIterable<T> deserialize(BlockingIterable<Buffer> source, java.lang.Class<T> type)
Applies a deserializer on the passedBlockingIterableto convert into aIterableof deserialized instances ofSerializer. If thesourceBlockingIterablecompletes with some left over data in a previously emittedBufferbut not deserialized in an object, thenBlockingIteratorfrom the returnedBlockingIterablewill throw anSerializationExceptionfromIterator.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-BlockingIterablecontainingBuffers to deserialize.type- The class forSerializer, the object to be deserialized.- Returns:
- A transformed
BlockingIterablesuch that each contained element in the originalBlockingIterableis transformed from typeBufferto an instance ofSerializer.
-
deserializeAggregated
<T> CloseableIterable<T> deserializeAggregated(Buffer serializedData, java.lang.Class<T> type)
Deserializes the passed encodedBufferto one or more instances ofSerializer.Incomplete data
This method assumes that the passedBuffercontains exact amount of data required to deserialize into at least one complete instance ofSerializer. If there is any left over data in theBufferafter the deserialization is complete,Iterator.hasNext()andIterator.next()methods will eventually throw aSerializationExceptionfrom theCloseableIteratorreturned 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- ABuffercontaining serialized representation of one or more instances ofSerializer.type- The class forSerializer, the object to be deserialized.- Returns:
- An
CloseableIterablecontaining one or more deserialized instances ofSerializer. If there is any left over data in theBufferafter the deserialization is complete,Iterator.hasNext()andIterator.next()methods will eventually throw aSerializationExceptionfrom theCloseableIteratorreturned 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 encodedBufferto zero or more instances ofSerializer.Incomplete data
This method assumes that the passedBuffercontains exact amount of data required to deserialize into at least one complete instance ofSerializer. If there is any left over data in theBufferafter deserialization is complete,Iterator.hasNext()andIterator.next()methods will eventually throw aSerializationExceptionfrom theCloseableIteratorreturned 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- ABuffercontaining serialized representation of one or more instances ofSerializer.typeHolder-TypeHolderholding theParameterizedTypeto be deserialized.- Returns:
- An
CloseableIterablecontaining one or more deserialized instances ofSerializer. If there is any left over data in theBufferafter the deserialization is complete,Iterator.hasNext()andIterator.next()methods will eventually throw aSerializationExceptionfrom theCloseableIteratorreturned 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 encodedBufferto a single instance ofSerializer.- Type Parameters:
T- The data type to deserialize.- Parameters:
serializedData- ABuffercontaining serialized representation of a single instance ofSerializer.type- The class forSerializer, the object to be deserialized.- Returns:
- The deserialized object.
- Throws:
SerializationException- If the passedBuffercontains an incomplete object or if there is any left over data in theBufferafter the deserialization is complete.
-
deserializeAggregatedSingle
<T> T deserializeAggregatedSingle(Buffer serializedData, TypeHolder<T> typeHolder)
Deserializes the passed encodedBufferto a single instance ofSerializer.- Type Parameters:
T- The data type to deserialize.- Parameters:
serializedData- ABuffercontaining serialized representation of a single instance ofSerializer.typeHolder-TypeHolderholding theParameterizedTypeto be deserialized.- Returns:
- The deserialized object.
- Throws:
SerializationException- If the passedBuffercontains an incomplete object or if there is any left over data in theBufferafter the deserialization is complete.
-
-