Search in sources :

Example 1 with DefaultSerializer

use of io.servicetalk.serialization.api.DefaultSerializer in project servicetalk by apple.

the class ProtoBufSerializationProviderBuilder method build0.

@SuppressWarnings("unchecked")
private void build0() {
    for (Map.Entry<Class<? extends MessageLite>, Parser<? extends MessageLite>> entry : types.entrySet()) {
        Class<MessageLite> messageType = (Class<MessageLite>) entry.getKey();
        Parser<MessageLite> parser = (Parser<MessageLite>) entry.getValue();
        Map<ContentCodec, HttpSerializer> serializersForType = new HashMap<>();
        Map<ContentCodec, HttpDeserializer> deserializersForType = new HashMap<>();
        for (ContentCodec codec : supportedCodings) {
            DefaultSerializer serializer = new DefaultSerializer(new ProtoBufSerializationProvider<>(messageType, codec, parser));
            HttpSerializer<MessageLite> httpSerializer = new ProtoHttpSerializer<>(serializer, codec, messageType);
            serializersForType.put(codec, httpSerializer);
            deserializersForType.put(codec, new HttpDeserializer<MessageLite>() {

                @Override
                public MessageLite deserialize(final HttpHeaders headers, final Buffer payload) {
                    return serializer.deserializeAggregatedSingle(payload, messageType);
                }

                @Override
                public BlockingIterable<MessageLite> deserialize(final HttpHeaders headers, final BlockingIterable<Buffer> payload) {
                    return serializer.deserialize(payload, messageType);
                }

                @Override
                public Publisher<MessageLite> deserialize(final HttpHeaders headers, final Publisher<Buffer> payload) {
                    return serializer.deserialize(payload, messageType);
                }
            });
        }
        serializers.put(messageType, serializersForType);
        deserializers.put(messageType, deserializersForType);
    }
}
Also used : HttpHeaders(io.servicetalk.http.api.HttpHeaders) HashMap(java.util.HashMap) DefaultSerializer(io.servicetalk.serialization.api.DefaultSerializer) HttpDeserializer(io.servicetalk.http.api.HttpDeserializer) BlockingIterable(io.servicetalk.concurrent.BlockingIterable) HttpSerializer(io.servicetalk.http.api.HttpSerializer) Buffer(io.servicetalk.buffer.api.Buffer) Publisher(io.servicetalk.concurrent.api.Publisher) MessageLite(com.google.protobuf.MessageLite) ContentCodec(io.servicetalk.encoding.api.ContentCodec) Parser(com.google.protobuf.Parser) HashMap(java.util.HashMap) Map(java.util.Map) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap)

Aggregations

MessageLite (com.google.protobuf.MessageLite)1 Parser (com.google.protobuf.Parser)1 Buffer (io.servicetalk.buffer.api.Buffer)1 BlockingIterable (io.servicetalk.concurrent.BlockingIterable)1 Publisher (io.servicetalk.concurrent.api.Publisher)1 ContentCodec (io.servicetalk.encoding.api.ContentCodec)1 HttpDeserializer (io.servicetalk.http.api.HttpDeserializer)1 HttpHeaders (io.servicetalk.http.api.HttpHeaders)1 HttpSerializer (io.servicetalk.http.api.HttpSerializer)1 DefaultSerializer (io.servicetalk.serialization.api.DefaultSerializer)1 Collections.unmodifiableMap (java.util.Collections.unmodifiableMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1