Package com.igormaznitsa.jbbp
Class JBBPParser
java.lang.Object
com.igormaznitsa.jbbp.JBBPParser
the Main class allows a user to parse a binary stream or block for predefined
and precompiled script.
- Since:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final JBBPParserExpressionArraySizeControllerDefault expression array size controller.static final intFlag to recognize negative expression results by zero.static final intFlag shows that if EOF and not whole packet has been read then remaining fields will be just ignored without exception. -
Method Summary
Modifier and TypeMethodDescriptionconvertToSrc(TargetSources target, String name) Convert the prepared parser into sources.Get compiled block containing compiled information for the parser.Get current registered instance of controller to check array size calculated by expression.longGet the final input stream byte counter value for the last parsing operation.intgetFlags()Get the parse flags.parse(byte[] array) Parse a byte array content.parse(byte[] array, JBBPVarFieldProcessor varFieldProcessor, JBBPExternalValueProvider externalValueProvider) Parse a byte array content.parse(InputStream in) Parse an input stream.parse(InputStream in, JBBPVarFieldProcessor varFieldProcessor, JBBPExternalValueProvider externalValueProvider) Parse am input stream with defined external value provider.parse(InputStream in, JBBPVarFieldProcessor varFieldProcessor, JBBPExternalValueProvider externalValueProvider, JBBPArraySizeLimiter arraySizeLimiter) Parse am input stream with defined external value provider.static JBBPParserPrepare a parser for a script with default bit order (LSB0) use.static JBBPParserPrepare a parser for a script with default bit order (LSB0) use and special flagsstatic JBBPParserprepare(String script, JBBPBitOrder bitOrder) Prepare a parser for a script and a bit order.static JBBPParserprepare(String script, JBBPBitOrder bitOrder, int flags) Prepare a parser for a script with defined a bit order and special flags.static JBBPParserprepare(String script, JBBPBitOrder bitOrder, JBBPCustomFieldTypeProcessor customFieldTypeProcessor, int flags) Prepare a parser for a script with defined a bit order and special flags.static JBBPParserprepare(String script, JBBPCustomFieldTypeProcessor customFieldTypeProcessor) Prepare a parser for a script with default bit order (LSB0) use and with defined custom type field processor.setExpressionArraySizeController(JBBPParserExpressionArraySizeController arraySizeController) Set current registered instance of controller to check array size calculated by expression.
-
Field Details
-
FLAG_SKIP_REMAINING_FIELDS_IF_EOF
public static final int FLAG_SKIP_REMAINING_FIELDS_IF_EOFFlag shows that if EOF and not whole packet has been read then remaining fields will be just ignored without exception.- See Also:
-
FLAG_NEGATIVE_EXPRESSION_RESULT_AS_ZERO
public static final int FLAG_NEGATIVE_EXPRESSION_RESULT_AS_ZEROFlag to recognize negative expression results by zero.- Since:
- 1.4.0
- See Also:
-
DEFAULT_EXPRESSION_ARRAY_SIZE_CONTROLLER
public static final JBBPParserExpressionArraySizeController DEFAULT_EXPRESSION_ARRAY_SIZE_CONTROLLERDefault expression array size controller. It is doing nothing.- Since:
- 2.1.0
-
-
Method Details
-
prepare
Prepare a parser for a script and a bit order.- Parameters:
script- a text script contains field order and types reference, it must not be nullbitOrder- the bit order for reading operations, it must not be null- Returns:
- the prepared parser for the script
- See Also:
-
prepare
Prepare a parser for a script with defined a bit order and special flags.- Parameters:
script- a text script contains field order and types reference, it must not be nullbitOrder- the bit order for reading operations, it must not be nullflags- special flags for parsing- Returns:
- the prepared parser for the script
- Since:
- 1.1
- See Also:
-
prepare
public static JBBPParser prepare(String script, JBBPBitOrder bitOrder, JBBPCustomFieldTypeProcessor customFieldTypeProcessor, int flags) Prepare a parser for a script with defined a bit order and special flags.- Parameters:
script- a text script contains field order and types reference, it must not be nullbitOrder- the bit order for reading operations, it must not be nullcustomFieldTypeProcessor- custom field type processor, it can be nullflags- special flags for parsing- Returns:
- the prepared parser for the script
- Since:
- 1.1.1
- See Also:
-
prepare
Prepare a parser for a script with default bit order (LSB0) use.- Parameters:
script- a text script contains field order and types reference, it must not be null- Returns:
- the prepared parser for the script
- See Also:
-
prepare
public static JBBPParser prepare(String script, JBBPCustomFieldTypeProcessor customFieldTypeProcessor) Prepare a parser for a script with default bit order (LSB0) use and with defined custom type field processor.- Parameters:
script- a text script contains field order and types reference, it must not be nullcustomFieldTypeProcessor- custom field type processor, can be null- Returns:
- the prepared parser for the script
- Since:
- 1.2.0
- See Also:
-
prepare
Prepare a parser for a script with default bit order (LSB0) use and special flags- Parameters:
script- a text script contains field order and types reference, it must not be nullflags- special flags for parsing- Returns:
- the prepared parser for the script
- Since:
- 1.1
- See Also:
-
getExpressionArraySizeController
Get current registered instance of controller to check array size calculated by expression.- Returns:
- current instance of array size observer, can't be null
- Since:
- 2.1.0
-
setExpressionArraySizeController
public JBBPParser setExpressionArraySizeController(JBBPParserExpressionArraySizeController arraySizeController) Set current registered instance of controller to check array size calculated by expression.- Parameters:
arraySizeController- instance of array size observer, must not be null.- Returns:
- instance of the parser.
- Throws:
NullPointerException- if argument is null- Since:
- 2.1.0
- See Also:
-
parse
Parse an input stream.- Parameters:
in- an input stream which content should be parsed, it must not be null- Returns:
- the parsed content as the root structure
- Throws:
IOException- it will be thrown for transport errors
-
parse
public JBBPFieldStruct parse(InputStream in, JBBPVarFieldProcessor varFieldProcessor, JBBPExternalValueProvider externalValueProvider) throws IOException Parse am input stream with defined external value provider.- Parameters:
in- an input stream which content will be parsed, it must not be nullvarFieldProcessor- a var field processor, it may be null if there is not any var field in a script, otherwise NPE will be thrown during parsingexternalValueProvider- an external value provider, it can be null but only if the script doesn't have fields desired the provider- Returns:
- the parsed content as the root structure
- Throws:
IOException- it will be thrown for transport errors
-
parse
public JBBPFieldStruct parse(InputStream in, JBBPVarFieldProcessor varFieldProcessor, JBBPExternalValueProvider externalValueProvider, JBBPArraySizeLimiter arraySizeLimiter) throws IOException Parse am input stream with defined external value provider.- Parameters:
in- an input stream which content will be parsed, it must not be nullvarFieldProcessor- a var field processor, it may be null if there is not any var field in a script, otherwise NPE will be thrown during parsingexternalValueProvider- an external value provider, it can be null but only if the script doesn't have fields desired the providerarraySizeLimiter- limiter to read whole stream arrays, must not be null- Returns:
- the parsed content as the root structure
- Throws:
IOException- it will be thrown for transport errorsJBBPReachedArraySizeLimitException- thrown if reached limit for a whole stream array- Since:
- 2.1.0
- See Also:
-
getFlags
public int getFlags()Get the parse flags.- Returns:
- the parser flags
- See Also:
-
parse
Parse a byte array content.- Parameters:
array- a byte array which content should be parsed, it must not be null- Returns:
- the parsed content as the root structure
- Throws:
IOException- it will be thrown for transport errors
-
parse
public JBBPFieldStruct parse(byte[] array, JBBPVarFieldProcessor varFieldProcessor, JBBPExternalValueProvider externalValueProvider) throws IOException Parse a byte array content.- Parameters:
array- a byte array which content should be parsed, it must not be nullvarFieldProcessor- a var field processor, it may be null if there is not any var field in a script, otherwise NPE will be thrown during parsingexternalValueProvider- an external value provider, it can be null but only if the script doesn't have fields desired the provider- Returns:
- the parsed content as the root structure
- Throws:
IOException- it will be thrown for transport errors
-
getFinalStreamByteCounter
public long getFinalStreamByteCounter()Get the final input stream byte counter value for the last parsing operation. It is loaded just after exception or parsing completion. NB: It is appropriate one only if the parsing didn't make any counter reset operation.- Returns:
- the last parsing byte counter value
-
getCompiledBlock
Get compiled block containing compiled information for the parser.- Returns:
- compiled block, must not be null
- Since:
- 1.3.0
-
convertToSrc
Convert the prepared parser into sources. It doesn't provide way to define different flag for conversion, it uses default flags for converters and provided for short fast way.- Parameters:
target- target to generate sources, must not be nullname- name of result, depends on target, must not be null, for instance class name (example 'com.test.jbbp.Parser')- Returns:
- list of source items generated during operation, must not be null and must not be empty
- Throws:
IllegalArgumentException- if target is unsupported- Since:
- 1.3.0
- See Also:
-