Skip to content

Commit 4690455

Browse files
authored
Update README.md
1 parent 6fa530a commit 4690455

File tree

1 file changed

+21
-31
lines changed

1 file changed

+21
-31
lines changed

README.md

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
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.
1615
![Use cases](https://github.com/raydac/java-binary-block-parser/blob/master/docs/jbbp_mm.png)
1716

18-
Change log
19-
===========
17+
# Change log
2018
- **1.2.0**
2119
- Refactoring
2220
- Improved tree of JBBP exceptions
@@ -39,8 +37,7 @@ Change log
3937
- **1.0**
4038
- The Initial version
4139

42-
Maven dependency
43-
======================
40+
# Maven dependency
4441
The Framework is published in the Maven Central and can be easily added as a dependency into a maven project
4542
```
4643
<dependency>
@@ -51,8 +48,7 @@ The Framework is published in the Maven Central and can be easily added as a dep
5148
```
5249
the precompiled library jar, javadoc and sources also can be downloaded directly from [the Maven central.](http://search.maven.org/#browse|808871750)
5350

54-
Hello world
55-
============
51+
# Hello world
5652
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.
5753

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

69-
More compex example with features added as of 1.1.0
70-
====================================================
65+
# More compex example with features added as of 1.1.0
7166
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
7267
```Java
7368
class Flags {
@@ -101,8 +96,7 @@ The Example will print in console the text below
10196
; END : Flags
10297
;--------------------------------------------------------------------------------
10398
```
104-
Fields
105-
==================
99+
# Fields
106100
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).
107101
Field name must not be started by a number or chars '$' and '_'. *Field names are case insensitive!*
108102
```
@@ -113,14 +107,14 @@ byte field3;
113107
```
114108
![JBBP field format, types and examples](https://github.com/raydac/java-binary-block-parser/blob/master/docs/jbbp_fields.png)
115109

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

123-
##Variable fields
117+
## Variable fields
124118
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.
125119
```
126120
final JBBPParser parser = JBBPParser.prepare("short k; var; int;");
@@ -140,15 +134,14 @@ If you have some data which structure is variable then you can use the `var` typ
140134
```
141135
*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.*
142136

143-
##Special types
137+
## Special types
144138
Special types makes some actions to skip data in input stream
145139
![JBBP field format, types and examples](https://github.com/raydac/java-binary-block-parser/blob/master/docs/jbbp_special_fields.png)
146-
##Byte order
140+
## Byte order
147141
Every multi-byte type can be read with different byte order.
148142
![JBBP field format, types and examples](https://github.com/raydac/java-binary-block-parser/blob/master/docs/jbbp_byteorder.png)
149143

150-
Expressions
151-
============
144+
# Expressions
152145
Expressions are used for calculation of length of arrays and allow brackets and integer operators which work similar to Java operators:
153146
- Arithmetic operators: +,-,%,*,/,%
154147
- Bit operators: &,|,^,~
@@ -164,25 +157,21 @@ int field1;
164157
byte [field1+struct1.field2] data;
165158
```
166159

167-
Commentaries
168-
=============
160+
# Commentaries
169161
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.
170162
```
171163
int;
172164
// hello commentaries
173165
byte field;
174166
```
175167

176-
Expression macroses
177-
====================
168+
# Expression macroses
178169
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.
179170

180-
How to get result of parsing
181-
=============================
171+
# How to get result of parsing
182172
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.
183173

184-
Example
185-
========
174+
# Example
186175
The Example below shows how to parse a PNG file with the JBBP parser (the example taken from tests)
187176
```Java
188177
final InputStream pngStream = getResourceAsInputStream("picture.png");
@@ -277,13 +266,14 @@ final JBBPParser tcpParser = JBBPParser.prepare(
277266

278267
final JBBPFieldStruct result = pngParser.parse(tcpFrameStream);
279268
```
269+
# F.A.Q.
270+
## Is it possible to use `@Bin` annotations for parsing and not only mapping?
271+
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.
280272

281-
My Binary data format is too complex one to be decoded by a JBBP script
282-
========================================================================
273+
## My Binary data format is too complex one to be decoded by a JBBP script
283274
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.
284275

285-
I want to make a bin block instead of parsing!
286-
===============================================
276+
## I want to make a bin block instead of parsing!
287277
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
288278
```Java
289279
import static com.igormaznitsa.jbbp.io.JBBPOut.*;

0 commit comments

Comments
 (0)