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 Summary
ConstructorDescriptionProtonScanningContext
(Class<?> expectedType, List<Type> entries, List<ProtonBuffer> encodedEntries) ProtonScanningContext
(Class<?> expectedType, Type entry, ProtonBuffer encodedEntry) -
Method Summary
Modifier and TypeMethodDescriptionstatic ProtonScanningContext<String>
createStringScanContext
(String... entries) Creates a new scanning context for the given collection ofString
values.static ProtonScanningContext<String>
createStringScanContext
(Collection<String> entries) Creates a new scanning context for the given collection ofString
values.static ProtonScanningContext<Symbol>
createSymbolScanContext
(Collection<Symbol> entries) Creates a new scanning context for the given collection ofSymbol
values.static ProtonScanningContext<Symbol>
createSymbolScanContext
(Symbol... entries) Creates a new scanning context for the given collection ofSymbol
values.boolean
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.boolean
matches
(StreamTypeDecoder<?> typeDecoder, InputStream stream, int encodedSize, Consumer<Type> matchConsumer) Returns true if the encoded entry bytes match against the search domain of the scan matching context and calls the provided matchConsumer
with the original unencoded form of the matched entry.boolean
matches
(TypeDecoder<?> typeDecoder, ProtonBuffer candidate, int candidateLength, Consumer<Type> matchConsumer) Returns true if the encoded entry bytes match against the search domain of the scan matching context and calls the provided matchConsumer
with the original unencoded form of the matched entry.void
reset()
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.
-
Constructor Details
-
ProtonScanningContext
-
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 interfaceScanningContext<Type>
- Specified by:
reset
in interfaceStreamScanningContext<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 toScanningContext.matches(TypeDecoder, ProtonBuffer, int, Consumer)
should return false as the target has already been found.- Specified by:
isComplete
in interfaceScanningContext<Type>
- Specified by:
isComplete
in interfaceStreamScanningContext<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 matchConsumer
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 interfaceScanningContext<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 bytesmatchConsumer
- 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 matchConsumer
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 anUnsupportedOperationException
if it is not supported.- Specified by:
matches
in interfaceStreamScanningContext<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 bytesmatchConsumer
- 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
Creates a new scanning context for the given collection ofString
values.- Parameters:
entries
- TheString
entries that will be scanned for in the encodedMap
- Returns:
- a
StreamScanningContext
for the collection of string entries.
-
createStringScanContext
Creates a new scanning context for the given collection ofString
values.- Parameters:
entries
- TheString
entries that will be scanned for in the encodedMap
- Returns:
- a
StreamScanningContext
for the collection of string entries.
-
createSymbolScanContext
Creates a new scanning context for the given collection ofSymbol
values.- Parameters:
entries
- TheSymbol
entries that will be scanned for in the encodedMap
- Returns:
- a
StreamScanningContext
for the collection of symbol entries.
-
createSymbolScanContext
Creates a new scanning context for the given collection ofSymbol
values.- Parameters:
entries
- TheSymbol
entries that will be scanned for in the encodedMap
- Returns:
- a
StreamScanningContext
for the collection of symbol entries.
-