Interface KeysAwareDecoder

All Superinterfaces:
AutoCloseable, Decoder
All Known Implementing Classes:
BsonReaderDecoder, JacksonDecoder, ProtobufDecoder

@Internal public interface KeysAwareDecoder extends Decoder
Optional decoder capability for matching object keys against a known key set.
Since:
3.1
Author:
Denis Stepanov
  • Field Details

    • MATCH_END_OBJECT

      static final int MATCH_END_OBJECT
      Marker for case where the end of an object was encountered.
      See Also:
    • MATCH_UNKNOWN_NAME

      static final int MATCH_UNKNOWN_NAME
      Marker for case where a property name was encountered but not matched by the Keys supplied to decodeKey(Keys). After this marker is returned, callers should obtain the unmatched property name with Decoder.decodeKey() and handle it as unknown for that same key set. Implementations must not return this marker for a property that matches the supplied keys.
      See Also:
  • Method Details

    • of

      static KeysAwareDecoder of(Decoder decoder)
      Adapt the decoder to the keys-aware contract.
      Parameters:
      decoder - The decoder
      Returns:
      A keys-aware decoder
    • decodeKey

      int decodeKey(Keys keys) throws IOException
      Decode the next object key and match it against the supplied key set. A non-negative result is the matched key index. MATCH_UNKNOWN_NAME means the current key is available through Decoder.decodeKey() and is guaranteed not to match the supplied Keys.
      Parameters:
      keys - The keys
      Returns:
      The matched key index, MATCH_END_OBJECT, or MATCH_UNKNOWN_NAME
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeStringValue

      default int decodeStringValue(Keys values) throws IOException
      Decode the next value if it is a string that is one of the supplied constant values, such as the serialized names of the constants of an enum. A non-negative result is the index of the matched value, which is then consumed. MATCH_UNKNOWN_NAME means the value was not consumed: it is not a string, is not one of the values, or the decoder does not match values, and the caller decodes it as usual.
      Parameters:
      values - The values
      Returns:
      The matched value index or MATCH_UNKNOWN_NAME
      Throws:
      IOException - If an unrecoverable error occurs
      Since:
      3.3
    • decodeStringValue

      static int decodeStringValue(Decoder decoder, Keys values) throws IOException
      Decode the next value with any decoder if it is a string that is one of the supplied constant values, see decodeStringValue(Keys).
      Parameters:
      decoder - The decoder
      values - The values
      Returns:
      The matched value index or MATCH_UNKNOWN_NAME
      Throws:
      IOException - If an unrecoverable error occurs
      Since:
      3.3