Skip to content

Commit 5c4193e

Browse files
authored
Update README.md
1 parent 3e0ca4f commit 5c4193e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,26 @@ The Framework supports full set of Java numeric primitives with extra types like
119119
##Complex types
120120
The Framework provides support for arrays and structures. Just keep in mind that in expressions you can make links to field values only defined before expression.
121121
![JBBP field format, types and examples](https://github.com/raydac/java-binary-block-parser/blob/master/docs/jbbp_complex_types.png)
122+
123+
##Variable fields
124+
If you have some data which structure is variable then you can use the `var` type for defined field and process reading of the data manually with custom [JBBPVarFieldProcessor](https://github.com/raydac/java-binary-block-parser/blob/master/src/main/java/com/igormaznitsa/jbbp/JBBPVarFieldProcessor.java) instance.
125+
```
126+
final JBBPParser parser = JBBPParser.prepare("short k; var; int;");
127+
final JBBPIntCounter counter = new JBBPIntCounter();
128+
final JBBPFieldStruct struct = parser.parse(new byte[]{9, 8, 33, 1, 2, 3, 4}, new JBBPVarFieldProcessor() {
129+
130+
public JBBPAbstractArrayField<? extends JBBPAbstractField> readVarArray(final JBBPBitInputStream inStream, final int arraySize, final JBBPNamedFieldInfo fieldName, final int extraValue, final JBBPByteOrder byteOrder, final JBBPNamedNumericFieldMap numericFieldMap) throws IOException {
131+
fail("Must not be called");
132+
return null;
133+
}
134+
135+
public JBBPAbstractField readVarField(final JBBPBitInputStream inStream, final JBBPNamedFieldInfo fieldName, final int extraValue, final JBBPByteOrder byteOrder, final JBBPNamedNumericFieldMap numericFieldMap) throws IOException {
136+
final int value = inStream.readByte();
137+
return new JBBPFieldByte(fieldName, (byte) value);
138+
}
139+
}, null);
140+
```
141+
122142
##Special types
123143
Special types makes some actions to skip data in input stream
124144
![JBBP field format, types and examples](https://github.com/raydac/java-binary-block-parser/blob/master/docs/jbbp_special_fields.png)

0 commit comments

Comments
 (0)