Class JBBPDslBuilder

java.lang.Object
com.igormaznitsa.jbbp.utils.JBBPDslBuilder

public class JBBPDslBuilder extends Object
Auxiliary builder to build string JBBP script through sequent method call. NB! The Builder generates JBBP string script which can be compiled by parser!
Since:
1.4.0
See Also:
  • Field Details

    • items

      protected final List<JBBPDslBuilder.Item> items
      The List contains items added into builder.
    • byteOrder

      protected JBBPByteOrder byteOrder
      The Variable contains current byte order for all next fields.
    • openedStructCounter

      protected int openedStructCounter
      Value contains number of currently opened structures.
  • Constructor Details

    • JBBPDslBuilder

      protected JBBPDslBuilder()
      Constructor is private one because can't be called directly.
  • Method Details

    • Begin

      public static JBBPDslBuilder Begin()
      Create new builder.
      Returns:
      the new instance of builder, must not be null
    • assertTextNotNullAndTrimmedNotEmpty

      protected static String assertTextNotNullAndTrimmedNotEmpty(String text)
    • assertNameIfNotNull

      protected static String assertNameIfNotNull(String name)
    • assertExpressionChars

      protected static String assertExpressionChars(String expression)
    • assertNotNegativeAndZero

      protected static int assertNotNegativeAndZero(int value)
    • doTabs

      protected static StringBuilder doTabs(boolean enable, StringBuilder buffer, int tabs)
    • addItem

      protected void addItem(JBBPDslBuilder.Item item)
    • size

      public int size()
      Get number of items added into internal item list.
      Returns:
      number of added items
    • arraySizeToString

      protected String arraySizeToString(int size)
      Auxiliary method to convert numeric value into array size expression.
      Parameters:
      size - size to be converted
      Returns:
      string contains expression which can be used as array size. must not be null
    • Align

      public JBBPDslBuilder Align()
      Add 'align' directive with default value (1 byte).
      Returns:
      the builder instance, must not be null
    • Align

      public JBBPDslBuilder Align(int alignBytes)
      Add 'align' directive.
      Parameters:
      alignBytes - number of bytes to be aligned, must not be zero or negative one
      Returns:
      the builder instance, must not be null
      Throws:
      IllegalArgumentException - if value is not acceptable
    • Align

      public JBBPDslBuilder Align(String sizeExpression)
      Add 'align' directive with size calculated by expression.
      Parameters:
      sizeExpression - expression to be calculated to get align size, must not be null
      Returns:
      the builder instance, must not be null
    • Skip

      public JBBPDslBuilder Skip()
      Add 'skip' directive with default value as one byte.
      Returns:
      the builder instance, must not be null
    • Skip

      public JBBPDslBuilder Skip(int bytesToSkip)
      Add 'skip' directive with number of bytes to be skipped.
      Parameters:
      bytesToSkip - number of bytes to be skipped, must not be zero or negative one
      Returns:
      the builder instance, must not be null
      Throws:
      IllegalArgumentException - if value is not acceptable
    • Skip

      public JBBPDslBuilder Skip(String sizeExpression)
      Add 'skip' directive with number of bytes to be skipped, their number calculated through expression.
      Parameters:
      sizeExpression - expression to be used to calculate number of bytes, must not be null
      Returns:
      the builder instance, must not be null
    • Custom

      public JBBPDslBuilder Custom(String type)
      Add anonymous custom variable.
      Parameters:
      type - custom type, must not be null
      Returns:
      the builder instance, must not be null
    • Var

      public JBBPDslBuilder Var()
      Add var anonymous field.
      Returns:
      the builder instance, must not be null
    • Var

      public JBBPDslBuilder Var(String name)
      Add named var field.
      Parameters:
      name - name of the field, can be null
      Returns:
      the builder instance, must not be null
    • Var

      public JBBPDslBuilder Var(String name, String param)
      Add named var field.
      Parameters:
      name - name of the field, can be null
      param - optional parameter for the field, can be null
      Returns:
      the builder instance, must not be null
    • Custom

      public JBBPDslBuilder Custom(String type, String name)
      Add named custom variable.
      Parameters:
      type - custom type, must not be null
      name - name of the field, can be null for anonymous
      Returns:
      the builder instance, must not be null
    • Custom

      public JBBPDslBuilder Custom(String type, String name, String param)
      Add named parametric custom variable.
      Parameters:
      type - custom type, must not be null
      name - name of the field, can be null for anonymous
      param - optional parameter for the field, can be null
      Returns:
      the builder instance, must not be null
    • Struct

      public JBBPDslBuilder Struct()
      Create new anonymous struct.
      Returns:
      the builder instance, must not be null
    • Struct

      public JBBPDslBuilder Struct(String name)
      Create new named struct.
      Parameters:
      name - name of structure, it can be null for anonymous one
      Returns:
      the builder instance, must not be null
    • StructArray

      public JBBPDslBuilder StructArray(String sizeExpression)
      Create anonymous structure array which size calculated by expression.
      Parameters:
      sizeExpression - expression to calculate array length, must not be null.
      Returns:
      the builder instance, must not be null
    • StructArray

      public JBBPDslBuilder StructArray(int size)
      Create anonymous fixed size structure array.
      Parameters:
      size - fixed size of the array, if negative one then read all steam until the end
      Returns:
      the builder instance, must not be null
    • StructArray

      public JBBPDslBuilder StructArray(String name, int size)
      Create named fixed length structure array.
      Parameters:
      name - name of the structure array, can be null for anonymous one
      size - fixed size of the array, if negative one then read all steam until the end
      Returns:
      the builder instance, must not be null
    • StructArray

      public JBBPDslBuilder StructArray(String name, String sizeExpression)
      Create named structure array which size calculated by expression.
      Parameters:
      name - name of the structure array, can be null for anonymous one
      sizeExpression - expression to calculate array length, must not be null.
      Returns:
      the builder instance, must not be null
    • Val

      public JBBPDslBuilder Val(String name, String expression)
      Add virtual field which not be read but its value will be calculated by expression
      Parameters:
      name - name of the value, it must not be null or empty
      expression - expression to calculate value, it must not be null or empty
      Returns:
      the builder instance, must not be null
    • ResetCounter

      public JBBPDslBuilder ResetCounter()
      Add command to reset counter of the current read stream.
      Returns:
      the builder instance, must not be null
      See Also:
    • VarArray

      public JBBPDslBuilder VarArray(int size)
      Create anonymous var array with fixed size.
      Parameters:
      size - size of the array, if negative then read till end of stream.
      Returns:
      the builder instance, must not be null
    • VarArray

      public JBBPDslBuilder VarArray(String sizeExpression)
      Create anonymous var array with size calculated through expression.
      Parameters:
      sizeExpression - expression to calculate size.
      Returns:
      the builder instance, must not be null
    • VarArray

      public JBBPDslBuilder VarArray(String name, int size)
      Create named var array with fixed size.
      Parameters:
      name - name of the array, can be null for anonymous one
      size - size of the array, if negative then read till end of stream.
      Returns:
      the builder instance, must not be null
    • VarArray

      public JBBPDslBuilder VarArray(String name, String sizeExpression)
      Create named var array with fixed size.
      Parameters:
      name - name of the array, can be null for anonymous one
      sizeExpression - expression to calculate size of the array, must not be null.
      Returns:
      the builder instance, must not be null
    • VarArray

      public JBBPDslBuilder VarArray(String name, int size, String param)
      Create named var array with fixed size.
      Parameters:
      name - name of the array, can be null for anonymous one
      size - size of array, it can be negative if to read stream till end.
      param - optional parameter for the field, can be null
      Returns:
      the builder instance, must not be null
    • VarArray

      public JBBPDslBuilder VarArray(String name, String sizeExpression, String param)
      Create named var array with fixed size.
      Parameters:
      name - name of the array, can be null for anonymous one
      sizeExpression - expression to calculate size of the array, must not be null.
      param - optional parameter for the field, can be null
      Returns:
      the builder instance, must not be null
    • CustomArray

      public JBBPDslBuilder CustomArray(String type, int size)
      Create anonymous custom type array with fixed size.
      Parameters:
      type - custom type, must not be null
      size - size of the array, if less than zero then read till end of stream.
      Returns:
      the builder instance, must not be null
    • CustomArray

      public JBBPDslBuilder CustomArray(String type, String size)
      Create anonymous custom type array with fixed size.
      Parameters:
      type - custom type, must not be null
      size - expression to calculate size of the array, must not be null.
      Returns:
      the builder instance, must not be null
    • CustomArray

      public JBBPDslBuilder CustomArray(String type, String name, String size)
      Create named custom type array with fixed size.
      Parameters:
      type - custom type, must not be null
      name - name of the array, can be null for anonymous one
      size - expression to calculate size of the array, must not be null.
      Returns:
      the builder instance, must not be null
    • CustomArray

      public JBBPDslBuilder CustomArray(String type, String name, int size)
      Create named custom type array with fixed size.
      Parameters:
      type - custom type, must not be null
      name - name of the array, can be null for anonymous one
      size - size of the array, if less than zero then read till end of stream.
      Returns:
      the builder instance, must not be null
    • CustomArray

      public JBBPDslBuilder CustomArray(String type, String name, int size, String param)
      Create named custom type array which size calculated by expression.
      Parameters:
      type - custom type, must not be null
      name - name of the array, can be null for anonymous one
      size - size of the array, if negative then read till the end of stream.
      param - optional parameter for the field, can be null
      Returns:
      the builder instance, must not be null
    • CustomArray

      public JBBPDslBuilder CustomArray(String type, String name, String sizeExpression, String param)
      Create named custom type array which size calculated by expression.
      Parameters:
      type - custom type, must not be null
      name - name of the array, can be null for anonymous one
      sizeExpression - expression to calculate array length, must not be null.
      param - optional parameter for the field, can be null
      Returns:
      the builder instance, must not be null
    • CloseStruct

      public JBBPDslBuilder CloseStruct()
      Add directive to close currently opened structure or a structure array.
      Returns:
      the builder instance, must not be null
      Throws:
      IllegalStateException - if there is not any opened struct
    • CloseStruct

      public JBBPDslBuilder CloseStruct(boolean closeAllOpened)
      Add directive to close currently opened structure or all opened structures.
      Parameters:
      closeAllOpened - flag to close all opened structures if true, false if close only last opened structure
      Returns:
      the builder instance, must not be null
      Throws:
      IllegalStateException - if there is not any opened struct
    • hasOpenedStructs

      public boolean hasOpenedStructs()
      Allows to check that there is an opened structure.
      Returns:
      true if there is any opened structure, false otherwise.
    • Bit

      public JBBPDslBuilder Bit()
      Add anonymous single bit field.
      Returns:
      the builder instance, must not be null
    • Bit

      public JBBPDslBuilder Bit(String name)
      Add named single bit field.
      Parameters:
      name - name of the field, can be null for anonymous one
      Returns:
      the builder instance, must not be null
    • Bits

      public JBBPDslBuilder Bits(int bits)
      Add anonymous fixed size bit field.
      Parameters:
      bits - , number of bits 1..7
      Returns:
      the builder instance, must not be null
    • Bits

      public JBBPDslBuilder Bits(JBBPBitNumber bits)
      Add anonymous fixed size bit field.
      Parameters:
      bits - , number of bits
      Returns:
      the builder instance, must not be null
    • Bits

      public JBBPDslBuilder Bits(String name, JBBPBitNumber bits)
      Add named fixed length bit field.
      Parameters:
      name - name of the field, if null then anonymous one
      bits - number of bits as length of the field, must not be null
      Returns:
      the builder instance, must not be null
    • Bits

      public JBBPDslBuilder Bits(String name, String bitLenExpression)
      Add named bit field which length calculated by expression.
      Parameters:
      name - name of the field, if null then anonymous one
      bitLenExpression - expression to calculate number of bits, must not be null
      Returns:
      the builder instance, must not be null
    • BitArray

      public JBBPDslBuilder BitArray(JBBPBitNumber bits, int size)
      Add anonymous fixed length bit array.
      Parameters:
      bits - length of the field, must not be null
      size - number of elements in array, if negative then till the end of stream
      Returns:
      the builder instance, must not be null
    • BitArray

      public JBBPDslBuilder BitArray(String name, JBBPBitNumber bits, int size)
      Add named fixed length bit array.
      Parameters:
      name - name of the array, if null then anonymous one
      bits - length of the field, must not be null
      size - number of elements in array, if negative then till the end of stream
      Returns:
      the builder instance, must not be null
    • BitArray

      public JBBPDslBuilder BitArray(String name, String bitLenExpression, int size)
      Add named fixed length bit array, size of one bit field is calculated by expression.
      Parameters:
      name - name of the array, if null then anonymous one
      bitLenExpression - expression to calculate length of the bit field, must not be null
      size - number of elements in array, if negative then till the end of stream
      Returns:
      the builder instance, must not be null
    • BitArray

      public JBBPDslBuilder BitArray(JBBPBitNumber bits, String sizeExpression)
      Add anonymous bit array with size calculated through expression.
      Parameters:
      bits - length of the field, must not be null
      sizeExpression - expression to be used to calculate array size, must not be null
      Returns:
      the builder instance, must not be null
    • BitArray

      public JBBPDslBuilder BitArray(String bitLenExpression, String sizeExpression)
      Add anonymous bit array with size calculated through expression.
      Parameters:
      bitLenExpression - expression to calculate length of the bit field, must not be null
      sizeExpression - expression to be used to calculate array size, must not be null
      Returns:
      the builder instance, must not be null
    • BitArray

      public JBBPDslBuilder BitArray(String name, JBBPBitNumber bits, String sizeExpression)
      Add named bit array with size calculated through expression.
      Parameters:
      name - name of the array, if null then anonymous one
      bits - length of the field, must not be null
      sizeExpression - expression to be used to calculate array size, must not be null
      Returns:
      the builder instance, must not be null
    • BitArray

      public JBBPDslBuilder BitArray(String name, String bitLenExpression, String sizeExpression)
      Add named bit array where each bit length is calculated through expression.
      Parameters:
      name - name of the array, if null then anonymous one
      bitLenExpression - expression to calculate length of the bit field, must not be null
      sizeExpression - expression to be used to calculate array size, must not be null
      Returns:
      the builder instance, must not be null
    • BoolArray

      public JBBPDslBuilder BoolArray(String sizeExpression)
      Add anonymous boolean array with size calculated through expression.
      Parameters:
      sizeExpression - expression to be used to calculate array size, must not be null
      Returns:
      the builder instance, must not be null
    • BoolArray

      public JBBPDslBuilder BoolArray(String name, int size)
      Add named fixed size boolean array.
      Parameters:
      name - name of the array, it can be null for anonymous one
      size - number of elements in array, if negative then till the end of stream
      Returns:
      the builder instance, must not be null
    • BoolArray

      public JBBPDslBuilder BoolArray(int size)
      Add anonymous fixed size boolean array.
      Parameters:
      size - number of elements in array, if negative then till the end of stream
      Returns:
      the builder instance, must not be null
    • BoolArray

      public JBBPDslBuilder BoolArray(String name, String sizeExpression)
      Add named boolean array which length calculated through expression.
      Parameters:
      name - name of the array, it can be null for anonymous one
      sizeExpression - expression to calculate number of elements, must not be null
      Returns:
      the builder instance, must not be null
    • Bool

      public JBBPDslBuilder Bool()
      Add an anonymous boolean field.
      Returns:
      the builder instance, must not be null
    • Bool

      public JBBPDslBuilder Bool(String name)
      Add named boolean field.
      Parameters:
      name - name of the field, can be null for anonymous one
      Returns:
      the builder instance, must not be null
    • Byte

      public JBBPDslBuilder Byte()
      Add anonymous signed byte field.
      Returns:
      the builder instance, must not be null
    • Byte

      public JBBPDslBuilder Byte(String name)
      Add named signed byte field.
      Parameters:
      name - name of the field, can be null for anonymous one
      Returns:
      the builder instance, must not be null
    • ByteArray

      public JBBPDslBuilder ByteArray(String sizeExpression)
      Add anonymous byte array which size calculated through expression.
      Parameters:
      sizeExpression - expression to be used to calculate array length, must not be null or empty.
      Returns:
      the builder instance, must not be null
    • ByteArray

      public JBBPDslBuilder ByteArray(int size)
      Add anonymous fixed size byte array.
      Parameters:
      size - size of the array, if negative then read stream till the end.
      Returns:
      the builder instance, must not be null
    • ByteArray

      public JBBPDslBuilder ByteArray(String name, int size)
      Add named fixed size byte array.
      Parameters:
      name - name of the array, it can be null fo anonymous fields
      size - size of the array, if negative then read stream till the end.
      Returns:
      the builder instance, must not be null
    • ByteArray

      public JBBPDslBuilder ByteArray(String name, String sizeExpression)
      Add named byte array which size calculated through expression.
      Parameters:
      name - name of the array, it can be null for anonymous fields
      sizeExpression - expression to be used to calculate array length, must not be null or empty.
      Returns:
      the builder instance, must not be null
    • UByte

      public JBBPDslBuilder UByte()
      Add anonymous unsigned byte field.
      Returns:
      the builder instance, must not be null
    • UByte

      public JBBPDslBuilder UByte(String name)
      Add named unsigned byte field.
      Parameters:
      name - name of the field, can be null for anonymous one
      Returns:
      the builder instance, must not be null
    • UByteArray

      public JBBPDslBuilder UByteArray(String sizeExpression)
      Added anonymous unsigned byte array which size calculated through expression.
      Parameters:
      sizeExpression - expression to be used to calculate size, must not be null or empty
      Returns:
      the builder instance, must not be null
    • UByteArray

      public JBBPDslBuilder UByteArray(int size)
      Add anonymous fixed size unsigned byte array.
      Parameters:
      size - size of the array, if negative then read stream till the end.
      Returns:
      the builder instance, must not be null
    • UByteArray

      public JBBPDslBuilder UByteArray(String name, int size)
      Add named fixed size unsigned byte array.
      Parameters:
      name - name of the field, it can be null for anonymous one
      size - size of the array, if negative then read stream till the end.
      Returns:
      the builder instance, must not be null
    • UByteArray

      public JBBPDslBuilder UByteArray(String name, String sizeExpression)
      Add named unsigned byte array which size calculated through expression.
      Parameters:
      name - name of the field, it can be null for anonymous one
      sizeExpression - expression to calculate array size, must ot be null or empty.
      Returns:
      the builder instance, must not be null
    • Short

      public JBBPDslBuilder Short()
      Added anonymous signed short field.
      Returns:
      the builder instance, must not be null
    • Short

      public JBBPDslBuilder Short(String name)
      Add named signed short field.
      Parameters:
      name - name of the field, can be null for anonymous one
      Returns:
      the builder instance, must not be null
    • ShortArray

      public JBBPDslBuilder ShortArray(String sizeExpression)
      Add anonymous signed short array which size calculated through expression.
      Parameters:
      sizeExpression - expression to be used for calculation, must not be null
      Returns:
      the builder instance, must not be null
    • ShortArray

      public JBBPDslBuilder ShortArray(int size)
      Add anonymous fixed size signed short array.
      Parameters:
      size - size of the array, if negative then stream will be read till end
      Returns:
      the builder instance, must not be null
    • ShortArray

      public JBBPDslBuilder ShortArray(String name, int size)
      Add named fixed size signed short array.
      Parameters:
      name - name of the field, if null then anonymous
      size - size of the array, if negative then stream will be read till end
      Returns:
      the builder instance, must not be null
    • ShortArray

      public JBBPDslBuilder ShortArray(String name, String sizeExpression)
      Add named fixed signed short array which size calculated through expression.
      Parameters:
      name - name of the field, if null then anonymous
      sizeExpression - expression to be used to calculate size, must not be null
      Returns:
      the builder instance, must not be null
    • UShort

      public JBBPDslBuilder UShort()
      Add anonymous unsigned short field.
      Returns:
      the builder instance, must not be null
    • UShort

      public JBBPDslBuilder UShort(String name)
      Add named unsigned short field.
      Parameters:
      name - name of the field, can be null for anonymous
      Returns:
      the builder instance, must not be null
    • UShortArray

      public JBBPDslBuilder UShortArray(String sizeExpression)
      Add anonymous unsigned short array which size calculated through expression.
      Parameters:
      sizeExpression - expression to be used for calculation, must not be null
      Returns:
      the builder instance, must not be null
    • UShortArray

      public JBBPDslBuilder UShortArray(int size)
      Add anonymous fixed size unsigned short array.
      Parameters:
      size - sizeof the array, if negative then read till the end of stream
      Returns:
      the builder instance, must not be null
    • UShortArray

      public JBBPDslBuilder UShortArray(String name, String sizeExpression)
      Add named fixed unsigned short array which size calculated through expression.
      Parameters:
      name - name of the field, if null then anonymous
      sizeExpression - expression to be used to calculate size, must not be null
      Returns:
      the builder instance, must not be null
    • UShortArray

      public JBBPDslBuilder UShortArray(String name, int size)
      Add named fixed size unsigned short array.
      Parameters:
      name - name of the field, if null then anonymous
      size - size of the array, if negative then stream will be read till end
      Returns:
      the builder instance, must not be null
    • Int

      public JBBPDslBuilder Int()
      Add anonymous integer field.
      Returns:
      the builder instance, must not be null
    • Int

      public JBBPDslBuilder Int(String name)
      Add named integer field.
      Parameters:
      name - name of the field, can be null for anonymous
      Returns:
      the builder instance, must not be null
    • IntArray

      public JBBPDslBuilder IntArray(String sizeExpression)
      Add anonymous integer array with size calculated through expression.
      Parameters:
      sizeExpression - expression to be used to calculate size, must not be null
      Returns:
      the builder instance, must not be null
    • IntArray

      public JBBPDslBuilder IntArray(int size)
      Add anonymous fixed size integer array.
      Parameters:
      size - size of the array, if negative then read stream till the end
      Returns:
      the builder instance, must not be null
    • IntArray

      public JBBPDslBuilder IntArray(String name, int size)
      Add named fixed size integer array.
      Parameters:
      name - name of field, it can be null for anonymous
      size - size of the array, if negative then read stream till the end
      Returns:
      the builder instance, must not be null
    • IntArray

      public JBBPDslBuilder IntArray(String name, String sizeExpression)
      Add named integer array with size calculated through expression.
      Parameters:
      name - name of field, can be nul for anonymous
      sizeExpression - expression to be used to calculate size, must not be null
      Returns:
      the builder instance, must not be null
    • Long

      public JBBPDslBuilder Long()
      Add anonymous long field.
      Returns:
      the builder instance, must not be null
    • Long

      public JBBPDslBuilder Long(String name)
      Add named long field.
      Parameters:
      name - name of the field, can be null for anonymous
      Returns:
      the builder instance, must not be null
    • LongArray

      public JBBPDslBuilder LongArray(String sizeExpression)
      Add anonymous long array which size calculated through expression.
      Parameters:
      sizeExpression - expression to be used to calculate size, must not be null
      Returns:
      the builder instance, must not be null
    • LongArray

      public JBBPDslBuilder LongArray(int size)
      Add anonymous fixed size long array.
      Parameters:
      size - size of array, if negative then read till stream end
      Returns:
      the builder instance, must not be null
    • LongArray

      public JBBPDslBuilder LongArray(String name, int size)
      Add named fixed size long array field.
      Parameters:
      name - name of field, can be null for anonymous
      size - size of array, if negative then read till stream end
      Returns:
      the builder instance, must not be null
    • LongArray

      public JBBPDslBuilder LongArray(String name, String sizeExpression)
      Add named long array which size calculated through expression.
      Parameters:
      name - name of the field, can be null for anonymous
      sizeExpression - expression to be used to calculate size, must not be null
      Returns:
      the builder instance, must not be null
    • Float

      public JBBPDslBuilder Float()
      Add anonymous float field.
      Returns:
      the builder instance, must not be null
    • Float

      public JBBPDslBuilder Float(String name)
      Add named float field
      Parameters:
      name - name of the field, can be null for anonymous
      Returns:
      the builder instance, must not be null
    • FloatArray

      public JBBPDslBuilder FloatArray(String sizeExpression)
      Add anonymous float array which size calculated through expression.
      Parameters:
      sizeExpression - expression to be used to calculate size, must not be null
      Returns:
      the builder instance, must not be null
    • FloatArray

      public JBBPDslBuilder FloatArray(int size)
      Add anonymous fixed size float array.
      Parameters:
      size - size of array, if negative then read till stream end
      Returns:
      the builder instance, must not be null
    • FloatArray

      public JBBPDslBuilder FloatArray(String name, int size)
      Add named fixed size float array.
      Parameters:
      name - name of field, null for anonymous
      size - size of array, read till stream end if negative
      Returns:
      the builder instance, must not be null
    • FloatArray

      public JBBPDslBuilder FloatArray(String name, String sizeExpression)
      Add named float array which size calculated through expression.
      Parameters:
      name - name of the field, can be null for anonymous
      sizeExpression - expression to be used to calculate size, must not be null
      Returns:
      the builder instance, must not be null
    • Double

      public JBBPDslBuilder Double()
      Add anonymous double field.
      Returns:
      the builder instance, must not be null
    • UInt

      public JBBPDslBuilder UInt()
      Add anonymous unsigned int field.
      Returns:
      the builder instance, must not be null
      Since:
      2.0.4
    • Double

      public JBBPDslBuilder Double(String name)
      Add named double field.
      Parameters:
      name - name of the field, can be null for anonymous
      Returns:
      the builder instance, must not be null
    • UInt

      public JBBPDslBuilder UInt(String name)
      Add named unsigned int field.
      Parameters:
      name - name of the field, can be null for anonymous
      Returns:
      the builder instance, must not be null
      Since:
      2.0.4
    • Comment

      public JBBPDslBuilder Comment(String text)
      Add comment, in case that a field followed by the comment, the comment will be placed on the same line as field definition.
      Parameters:
      text - text of comment, can be null
      Returns:
      the builder instance, must not be null
    • NewLineComment

      public JBBPDslBuilder NewLineComment(String text)
      Add comment which will be placed on new line.
      Parameters:
      text - text of comment, can be null
      Returns:
      the builder instance, must not be null
      Since:
      1.4.1
    • DoubleArray

      public JBBPDslBuilder DoubleArray(String sizeExpression)
      Add anonymous double array field which size calculated trough expression.
      Parameters:
      sizeExpression - expression to be used to calculate array size, must not be null
      Returns:
      the builder instance, must not be null
    • DoubleArray

      public JBBPDslBuilder DoubleArray(int size)
      Add anonymous fixed size double array field.
      Parameters:
      size - size of the array, if negative then read till end of stream
      Returns:
      the builder instance, must not be null
    • UIntArray

      public JBBPDslBuilder UIntArray(int size)
      Add anonymous fixed size unsigned int array field.
      Parameters:
      size - size of the array, if negative then read till end of stream
      Returns:
      the builder instance, must not be null
      Since:
      2.0.4
    • DoubleArray

      public JBBPDslBuilder DoubleArray(String name, int size)
      Add named fixed size double array field.
      Parameters:
      name - ame of the field, can be null for anonymous
      size - size of the array, if negative then read till end of stream
      Returns:
      the builder instance, must not be null
    • UIntArray

      public JBBPDslBuilder UIntArray(String name, String sizeExpression)
      Add named unsigned integer array field which size calculated trough expression.
      Parameters:
      name - name of the field, can be null for anonymous
      sizeExpression - expression to be used to calculate array size, must not be null
      Returns:
      the builder instance, must not be null
      Since:
      2.0.4
    • DoubleArray

      public JBBPDslBuilder DoubleArray(String name, String sizeExpression)
      Add named double array field which size calculated trough expression.
      Parameters:
      name - name of the field, can be null for anonymous
      sizeExpression - expression to be used to calculate array size, must not be null
      Returns:
      the builder instance, must not be null
    • UIntArray

      public JBBPDslBuilder UIntArray(String name, int size)
      Add named fixed size unsigned int array field.
      Parameters:
      name - ame of the field, can be null for anonymous
      size - size of the array, if negative then read till end of stream
      Returns:
      the builder instance, must not be null
      Since:
      2.0.4
    • String

      public JBBPDslBuilder String()
      Add anonymous string field.
      Returns:
      the builder instance, must not be null
    • String

      public JBBPDslBuilder String(String name)
      Add named string field.
      Parameters:
      name - name of field, can be null for anonymous one
      Returns:
      the builder instance, must not be null
    • StringArray

      public JBBPDslBuilder StringArray(String sizeExpression)
      Add anonymous string array which size calculated through expression.
      Parameters:
      sizeExpression - expression to calculate size, must not be null
      Returns:
      the builder instance, must not be null
    • StringArray

      public JBBPDslBuilder StringArray(int size)
      Add anonymous fixed size string array.
      Parameters:
      size - size of array, if negative then read till stream end
      Returns:
      the builder instance, must not be null
    • StringArray

      public JBBPDslBuilder StringArray(String name, int size)
      Add named fixed size string array.
      Parameters:
      name - name of field, can be null for anonymous
      size - size of array, if negative then read till stream end
      Returns:
      the builder instance, must not be null
    • StringArray

      public JBBPDslBuilder StringArray(String name, String sizeExpression)
      Add named string array which size calculated through expression.
      Parameters:
      name - name of field, can be null for anonymous
      sizeExpression - expression to calculate size, must not be null
      Returns:
      the builder instance, must not be null
    • ByteOrder

      public JBBPDslBuilder ByteOrder(JBBPByteOrder order)
      Set byte order for next fields
      Parameters:
      order - order, if null then BIG_ENDIAN
      Returns:
      the builder instance, must not be null
    • End

      public String End()
      Build non-formatted script.
      Returns:
      script in non-formatted form, must not be null
      Throws:
      IllegalStateException - if there is an unclosed struct
    • End

      public String End(boolean format)
      Build a formatted script.
      Parameters:
      format - if true then make some formatting of result, false if non-formatted version allowed
      Returns:
      script in formatted form, must not be null
      Throws:
      IllegalStateException - if there is an unclosed struct
    • collectAnnotatedFields

      protected JBBPDslBuilder.BinFieldContainer collectAnnotatedFields(Class<?> annotatedClass)
      Allows to collect all fields which can be used for scripting.
      Parameters:
      annotatedClass - class to be processed, must not be null
      Returns:
      container which contains all found items
    • AnnotatedClass

      public JBBPDslBuilder AnnotatedClass(Class<?> annotatedClass)
      Convert an annotated class into its JBBP DSL representation. NB! the method creates structure bases on class name, so that it can't be used for auto-mapping if you want use auto-mapping, use AnnotatedClassFields(Class)
      Parameters:
      annotatedClass - class to be converted into JBBP script, must not be null
      Returns:
      the builder instance, must not be null
      See Also:
    • AnnotatedClassFields

      public JBBPDslBuilder AnnotatedClassFields(Class<?> annotatedClass)
      Add just fields of annotated class, outbound class will not be added as structure. The Method allows to prepare script which will be able make mapping of field values
      Parameters:
      annotatedClass - class to be converted into JBBP script, must not be null
      Returns:
      the builder instance, must not be null
      See Also:
    • addAnnotatedClass

      protected JBBPDslBuilder addAnnotatedClass(Class<?> annotatedClass, boolean onlyFields)