Class AbstractMapTypeDecoder

java.lang.Object
org.apache.qpid.protonj2.codec.decoders.AbstractPrimitiveTypeDecoder<Map>
org.apache.qpid.protonj2.codec.decoders.primitives.AbstractMapTypeDecoder
All Implemented Interfaces:
MapTypeDecoder, PrimitiveTypeDecoder<Map>, StreamTypeDecoder<Map>, TypeDecoder<Map>
Direct Known Subclasses:
Map32TypeDecoder, Map8TypeDecoder

public abstract class AbstractMapTypeDecoder extends AbstractPrimitiveTypeDecoder<Map> implements MapTypeDecoder
Base for the various Map type decoders used to read AMQP Map values.
  • Constructor Details

    • AbstractMapTypeDecoder

      public AbstractMapTypeDecoder()
  • Method Details

    • readValue

      public Map<Object,Object> readValue(ProtonBuffer buffer, DecoderState state) throws DecodeException
      Description copied from interface: TypeDecoder
      Reads the next type from the given buffer and returns it.
      Specified by:
      readValue in interface TypeDecoder<Map>
      Parameters:
      buffer - the source of encoded data.
      state - the current state of the decoder.
      Returns:
      the next instance in the stream that this decoder handles.
      Throws:
      DecodeException - if an error is encountered while reading the next value.
    • skipValue

      public void skipValue(ProtonBuffer buffer, DecoderState state) throws DecodeException
      Description copied from interface: TypeDecoder
      Skips over the bytes that compose the type this descriptor decodes.

      Skipping values can be used when the type is not used or processed by the application doing the decoding. An example might be an AMQP message decoder that only needs to decode certain parts of the message and not others.

      Specified by:
      skipValue in interface TypeDecoder<Map>
      Parameters:
      buffer - The buffer that contains the encoded type.
      state - The decoder state.
      Throws:
      DecodeException - if an error occurs while skipping the value.
    • scanKeys

      public <KeyType> void scanKeys(ProtonBuffer buffer, DecoderState state, ScanningContext<KeyType> context, BiConsumer<KeyType,Object> matchConsumer) throws DecodeException
      Description copied from interface: MapTypeDecoder
      Scan the encoded Map keys matching on predetermined key value encodings to quickly find mappings that are of interest and then only decoding the value portion of the matched key / value pair. This allows for quick checks of incoming Map types without the performance penalty of a full decode. After the method returns the contexts of the encoded Map in the provided buffer will have been consumed and the next type can be decoded.

      Each matching key / value mapping triggers a call to the provided BiConsumer with the key that triggered the match (generally a cached non-decoded value) and the decoded value mapped to that key. The caller should use the consumer to trigger actions based on the matches found in the mappings which avoid full decodings of large maps when only a limited set of values is desired.

      Specified by:
      scanKeys in interface MapTypeDecoder
      Type Parameters:
      KeyType - The key type is used when calling the match consumer
      Parameters:
      buffer - The buffer containing the encoded Map type.
      state - The DecoderState used during this decode.
      context - The previously created and configured ScanningContext
      matchConsumer - The consumer that will be notified when a matching key is found.
      Throws:
      DecodeException - if an error occurs reading the value
    • readValue

      public Map<Object,Object> readValue(InputStream stream, StreamDecoderState state) throws DecodeException
      Description copied from interface: StreamTypeDecoder
      Reads the next type from the given buffer and returns it.
      Specified by:
      readValue in interface StreamTypeDecoder<Map>
      Parameters:
      stream - the source of encoded data.
      state - the current state of the decoder.
      Returns:
      the next instance in the stream that this decoder handles.
      Throws:
      DecodeException - if an error is encountered while reading the next value.
    • skipValue

      public void skipValue(InputStream stream, StreamDecoderState state) throws DecodeException
      Description copied from interface: StreamTypeDecoder
      Skips over the bytes that compose the type this descriptor decodes.

      Skipping values can be used when the type is not used or processed by the application doing the decoding. An example might be an AMQP message decoder that only needs to decode certain parts of the message and not others.

      Specified by:
      skipValue in interface StreamTypeDecoder<Map>
      Parameters:
      stream - The stream that contains the encoded type.
      state - The decoder state.
      Throws:
      DecodeException - if an error occurs while skipping the value.
    • scanKeys

      public <KeyType> void scanKeys(InputStream stream, StreamDecoderState state, StreamScanningContext<KeyType> context, BiConsumer<KeyType,Object> matchConsumer) throws DecodeException
      Description copied from interface: MapTypeDecoder
      Scan the encoded Map keys matching on predetermined key value encodings to quickly find mappings that are of interest and then only decoding the value portion of the matched key / value pair. This allows for quick checks of incoming Map types without the performance penalty of a full decode. After the method returns the contexts of the encoded Map in the provided stream will have been consumed and the next type can be decoded.

      Each matching key / value mapping triggers a call to the provided BiConsumer with the key that triggered the match (generally a cached non-decoded value) and the decoded value mapped to that key. The caller should use the consumer to trigger actions based on the matches found in the mappings which avoid full decodings of large maps when only a limited set of values is desired.

      Specified by:
      scanKeys in interface MapTypeDecoder
      Type Parameters:
      KeyType - The key type is used when calling the match consumer
      Parameters:
      stream - The InputStream containing the encoded Map type.
      state - The StreamDecoderState used during this decode.
      context - The previously created and configured ScanningContext
      matchConsumer - The consumer that will be notified when a matching key is found.
      Throws:
      DecodeException - if an error occurs reading the value