mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Polishing in Protobuf decoders
See gh-37147
This commit is contained in:
+11
-12
@@ -173,18 +173,6 @@ public class ProtobufDecoder extends ProtobufCodecSupport implements Decoder<Mes
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use merge methods on {@link Message.Builder} to read a single message
|
||||
* from the given {@code DataBuffer}.
|
||||
* @since 7.0
|
||||
*/
|
||||
protected void merge(DataBuffer dataBuffer, Message.Builder builder) throws IOException {
|
||||
ByteBuffer byteBuffer = ByteBuffer.allocate(dataBuffer.readableByteCount());
|
||||
dataBuffer.toByteBuffer(byteBuffer);
|
||||
builder.mergeFrom(CodedInputStream.newInstance(byteBuffer), this.extensionRegistry);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new {@code Message.Builder} instance for the given class.
|
||||
* <p>This method uses a ConcurrentHashMap for caching method lookups.
|
||||
@@ -198,6 +186,17 @@ public class ProtobufDecoder extends ProtobufCodecSupport implements Decoder<Mes
|
||||
return (Message.Builder) method.invoke(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use merge methods on {@link Message.Builder} to read a single message
|
||||
* from the given {@code DataBuffer}.
|
||||
* @since 7.0
|
||||
*/
|
||||
protected void merge(DataBuffer dataBuffer, Message.Builder builder) throws IOException {
|
||||
ByteBuffer byteBuffer = ByteBuffer.allocate(dataBuffer.readableByteCount());
|
||||
dataBuffer.toByteBuffer(byteBuffer);
|
||||
builder.mergeFrom(CodedInputStream.newInstance(byteBuffer), this.extensionRegistry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MimeType> getDecodableMimeTypes() {
|
||||
return getMimeTypes();
|
||||
|
||||
+13
-13
@@ -95,6 +95,19 @@ public class ProtobufHttpMessageWriter extends EncoderHttpMessageWriter<Message>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@code Message.Builder} instance for the given class.
|
||||
* <p>This method uses a ConcurrentHashMap for caching method lookups.
|
||||
*/
|
||||
protected static Message.Builder getMessageBuilder(Class<?> clazz) throws Exception {
|
||||
Method method = methodCache.get(clazz);
|
||||
if (method == null) {
|
||||
method = clazz.getMethod("newBuilder");
|
||||
methodCache.put(clazz, method);
|
||||
}
|
||||
return (Message.Builder) method.invoke(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@code MediaType} to use when the input Publisher is multivalued.
|
||||
* @since 7.0
|
||||
@@ -118,17 +131,4 @@ public class ProtobufHttpMessageWriter extends EncoderHttpMessageWriter<Message>
|
||||
protected void extendHeaders(ReactiveHttpOutputMessage message, Map<String, Object> hints) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@code Message.Builder} instance for the given class.
|
||||
* <p>This method uses a ConcurrentHashMap for caching method lookups.
|
||||
*/
|
||||
protected static Message.Builder getMessageBuilder(Class<?> clazz) throws Exception {
|
||||
Method method = methodCache.get(clazz);
|
||||
if (method == null) {
|
||||
method = clazz.getMethod("newBuilder");
|
||||
methodCache.put(clazz, method);
|
||||
}
|
||||
return (Message.Builder) method.invoke(clazz);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user