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);
}
}
Aggregations