Class JBBPParser

java.lang.Object
com.igormaznitsa.jbbp.JBBPParser

public final class JBBPParser extends Object
the Main class allows a user to parse a binary stream or block for predefined and precompiled script.
Since:
1.0
  • Field Details

    • FLAG_SKIP_REMAINING_FIELDS_IF_EOF

      public static final int FLAG_SKIP_REMAINING_FIELDS_IF_EOF
      Flag 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_ZERO
      Flag 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_CONTROLLER
      Default expression array size controller. It is doing nothing.
      Since:
      2.1.0
  • Method Details

    • prepare

      public static JBBPParser prepare(String script, JBBPBitOrder bitOrder)
      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 null
      bitOrder - the bit order for reading operations, it must not be null
      Returns:
      the prepared parser for the script
      See Also:
    • prepare

      public static JBBPParser prepare(String script, JBBPBitOrder bitOrder, 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 null
      bitOrder - the bit order for reading operations, it must not be null
      flags - 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 null
      bitOrder - the bit order for reading operations, it must not be null
      customFieldTypeProcessor - custom field type processor, it can be null
      flags - special flags for parsing
      Returns:
      the prepared parser for the script
      Since:
      1.1.1
      See Also:
    • prepare

      public static JBBPParser prepare(String script)
      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 null
      customFieldTypeProcessor - custom field type processor, can be null
      Returns:
      the prepared parser for the script
      Since:
      1.2.0
      See Also:
    • prepare

      public static JBBPParser prepare(String script, int flags)
      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 null
      flags - special flags for parsing
      Returns:
      the prepared parser for the script
      Since:
      1.1
      See Also:
    • getExpressionArraySizeController

      public JBBPParserExpressionArraySizeController 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

      public JBBPFieldStruct parse(InputStream in) throws IOException
      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 null
      varFieldProcessor - a var field processor, it may be null if there is not any var field in a script, otherwise NPE will be thrown during parsing
      externalValueProvider - 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 null
      varFieldProcessor - a var field processor, it may be null if there is not any var field in a script, otherwise NPE will be thrown during parsing
      externalValueProvider - an external value provider, it can be null but only if the script doesn't have fields desired the provider
      arraySizeLimiter - 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 errors
      JBBPReachedArraySizeLimitException - 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

      public JBBPFieldStruct parse(byte[] array) throws IOException
      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 null
      varFieldProcessor - a var field processor, it may be null if there is not any var field in a script, otherwise NPE will be thrown during parsing
      externalValueProvider - 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

      public JBBPCompiledBlock getCompiledBlock()
      Get compiled block containing compiled information for the parser.
      Returns:
      compiled block, must not be null
      Since:
      1.3.0
    • convertToSrc

      public List<ResultSrcItem> convertToSrc(TargetSources target, String name)
      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 null
      name - 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: