Class ProtonScanningContext<Type>

java.lang.Object
org.apache.qpid.protonj2.codec.decoders.ProtonScanningContext<Type>
All Implemented Interfaces:
ScanningContext<Type>, StreamScanningContext<Type>

public class ProtonScanningContext<Type> extends Object implements ScanningContext<Type>, StreamScanningContext<Type>
  • Constructor Details

    • ProtonScanningContext

      public ProtonScanningContext(Class<?> expectedType, Type entry, ProtonBuffer encodedEntry)
    • ProtonScanningContext

      public ProtonScanningContext(Class<?> expectedType, List<Type> entries, List<ProtonBuffer> encodedEntries)
  • Method Details

    • reset

      public void reset()
      Description copied from interface: ScanningContext
      Reset the context to its original state at the end of a complete scan which should allow the context to be used again when a new scan is started (e.g. ScanningContext.isComplete() should start returning false).
      Specified by:
      reset in interface ScanningContext<Type>
      Specified by:
      reset in interface StreamScanningContext<Type>
    • isComplete

      public boolean isComplete()
      Description copied from interface: ScanningContext
      Allows for the scanner to optimize reading of encoded data by determining if the target of the matching context has been found in which case the scanner can consume any remaining encoded bytes without regard for the matcher. In this state any call to ScanningContext.matches(TypeDecoder, ProtonBuffer, int, Consumer) should return false as the target has already been found.
      Specified by:
      isComplete in interface ScanningContext<Type>
      Specified by:
      isComplete in interface StreamScanningContext<Type>
      Returns:
      true if the target of the matching context has already been found.
    • matches

      public boolean matches(TypeDecoder<?> typeDecoder, ProtonBuffer candidate, int candidateLength, Consumer<Type> matchConsumer)
      Description copied from interface: ScanningContext
      Returns true if the encoded entry bytes match against the search domain of the scan matching context and calls the provided match Consumer with the original unencoded form of the matched entry. The caller must provide the size of the encoded value being checked to allow for pass of the source bytes without copying which could contain more entries following the candidate value in question.

      The matcher must not alter the read offset of the provided buffer, doing so can corrupt the buffer state and likely cause decode exceptions on follow on decode operations.

      Specified by:
      matches in interface ScanningContext<Type>
      Parameters:
      typeDecoder - The type decoder of the encoded type that is contained in the buffer.
      candidate - Buffer whose first read index is the start of the encoded bytes.
      candidateLength - The region of the candidate buffer that contains the encoded bytes
      matchConsumer - An optional consumer that should be called if a match is found.
      Returns:
      true if the candidate matches a target in the search domain.
    • matches

      public boolean matches(StreamTypeDecoder<?> typeDecoder, InputStream stream, int encodedSize, Consumer<Type> matchConsumer)
      Description copied from interface: StreamScanningContext
      Returns true if the encoded entry bytes match against the search domain of the scan matching context and calls the provided match Consumer with the original unencoded form of the matched entry. The caller must provide the size of the encoded value being checked to allow for pass of the source bytes without copying which could contain more entries following the candidate value in question.

      The implementation must not consume the encoded bytes which requires that the provided InputStream support mark and reset of the stream position. The implementation should check for mark support in the provided stream and throw an UnsupportedOperationException if it is not supported.

      Specified by:
      matches in interface StreamScanningContext<Type>
      Parameters:
      typeDecoder - The stream type decoder of the encoded type that is contained in the buffer.
      stream - Buffer whose first read index is the start of the encoded bytes.
      encodedSize - The region of the candidate buffer that contains the encoded bytes
      matchConsumer - An optional consumer that should be called if a match is found.
      Returns:
      true if the candidate matches a target in the search domain.
    • createStringScanContext

      public static ProtonScanningContext<String> createStringScanContext(String... entries)
      Creates a new scanning context for the given collection of String values.
      Parameters:
      entries - The String entries that will be scanned for in the encoded Map
      Returns:
      a StreamScanningContext for the collection of string entries.
    • createStringScanContext

      public static ProtonScanningContext<String> createStringScanContext(Collection<String> entries)
      Creates a new scanning context for the given collection of String values.
      Parameters:
      entries - The String entries that will be scanned for in the encoded Map
      Returns:
      a StreamScanningContext for the collection of string entries.
    • createSymbolScanContext

      public static ProtonScanningContext<Symbol> createSymbolScanContext(Symbol... entries)
      Creates a new scanning context for the given collection of Symbol values.
      Parameters:
      entries - The Symbol entries that will be scanned for in the encoded Map
      Returns:
      a StreamScanningContext for the collection of symbol entries.
    • createSymbolScanContext

      public static ProtonScanningContext<Symbol> createSymbolScanContext(Collection<Symbol> entries)
      Creates a new scanning context for the given collection of Symbol values.
      Parameters:
      entries - The Symbol entries that will be scanned for in the encoded Map
      Returns:
      a StreamScanningContext for the collection of symbol entries.