Class ProtobufDecoder
java.lang.Object
io.micronaut.serde.LimitingStream
io.micronaut.serde.protobuf.ProtobufDecoder
- All Implemented Interfaces:
Decoder, KeysAwareDecoder, AutoCloseable
Protocol Buffers implementation of
Decoder.
The payload carries field numbers, not names, so every structure is decoded against the
ProtoSchema of the type being read into. Fields whose numbers the schema does not know
are skipped, which is how protobuf stays forward compatible.
Repeated fields arrive in one of two shapes and both are handled: a packed run, which is one length-delimited block of values, or a sequence of separately tagged values.
- Since:
- 3.2
-
Nested Class Summary
Nested classes/interfaces inherited from class LimitingStream
LimitingStream.RemainingLimits -
Field Summary
Fields inherited from class LimitingStream
DEFAULT_LIMITS, DEFAULT_MAXIMUM_DEPTHFields inherited from interface KeysAwareDecoder
MATCH_END_OBJECT, MATCH_UNKNOWN_NAME -
Constructor Summary
ConstructorsConstructorDescriptionProtobufDecoder(byte[] payload, LimitingStream.RemainingLimits remainingLimits, Deserializer.DecoderContext decoderContext) Create a root decoder over a complete protobuf payload. -
Method Summary
Modifier and TypeMethodDescriptioncreateDeserializationException(String message, @Nullable Object invalidValue) Creates an exception for the given message.Decodes the current state into an arbitrary object.decodeArray(io.micronaut.core.type.Argument<?> type) Start decoding an array.Decodes a BigDecimal.Decodes a BigInteger.byte[]Decode binary data from this stream.booleanDecodes a boolean.Buffer the whole subtree of this value and return it as a newDecoder.byteDecodes a byte.charDecodes a char.doubleDecodes a double.floatDecodes a float.intDecodes a int.@Nullable StringDecodes a key, if there are no more keys to decode returnsnull.intDecode the next object key and match it against the supplied key set.longDecodes a long.io.micronaut.json.tree.JsonNodeDecodes the current state into aJsonNode.booleanAttempt to decode a null value.decodeObject(io.micronaut.core.type.Argument<?> type) Decodes an object.shortDecodes a short.Decodes a string.voidfinishStructure(boolean consumeLeftElements) booleanvoidSkips the current value.Methods inherited from class LimitingStream
childLimits, decreaseDepth, increaseDepth, limitsFromConfiguration, ourLimitsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Decoder
close, decodeArray, decodeBigDecimalNullable, decodeBigIntegerNullable, decodeBinaryNullable, decodeBooleanNullable, decodeByteNullable, decodeCharNullable, decodeDoubleNullable, decodeFloatNullable, decodeIntNullable, decodeLongNullable, decodeNumber, decodeNumberNullable, decodeObject, decodeShortNullable, decodeStringNullable, finishStructure, getCoercionPolicy
-
Constructor Details
-
ProtobufDecoder
public ProtobufDecoder(byte[] payload, LimitingStream.RemainingLimits remainingLimits, Deserializer.DecoderContext decoderContext) Create a root decoder over a complete protobuf payload.- Parameters:
payload- The payloadremainingLimits- The nesting limitsdecoderContext- The decoder context, used to resolve deserializers for nested values
-
-
Method Details
-
decodeObject
Description copied from interface:DecoderDecodes an object.- Specified by:
decodeObjectin interfaceDecoder- Parameters:
type- The type, nevernull- Returns:
- The object decoder
- Throws:
IOException- If an unrecoverable error occurs
-
decodeArray
Description copied from interface:DecoderStart decoding an array.- Specified by:
decodeArrayin interfaceDecoder- Parameters:
type- The array type- Returns:
- The array decoder
- Throws:
IOException- If an unrecoverable error occurs
-
hasNextArrayValue
- Specified by:
hasNextArrayValuein interfaceDecoder- Returns:
- Returns
trueif another array value is available. - Throws:
IOException- If an unrecoverable error occurs
-
decodeKey
Description copied from interface:KeysAwareDecoderDecode the next object key and match it against the supplied key set. A non-negative result is the matched key index.KeysAwareDecoder.MATCH_UNKNOWN_NAMEmeans the current key is available throughDecoder.decodeKey()and is guaranteed not to match the suppliedKeys.- Specified by:
decodeKeyin interfaceKeysAwareDecoder- Parameters:
keys- The keys- Returns:
- The matched key index,
KeysAwareDecoder.MATCH_END_OBJECT, orKeysAwareDecoder.MATCH_UNKNOWN_NAME - Throws:
IOException- If an unrecoverable error occurs
-
decodeKey
Description copied from interface:DecoderDecodes a key, if there are no more keys to decode returnsnull.- Specified by:
decodeKeyin interfaceDecoder- Returns:
- The key or
nullif there aren't any more keys - Throws:
IOException- If an unrecoverable error occurs
-
decodeString
Description copied from interface:DecoderDecodes a string.- Specified by:
decodeStringin interfaceDecoder- Returns:
- The string, never
null - Throws:
IOException- If an unrecoverable error occurs
-
decodeBoolean
Description copied from interface:DecoderDecodes a boolean.- Specified by:
decodeBooleanin interfaceDecoder- Returns:
- The boolean
- Throws:
IOException- If an unrecoverable error occurs
-
decodeByte
Description copied from interface:DecoderDecodes a byte.- Specified by:
decodeBytein interfaceDecoder- Returns:
- The byte
- Throws:
IOException- If an unrecoverable error occurs
-
decodeShort
Description copied from interface:DecoderDecodes a short.- Specified by:
decodeShortin interfaceDecoder- Returns:
- The short
- Throws:
IOException- If an unrecoverable error occurs
-
decodeChar
Description copied from interface:DecoderDecodes a char.- Specified by:
decodeCharin interfaceDecoder- Returns:
- The char
- Throws:
IOException- If an unrecoverable error occurs
-
decodeInt
Description copied from interface:DecoderDecodes a int.- Specified by:
decodeIntin interfaceDecoder- Returns:
- The int
- Throws:
IOException- If an unrecoverable error occurs
-
decodeLong
Description copied from interface:DecoderDecodes a long.- Specified by:
decodeLongin interfaceDecoder- Returns:
- The long
- Throws:
IOException- If an unrecoverable error occurs
-
decodeFloat
Description copied from interface:DecoderDecodes a float.- Specified by:
decodeFloatin interfaceDecoder- Returns:
- The float
- Throws:
IOException- If an unrecoverable error occurs
-
decodeDouble
Description copied from interface:DecoderDecodes a double.- Specified by:
decodeDoublein interfaceDecoder- Returns:
- The double
- Throws:
IOException- If an unrecoverable error occurs
-
decodeBigInteger
Description copied from interface:DecoderDecodes a BigInteger.- Specified by:
decodeBigIntegerin interfaceDecoder- Returns:
- The BigInteger, never
null - Throws:
IOException- If an unrecoverable error occurs
-
decodeBigDecimal
Description copied from interface:DecoderDecodes a BigDecimal.- Specified by:
decodeBigDecimalin interfaceDecoder- Returns:
- The BigDecimal, never
null - Throws:
IOException- If an unrecoverable error occurs
-
decodeBinary
Description copied from interface:DecoderDecode binary data from this stream. Binary data can be serialized in multiple different ways that differ by format.- An array of numbers must be supported by all implementations, for compatibility. This is also the default implementation.
- A base64 string. This is convenient for text-based formats like json, and is supported by jackson.
- A format-specific type, for binary formats such as bson.
- Other format specific behavior. Oracle JDBC Json will parse strings as hex, for example.
Implementations must support the array shape, but the other shapes are optional.
- Specified by:
decodeBinaryin interfaceDecoder- Returns:
- The decoded byte array
- Throws:
IOException
-
decodeNull
public boolean decodeNull()Description copied from interface:DecoderAttempt to decode a null value. Returnsfalseif this value is not null, and another method should be used for decoding. Returnstrueif this value was null, and the cursor has been advanced to the next value.- Specified by:
decodeNullin interfaceDecoder- Returns:
- Returns
trueif the value wasnull
-
decodeArbitrary
Description copied from interface:DecoderDecodes the current state into an arbitrary object.The following should be decoded by this method:
- Specified by:
decodeArbitraryin interfaceDecoder- Returns:
- The decoded object
- Throws:
IOException- If an unrecoverable error occurs
-
decodeNode
Description copied from interface:DecoderDecodes the current state into aJsonNode.- Specified by:
decodeNodein interfaceDecoder- Returns:
- The decoded node
- Throws:
IOException- If an unrecoverable error occurs
-
decodeBuffer
Description copied from interface:DecoderBuffer the whole subtree of this value and return it as a newDecoder. The returnedDecodercan be used independently to thisDecoder. This means actual parsing of the subtree can be delayed.The returned
Decodershould behave identically to thisDecoder. This means that for exampledecoder.decodeDouble()should be equivalent todecoder.decodeBuffer().decodeDouble().- Specified by:
decodeBufferin interfaceDecoder- Returns:
- An independent decoder that visits this subtree.
- Throws:
IOException- If an unrecoverable error occurs
-
skipValue
Description copied from interface:DecoderSkips the current value.- Specified by:
skipValuein interfaceDecoder- Throws:
IOException- If an unrecoverable error occurs
-
finishStructure
- Specified by:
finishStructurein interfaceDecoder- Parameters:
consumeLeftElements- True to consume left elements- Throws:
IOException- If an unrecoverable error occurs
-
createDeserializationException
Description copied from interface:DecoderCreates an exception for the given message.- Specified by:
createDeserializationExceptionin interfaceDecoder- Parameters:
message- The message, nevernullinvalidValue- The invalid value. Can benull.- Returns:
- The exception, never
null
-