mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-22 14:09:25 +00:00
Polishing in Protobuf support
See gh-35403
This commit is contained in:
+2
-2
@@ -47,8 +47,8 @@ public abstract class ProtobufCodecSupport {
|
||||
if (mimeType == null) {
|
||||
return true;
|
||||
}
|
||||
for (MimeType m : MIME_TYPES) {
|
||||
if (m.isCompatibleWith(mimeType)) {
|
||||
for (MimeType supportedMimeType : MIME_TYPES) {
|
||||
if (supportedMimeType.isCompatibleWith(mimeType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -129,8 +129,7 @@ public class ProtobufDecoder extends ProtobufCodecSupport implements Decoder<Mes
|
||||
public Flux<Message> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
|
||||
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
||||
|
||||
MessageDecoderFunction decoderFunction =
|
||||
new MessageDecoderFunction(elementType, this.maxMessageSize);
|
||||
MessageDecoderFunction decoderFunction = new MessageDecoderFunction(elementType, this.maxMessageSize);
|
||||
|
||||
return Flux.from(inputStream)
|
||||
.flatMapIterable(decoderFunction)
|
||||
|
||||
+16
-5
@@ -131,12 +131,19 @@ public class ProtobufJsonDecoder implements Decoder<Message> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Message> decode(Publisher<DataBuffer> inputStream, ResolvableType targetType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
||||
return Flux.error(new UnsupportedOperationException("Protobuf decoder does not support Flux, use Mono<List<...>> instead."));
|
||||
public Flux<Message> decode(
|
||||
Publisher<DataBuffer> inputStream, ResolvableType targetType, @Nullable MimeType mimeType,
|
||||
@Nullable Map<String, Object> hints) {
|
||||
|
||||
return Flux.error(new UnsupportedOperationException(
|
||||
"Protobuf decoder does not support Flux, use Mono<List<...>> instead."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message decode(DataBuffer dataBuffer, ResolvableType targetType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) throws DecodingException {
|
||||
public Message decode(
|
||||
DataBuffer dataBuffer, ResolvableType targetType, @Nullable MimeType mimeType,
|
||||
@Nullable Map<String, Object> hints) throws DecodingException {
|
||||
|
||||
try {
|
||||
Message.Builder builder = getMessageBuilder(targetType.toClass());
|
||||
this.parser.merge(new InputStreamReader(dataBuffer.asInputStream()), builder);
|
||||
@@ -164,10 +171,14 @@ public class ProtobufJsonDecoder implements Decoder<Message> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Message> decodeToMono(Publisher<DataBuffer> inputStream, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
||||
public Mono<Message> decodeToMono(
|
||||
Publisher<DataBuffer> inputStream, ResolvableType elementType, @Nullable MimeType mimeType,
|
||||
@Nullable Map<String, Object> hints) {
|
||||
|
||||
return DataBufferUtils.join(inputStream, this.maxMessageSize)
|
||||
.map(dataBuffer -> decode(dataBuffer, elementType, mimeType, hints))
|
||||
.onErrorMap(DataBufferLimitException.class, exc -> new DecodingException("Could not decode JSON as Protobuf message", exc));
|
||||
.onErrorMap(DataBufferLimitException.class,
|
||||
exc -> new DecodingException("Could not decode JSON as Protobuf message", exc));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
@@ -257,6 +257,7 @@ public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverter<M
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Protobuf format support.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user