Class JBBPToJavaConverter
java.lang.Object
com.igormaznitsa.jbbp.compiler.conversion.CompiledBlockVisitor
com.igormaznitsa.jbbp.compiler.conversion.JBBPToJavaConverter
Converter to produce Java class sources (1.6+) from JBBPParser. If a parser
contains variable field, custom fields or external values in expressions then
the result class will be abstract one and its abstract methods must be
implemented in successor.
- Since:
- 1.3.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder to build instance of converter. -
Field Summary
Fields inherited from class com.igormaznitsa.jbbp.compiler.conversion.CompiledBlockVisitor
compiledBlock, parserFlags -
Method Summary
Modifier and TypeMethodDescriptionconvert()Do conversion.Get result of the conversion process.static JBBPToJavaConverter.BuildermakeBuilder(JBBPParser parser) Make new builder.voidvisitActionItem(int offsetInCompiledBlock, int actionType, JBBPIntegerValueEvaluator nullableArgument) Visit an action item (like skip, align or reset counter command)voidvisitBitField(int offsetInCompiledBlock, JBBPByteOrder byteOrder, JBBPNamedFieldInfo nullableNameFieldInfo, boolean readWholeStream, JBBPIntegerValueEvaluator notNullFieldSize, JBBPIntegerValueEvaluator nullableArraySize) Visit a custom type field.voidvisitCustomField(int offsetInCompiledBlock, JBBPFieldTypeParameterContainer notNullFieldType, JBBPNamedFieldInfo nullableNameFieldInfo, JBBPByteOrder byteOrder, boolean readWholeStream, JBBPIntegerValueEvaluator nullableArraySizeEvaluator, JBBPIntegerValueEvaluator extraDataValueEvaluator) Visit a custom type field.voidvisitEnd()Called after visit each item.voidvisitPrimitiveField(int offsetInCompiledBlock, int primitiveType, JBBPNamedFieldInfo nullableNameFieldInfo, JBBPByteOrder byteOrder, boolean readWholeStreamAsArray, boolean altFieldType, JBBPIntegerValueEvaluator nullableArraySize) Visit a primitive data fieldvoidCalled before visit of each item.voidvisitStructureEnd(int offsetInCompiledBlock, JBBPNamedFieldInfo nullableNameFieldInfo) End visit of a structurevoidvisitStructureStart(int offsetInCompiledBlock, JBBPByteOrder byteOrder, boolean readWholeStream, JBBPNamedFieldInfo nullableNameFieldInfo, JBBPIntegerValueEvaluator nullableArraySize) Visit a structure field.voidvisitValField(int offsetInCompiledBlock, JBBPByteOrder byteOrder, JBBPNamedFieldInfo nameFieldInfo, JBBPIntegerValueEvaluator expression) Visit field contains virtual field defined through VAL type.voidvisitVarField(int offsetInCompiledBlock, JBBPNamedFieldInfo nullableNameFieldInfo, JBBPByteOrder byteOrder, boolean readWholeStream, JBBPIntegerValueEvaluator nullableArraySizeEvaluator, JBBPIntegerValueEvaluator extraDataValue) Visit a variable field (which is defined with var data type)Methods inherited from class com.igormaznitsa.jbbp.compiler.conversion.CompiledBlockVisitor
isFlagSkipRemainingFieldsIfEOF, visit
-
Method Details
-
makeBuilder
Make new builder.- Parameters:
parser- parser instance to be used as the base for translation, must not be null- Returns:
- the new builder instance, must not be null.
-
convert
Do conversion.- Returns:
- generated class with needed parameters as text, must not be null.
-
visitStart
public void visitStart()Description copied from class:CompiledBlockVisitorCalled before visit of each item.- Overrides:
visitStartin classCompiledBlockVisitor
-
getResult
Get result of the conversion process.- Returns:
- the result, it will not be null if the process completed without errors.
-
visitEnd
public void visitEnd()Description copied from class:CompiledBlockVisitorCalled after visit each item.- Overrides:
visitEndin classCompiledBlockVisitor
-
visitStructureStart
public void visitStructureStart(int offsetInCompiledBlock, JBBPByteOrder byteOrder, boolean readWholeStream, JBBPNamedFieldInfo nullableNameFieldInfo, JBBPIntegerValueEvaluator nullableArraySize) Description copied from class:CompiledBlockVisitorVisit a structure field.- Overrides:
visitStructureStartin classCompiledBlockVisitor- Parameters:
offsetInCompiledBlock- offset in the compiled blockbyteOrder- byte order for the field, must not be nullreadWholeStream- true if whole stream should be read as array of var type, false otherwisenullableNameFieldInfo- field info, null if the field is anonymous onenullableArraySize- if not null then evaluator of array size to be read from stream
-
visitStructureEnd
Description copied from class:CompiledBlockVisitorEnd visit of a structure- Overrides:
visitStructureEndin classCompiledBlockVisitor- Parameters:
offsetInCompiledBlock- offset in the compiled blocknullableNameFieldInfo- field info, null if the field is anonymous one
-
visitValField
public void visitValField(int offsetInCompiledBlock, JBBPByteOrder byteOrder, JBBPNamedFieldInfo nameFieldInfo, JBBPIntegerValueEvaluator expression) Description copied from class:CompiledBlockVisitorVisit field contains virtual field defined through VAL type.- Overrides:
visitValFieldin classCompiledBlockVisitor- Parameters:
offsetInCompiledBlock- offset in the compiled blockbyteOrder- byteOrdernameFieldInfo- name of the field, must not be nullexpression- expression to calculate value
-
visitPrimitiveField
public void visitPrimitiveField(int offsetInCompiledBlock, int primitiveType, JBBPNamedFieldInfo nullableNameFieldInfo, JBBPByteOrder byteOrder, boolean readWholeStreamAsArray, boolean altFieldType, JBBPIntegerValueEvaluator nullableArraySize) Description copied from class:CompiledBlockVisitorVisit a primitive data field- Overrides:
visitPrimitiveFieldin classCompiledBlockVisitor- Parameters:
offsetInCompiledBlock- offset in the compiled blockprimitiveType- the primitive typenullableNameFieldInfo- field info, null if the field is anonymous onebyteOrder- byte order for the field, must not be nullreadWholeStreamAsArray- if true then it is an array with unknown size till the stream endaltFieldType- flag shows that field type is alternative one, INT should be recognized as FLOAT and LONG as DOUBLE and BOOL as STRINGnullableArraySize- array size if the field is array, null if the field is not array or variable length array- See Also:
-
visitBitField
public void visitBitField(int offsetInCompiledBlock, JBBPByteOrder byteOrder, JBBPNamedFieldInfo nullableNameFieldInfo, boolean readWholeStream, JBBPIntegerValueEvaluator notNullFieldSize, JBBPIntegerValueEvaluator nullableArraySize) Description copied from class:CompiledBlockVisitorVisit a custom type field.- Overrides:
visitBitFieldin classCompiledBlockVisitor- Parameters:
offsetInCompiledBlock- offset in the compiled blockbyteOrder- byte order for the field, must not be nullnullableNameFieldInfo- field info, null if the field is anonymous onereadWholeStream- true if whole stream should be read as array of var type, false otherwisenotNullFieldSize- evaluator to calculate size of the field, must not be nullnullableArraySize- if not null then evaluator of array size to be read from stream
-
visitCustomField
public void visitCustomField(int offsetInCompiledBlock, JBBPFieldTypeParameterContainer notNullFieldType, JBBPNamedFieldInfo nullableNameFieldInfo, JBBPByteOrder byteOrder, boolean readWholeStream, JBBPIntegerValueEvaluator nullableArraySizeEvaluator, JBBPIntegerValueEvaluator extraDataValueEvaluator) Description copied from class:CompiledBlockVisitorVisit a custom type field.- Overrides:
visitCustomFieldin classCompiledBlockVisitor- Parameters:
offsetInCompiledBlock- offset in the compiled blocknotNullFieldType- field type info, must not be nullnullableNameFieldInfo- field info, null if the field is anonymous onebyteOrder- byte order for the field, must not be nullreadWholeStream- true if whole stream should be read as array of var type, false otherwisenullableArraySizeEvaluator- if not null then evaluator of array size to be read from streamextraDataValueEvaluator- if not null then extra data evaluator for the var field
-
visitVarField
public void visitVarField(int offsetInCompiledBlock, JBBPNamedFieldInfo nullableNameFieldInfo, JBBPByteOrder byteOrder, boolean readWholeStream, JBBPIntegerValueEvaluator nullableArraySizeEvaluator, JBBPIntegerValueEvaluator extraDataValue) Description copied from class:CompiledBlockVisitorVisit a variable field (which is defined with var data type)- Overrides:
visitVarFieldin classCompiledBlockVisitor- Parameters:
offsetInCompiledBlock- offset in the compiled blocknullableNameFieldInfo- field info, null if the field is anonymous onebyteOrder- byte order for the field, must not be nullreadWholeStream- true if whole stream should be read as array of var type, false otherwisenullableArraySizeEvaluator- if not null then evaluator of array size to be read from streamextraDataValue- if not null then extra data evaluator for the var field
-
visitActionItem
public void visitActionItem(int offsetInCompiledBlock, int actionType, JBBPIntegerValueEvaluator nullableArgument) Description copied from class:CompiledBlockVisitorVisit an action item (like skip, align or reset counter command)- Overrides:
visitActionItemin classCompiledBlockVisitor- Parameters:
offsetInCompiledBlock- offset in the compiled blockactionType- the action typenullableArgument- argument for action, it can be null- See Also:
-