Skip to content

Commit eea121d

Browse files
committed
Conflicts: README.md
2 parents 42f4d33 + 4690455 commit eea121d

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed

README.md

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
![JBBP Logo](https://github.com/raydac/java-binary-block-parser/blob/master/logo.png)
1010

11-
Introduction
12-
=============
11+
#Introduction
1312
Java has some embedded features to parse binary data (for instance ByteBuffer), but I wanted to work with separated bits and describe binary structure in some strong DSL(domain specific language). I was very impressed by the [the Python Struct package](https://docs.python.org/2/library/struct.html) package so that I decided to make something like that. So JBBP was born.<br>
1413
p.s.<br>
1514
For instance I have been very actively using the framework in [the ZX-Poly emulator](https://github.com/raydac/zxpoly) to parse snapshot files and save results.
@@ -44,8 +43,7 @@ Change log
4443
- **1.0 (08-AUG-2014)**
4544
- The Initial version
4645

47-
Maven dependency
48-
======================
46+
# Maven dependency
4947
The Framework is published in the Maven Central and can be easily added as a dependency into a maven project
5048
```
5149
<dependency>
@@ -56,8 +54,7 @@ The Framework is published in the Maven Central and can be easily added as a dep
5654
```
5755
the precompiled library jar, javadoc and sources also can be downloaded directly from [the Maven central.](http://search.maven.org/#browse|808871750)
5856

59-
Hello world
60-
============
57+
# Hello world
6158
The Framework is very easy in use because it has only two main classes for its functionality com.igormaznitsa.jbbp.JBBPParser (for data parsing) and com.igormaznitsa.jbbp.io.JBBPOut (for binary block writing), both of them work over low-level IO classes com.igormaznitsa.jbbp.io.JBBPBitInputStream and com.igormaznitsa.jbbp.io.JBBPBitOutputStream which are the core for the framework.
6259

6360
The Easiest case below shows how to parse byte array to bits.
@@ -71,8 +68,7 @@ class Parsed {@Bin(type = BinType.BIT_ARRAY)byte[] parsed;}
7168
Parsed parsedBits = JBBPParser.prepare("bit:1 [_] parsed;").parse(new byte[]{1,2,3,4,5}).mapTo(Parsed.class);
7269
```
7370

74-
More compex example with features added as of 1.1.0
75-
====================================================
71+
# More compex example with features added as of 1.1.0
7672
The Example shows how to parse a byte written in non-standard MSB0 order (Java has LSB0 bit order) to bit fields, print its values and pack fields back
7773
```Java
7874
class Flags {
@@ -106,8 +102,7 @@ The Example will print in console the text below
106102
; END : Flags
107103
;--------------------------------------------------------------------------------
108104
```
109-
Fields
110-
==================
105+
# Fields
111106
Every field can have case insensitive name which should not contain '.' (because it is reserved for links to structure field values) and '#'(because it is also reserver for inside usage).
112107
Field name must not be started by a number or chars '$' and '_'. *Field names are case insensitive!*
113108
```
@@ -118,14 +113,14 @@ byte field3;
118113
```
119114
![JBBP field format, types and examples](https://github.com/raydac/java-binary-block-parser/blob/master/docs/jbbp_fields.png)
120115

121-
##Primitive types
116+
## Primitive types
122117
The Framework supports full set of Java numeric primitives with extra types like ubyte and bit.
123118
![JBBP field format, types and examples](https://github.com/raydac/java-binary-block-parser/blob/master/docs/jbbp_primitives.png)
124-
##Complex types
119+
## Complex types
125120
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.
126121
![JBBP field format, types and examples](https://github.com/raydac/java-binary-block-parser/blob/master/docs/jbbp_complex_types.png)
127122

128-
##Variable fields
123+
## Variable fields
129124
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.
130125
```
131126
final JBBPParser parser = JBBPParser.prepare("short k; var; int;");
@@ -145,15 +140,14 @@ If you have some data which structure is variable then you can use the `var` typ
145140
```
146141
*NB! Some programmers trying to use only parser for complex data, it is mistake. In the case it is much better to have several easy parsers working with the same [JBBPBitInputStream](https://github.com/raydac/java-binary-block-parser/blob/master/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitInputStream.java) instance, it allows to keep decision points on Java level and make solution easier.*
147142

148-
##Special types
143+
## Special types
149144
Special types makes some actions to skip data in input stream
150145
![JBBP field format, types and examples](https://github.com/raydac/java-binary-block-parser/blob/master/docs/jbbp_special_fields.png)
151-
##Byte order
146+
## Byte order
152147
Every multi-byte type can be read with different byte order.
153148
![JBBP field format, types and examples](https://github.com/raydac/java-binary-block-parser/blob/master/docs/jbbp_byteorder.png)
154149

155-
Expressions
156-
============
150+
# Expressions
157151
Expressions are used for calculation of length of arrays and allow brackets and integer operators which work similar to Java operators:
158152
- Arithmetic operators: +,-,%,*,/,%
159153
- Bit operators: &,|,^,~
@@ -169,25 +163,21 @@ int field1;
169163
byte [field1+struct1.field2] data;
170164
```
171165

172-
Commentaries
173-
=============
166+
# Commentaries
174167
You can use commentaries inside a parser script, the parser supports the only comment format and recognizes as commentaries all text after '//' till the end of line.
175168
```
176169
int;
177170
// hello commentaries
178171
byte field;
179172
```
180173

181-
Expression macroses
182-
====================
174+
# Expression macroses
183175
Inside expression you can use field names and field paths, also you can use the special macros '$$' which represents the current input stream byte counter, all fields started with '$' will be recognized by the parser as special user defined variables and it will be requesting them from special user defined provider. If the array size contains the only '_' symbol then the field or structure will not have defined size and whole stream will be read.
184176

185-
How to get result of parsing
186-
=============================
177+
# How to get result of parsing
187178
The Result of parsing is an instance of com.igormaznitsa.jbbp.model.JBBPFieldStruct class which represents the root invisible structure for the parsed data and you can use its inside methods to find desired fields for their names, paths or classes. All Fields are successors of com.igormaznitsa.jbbp.model.JBBPAbstractField class. To increase comfort, it is easier to use mapping to classes when the mapper automaticaly places values to fields of a Java class.
188179

189-
Example
190-
========
180+
# Example
191181
The Example below shows how to parse a PNG file with the JBBP parser (the example taken from tests)
192182
```Java
193183
final InputStream pngStream = getResourceAsInputStream("picture.png");
@@ -282,13 +272,14 @@ final JBBPParser tcpParser = JBBPParser.prepare(
282272

283273
final JBBPFieldStruct result = pngParser.parse(tcpFrameStream);
284274
```
275+
# F.A.Q.
276+
## Is it possible to use `@Bin` annotations for parsing and not only mapping?
277+
No, `@Bin` annotations in classes are used only for mapping and data writing, but there is [the code snippet](https://gist.github.com/raydac/28d770307bd33683aa17ea3c39d5e2c4) allows to generate JBBP DSL based on detected @Bin annotations in class.
285278

286-
My Binary data format is too complex one to be decoded by a JBBP script
287-
========================================================================
279+
## My Binary data format is too complex one to be decoded by a JBBP script
288280
No problems! The Parser works over com.igormaznitsa.jbbp.io.BitInputStream class which can be used directly and allows read bits, bytes, count bytes and align data from a stream.
289281

290-
I want to make a bin block instead of parsing!
291-
===============================================
282+
## I want to make a bin block instead of parsing!
292283
The Framework contains a special helper as the class com.igormaznitsa.jbbp.io.JBBPOut which allows to build bin blocks with some kind of DSL
293284
```Java
294285
import static com.igormaznitsa.jbbp.io.JBBPOut.*;

0 commit comments

Comments
 (0)