pax_global_header 0000666 0000000 0000000 00000000064 13774343126 0014524 g ustar 00root root 0000000 0000000 52 comment=5f1f12133993403cd443ab3f012a085f9471141d
java-binary-block-parser-2.0.3/ 0000775 0000000 0000000 00000000000 13774343126 0016313 5 ustar 00root root 0000000 0000000 java-binary-block-parser-2.0.3/.gitignore 0000664 0000000 0000000 00000006262 13774343126 0020311 0 ustar 00root root 0000000 0000000 /**/target/
/target/
/nbproject/
/**/.idea/
*.iml
/jbbp-plugins/jbbp-gradle/.gradle/
/jbbp-plugins/jbbp-gradle/build/
/jbbp/BenchmarkList
/jbbp/CompilerHints
/jbbp/nb-configuration.xml
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/classes/com/igormaznitsa/jbbp/plugin/common/converters/Java16Converter.class
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/classes/com/igormaznitsa/jbbp/plugin/common/converters/JBBPScriptTranslator$Parameters.class
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/classes/com/igormaznitsa/jbbp/plugin/common/converters/JBBPScriptTranslator.class
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/classes/com/igormaznitsa/jbbp/plugin/common/converters/ParserFlags.class
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/classes/com/igormaznitsa/jbbp/plugin/common/converters/Target.class
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/classes/com/igormaznitsa/jbbp/plugin/common/utils/CommonUtils.class
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/classes/com/igormaznitsa/jbbp/plugin/mvn/AbstractJBBPMojo.class
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/classes/com/igormaznitsa/jbbp/plugin/mvn/HelpMojo.class
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/classes/com/igormaznitsa/jbbp/plugin/mvn/JBBPCleanMojo.class
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/classes/com/igormaznitsa/jbbp/plugin/mvn/JBBPGenerateMojo$1.class
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/classes/com/igormaznitsa/jbbp/plugin/mvn/JBBPGenerateMojo.class
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/classes/META-INF/maven/com.igormaznitsa/jbbp-maven-plugin/plugin-help.xml
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/classes/META-INF/maven/plugin.xml
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/generated-sources/plugin/com/igormaznitsa/jbbp/plugin/mvn/HelpMojo.java
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/maven-archiver/pom.properties
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/surefire-reports/TEST-com.igormaznitsa.jbbp.plugin.mvn.JBBPGenerateMojoTest.xml
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/test-classes/com/igormaznitsa/jbbp/plugin/mvn/JBBPGenerateMojoTest.class
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/test-classes/com/igormaznitsa/jbbp/plugin/mvn/mojoConfig.xml
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/jbbp-maven-plugin-2.0.0-SNAPSHOT.jar
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/jbbp-maven-plugin-2.0.0-SNAPSHOT-bundle.jar
/jbbp-plugins/jbbp-maven/jbbp-maven-plugin/target/maven-plugin-help.properties
/jbbp/jmh-out.txt
/jbbp/jmh-result.json
/jbbp-plugins/jbbp-gradle/.settings/
/jbbp-plugins/jbbp-gradle/bin/
/jbbp-plugins/jbbp-gradle/.classpath
/jbbp-plugins/jbbp-gradle/.project
/**/.vscode/
java-binary-block-parser-2.0.3/.projectKnowledge/ 0000775 0000000 0000000 00000000000 13774343126 0021677 5 ustar 00root root 0000000 0000000 java-binary-block-parser-2.0.3/.projectKnowledge/JBBP.mmd 0000664 0000000 0000000 00000006242 13774343126 0023117 0 ustar 00root root 0000000 0000000 Mind Map generated by NB MindMap plugin
> __version__=`1.1`,showJumps=`true`
---
# Java Binary
Block Parser
v 2\.0\.1
## License
> fillColor=`#33CC00`,leftSide=`true`
### Apache License 2\.0
> fillColor=`#99FF00`
## Compatibility
> fillColor=`#CCCCFF`,leftSide=`true`
### Java 1\.8\+
> fillColor=`#3399FF`,textColor=`#FFFFCC`
### Android 3\.0\+
> fillColor=`#3399FF`,textColor=`#FFFFCC`
## does\.\.\.
### have small size
and no 3th part dependencies
> fillColor=`#33FF66`
### have strong
embedded DSL with\.\.\.
> fillColor=`#CCCCFF`,topicLinkUID=`15292664291A`
- TOPIC
1528DC7A000A
#### signed and
unsigned data types
> fillColor=`#CCCCFF`
#### custom processing of
non\-standard data types
> fillColor=`#CCCCFF`
#### arrays and
structures
> fillColor=`#CCCCFF`
#### expressions and another field value
as data length
> fillColor=`#CCCCFF`
#### aligning and skipping data
> fillColor=`#CCCCFF`
### have support for \.\.\.
> fillColor=`#FFCCCC`
#### all bit orders
> fillColor=`#FFCCCC`
- FILE
jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOrder.java
#### all byte orders
> fillColor=`#FFCCCC`
- FILE
jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPByteOrder.java
### have annotation to\.\.
> fillColor=`#CCFFCC`
- FILE
jbbp/src/main/java/com/igormaznitsa/jbbp/mapper/Bin.java
#### map parsed data to class fields
> fillColor=`#CCFFCC`
#### serialize field data into stream
> fillColor=`#CCFFCC`
### can make text representation
of parsed data
> fillColor=`#FFFFCC`
- TOPIC
152926734C4A
### conversion of script into
Java classes
> fillColor=`#AAFF82`,topicLinkUID=`15E33F334A5A`
- TOPIC
15E33F384B4A
## Main parts
> fillColor=`#00FFFF`,leftSide=`true`
### Java source generator
> fillColor=`#D1FF9C`,topicLinkUID=`15E33F384B4A`
- FILE
jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/conversion/JBBPToJavaConverter.java
#### Maven plugin
> fillColor=`#D1FF9C`
- FILE
jbbp-plugins/jbbp-maven
#### Gradle plugin
> fillColor=`#D1FF9C`,leftSide=`true`
- FILE
jbbp-plugins/jbbp-gradle
### Streams
> fillColor=`#FF99FF`
#### JBBPBitInputStream
> fillColor=`#FF99FF`
- FILE
jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitInputStream.java
#### JBBPBitOutputStream
> fillColor=`#FF99FF`,leftSide=`true`
- FILE
jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java
### DSL
> fillColor=`#66FF00`,leftSide=`true`,topicLinkUID=`1528DC7A000A`
#### JBBPParser
> fillColor=`#66FF00`
- FILE
jbbp/src/main/java/com/igormaznitsa/jbbp/JBBPParser.java
#### JBBPDslBuilder
> fillColor=`#66FF00`,leftSide=`true`
- FILE
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPDslBuilder.java
### Write binary
data
> fillColor=`#00CCCC`,leftSide=`true`
#### JBBPOut
> fillColor=`#00CCCC`
- FILE
jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPOut.java
### Convert To Text
> fillColor=`#FFFFCC`,leftSide=`true`,topicLinkUID=`152926734C4A`
#### JBBPTextWriter
> fillColor=`#FFFFCC`
- FILE
jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPTextWriter.java
java-binary-block-parser-2.0.3/.projectKnowledge/JBBP_Types.mmd 0000664 0000000 0000000 00000012307 13774343126 0024302 0 ustar 00root root 0000000 0000000 Mind Map generated by NB MindMap plugin
> __version__=`1.1`,showJumps=`true`
---
# Fields
## Primitive
types
### allowed types
> fillColor=`#FF9999`
#### bit\[:1\.\.7\]
> fillColor=`#9999FF`
##### 1 bit by default
> fillColor=`#FF66FF`
#### bool
> fillColor=`#9999FF`
##### 8 bit field
> fillColor=`#99FFFF`
###### FALSE \(==0\)
> fillColor=`#CCFFCC`
####### 0 in write operations
> fillColor=`#CCFFCC`
###### TRUE \(\!=0\)
> fillColor=`#CCFFCC`
####### 1 in write operations
> fillColor=`#CCFFCC`
#### byte
> fillColor=`#9999FF`
##### 8 bit signed field
> fillColor=`#99FFFF`
#### ubyte
> fillColor=`#9999FF`
##### 8 bit unsigned field
> fillColor=`#99FFFF`
#### short
> fillColor=`#9999FF`
##### 16 bit signed field
> fillColor=`#99FFFF`
#### ushort
> fillColor=`#9999FF`
##### 16 bit unsigned field
> fillColor=`#99FFFF`
#### int
> fillColor=`#9999FF`
##### 32 bit signed field
> fillColor=`#99FFFF`
#### long
> fillColor=`#9999FF`
##### 64 bit signed field
> fillColor=`#99FFFF`
#### floatj
> fillColor=`#FFFE9F`
##### 32 bit signed field
\(Java float format\)
> fillColor=`#99FFFF`
#### doublej
> fillColor=`#FFFE9F`
##### 64 bit signed field
\(Java double format\)
> fillColor=`#99FFFF`
#### stringj
> fillColor=`#FFFE9F`
##### UTF\-8 string with length info, NULL value is allowed
> fillColor=`#99FFFF`
#### var
> fillColor=`#00FAFF`
##### custom field to be processed by specific code
> fillColor=`#00FAFF`
#### val
> fillColor=`#71B9FF`
- TOPIC
164BC0A19BEA
##### Virtual int field which value is calculated by expression
> fillColor=`#71B9FF`
#### CUSTOM TYPES
> fillColor=`#FFF56B`
##### list of types must be provided by external processor
and the processor must provide read operations
> fillColor=`#FFF56B`
### format
> fillColor=`#FF9999`
#### \ \[\\];
> fillColor=`#FFCC00`
##### int;
> fillColor=`#99FF99`
##### int data;
> fillColor=`#99FF99`
##### bit:3 bits;
> fillColor=`#99FF99`
##### bit:\(a\+1\) b;
> fillColor=`#99FF99`
## Complex types
### Arrays
> fillColor=`#9999FF`
#### \ '\['\|\|\_'\]' \[\\];
> fillColor=`#FFCC00`,topicLinkUID=`152971A8B02A`
##### \ is hardcoded
number of items
> fillColor=`#6666FF`,textColor=`#CCFFCC`
###### bit:3 \[1244\];
> fillColor=`#99FF99`
##### \ is some expression
provides length of the array
> fillColor=`#6666FF`,textColor=`#CCFFCC`
###### int length; byte \[length\*2\] data;
> fillColor=`#99FF99`
##### '\_' means read whole stream
untill the stream end
> fillColor=`#6666FF`,textColor=`#CCFFCC`
###### it is impossible to have fields after
> fillColor=`#FF3300`,textColor=`#FFFFFF`
###### long header; byte \[\_\] allData;
> fillColor=`#99FF99`
### Structures
> fillColor=`#9999FF`
#### \[\\]\['\['array\_length|expression|\_'\]'\]\{ \\.\.\. \}
> fillColor=`#FFCC00`
- TOPIC
152971A8B02A
##### \{bit;\}
> fillColor=`#99FF99`
##### header \{ubyte sections; ubyte datalen;\}
sections \[header\.sections\]\{byte \[header\.datalen\] data;\}
> fillColor=`#99FF99`
## Special
> leftSide=`true`
### Align stream
> fillColor=`#9999FF`
#### align\[:number\_of\_bytes|:\(expression\_in\_parentheses\)\]
> fillColor=`#FFCC00`
##### align; byte \[123\];
> fillColor=`#99FF99`,leftSide=`true`
##### align:4; byte\[123\];
> fillColor=`#99FF99`,leftSide=`true`
##### align:\($$\+45\); int data;
> fillColor=`#99FF99`,leftSide=`true`
#### by default
align to 1 byte
> fillColor=`#FF66FF`
#### Skips bytes to align the byte
counter to needed value
> fillColor=`#FFFFCC`
- TOPIC
1529753E90BA
### Byte counter
> fillColor=`#FF9999`,topicLinkUID=`1529753E90BA`
#### $$ in expressions
> fillColor=`#FF9999`
#### can be reset by special command
> fillColor=`#FFCB2F`,leftSide=`true`
##### reset$$;
> fillColor=`#FFCB2F`
### Skip bytes
> fillColor=`#9999FF`
#### Skips needed number of bytes
> fillColor=`#FFFFCC`
- TOPIC
1529753E90BA
#### by default
skip 1 byte
> fillColor=`#FF66FF`
#### skip\[:number\_of\_bytes|\(expression\_in\_parentheses\)\]
> fillColor=`#FFCC00`
##### skip; int;
> fillColor=`#99FF99`
##### skip:34; byte;
> fillColor=`#99FF99`,leftSide=`true`
##### skip:\($$\*2\); int data;
> fillColor=`#99FF99`,leftSide=`true`
### Virtual field
> fillColor=`#71B9FF`,leftSide=`true`,topicLinkUID=`164BC0A19BEA`
#### val:\(\\) \
> fillColor=`#FFC522`
##### val:45 a;
> fillColor=`#63FF8F`
##### val:\(a\+b\) c;
> fillColor=`#63FF8F`,leftSide=`true`
#### must be named
> fillColor=`#FFFF00`
#### allows to set a value
calculated by expression
> fillColor=`#FFFF00`,leftSide=`true`
#### doesn't take part in read\-write
> fillColor=`#FFFF00`,leftSide=`true`
## Byte order
> leftSide=`true`
### \[\<|\>\]\\.\.\.
> fillColor=`#FFCC33`
#### \>
> fillColor=`#FF99FF`
##### Big\-Endinan
###### \>int \[26\] data;
> fillColor=`#99FF99`
##### It is the default value and
can be omitted
> fillColor=`#FF6666`
#### \<
> fillColor=`#FF99FF`
##### Little\-Endian
> leftSide=`true`
###### \ fillColor=`#99FF99`
java-binary-block-parser-2.0.3/LICENSE 0000664 0000000 0000000 00000026135 13774343126 0017327 0 ustar 00root root 0000000 0000000 Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
java-binary-block-parser-2.0.3/README.md 0000664 0000000 0000000 00000044022 13774343126 0017574 0 ustar 00root root 0000000 0000000 
[](http://www.apache.org/licenses/LICENSE-2.0)
[](http://search.maven.org/#artifactdetails|com.igormaznitsa|jbbp|2.0.3|jar)
[](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
[](http://developer.android.com/sdk/index.html)
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=AHWJHJFBAWGL2)
[](https://yoomoney.ru/to/41001158080699)
# Introduction
Java has some embedded features to parse binary data (for instance ByteBuffer), but sometime it is needed to work on bit
level and describe binary structures through some DSL(domain specific language). I was impressed by
the [the Python Struct package](https://docs.python.org/2/library/struct.html) package and wanted to get something like
that for Java. So I developed the JBBP library.

# Change log
- __2.0.3 (03-jan-2021)__
- added service methods `JBBPUtils.traceData` to print dump of an input stream into a PrintStream
- improved `JBBPTokenizerException` to show marked error
position [#30](https://github.com/raydac/java-binary-block-parser/issues/30)
- __2.0.2 (22-aug-2020)__
- added `JBBPOut#Bin` variant to override `@Bin` annotation fields in written objects.
- [#28](https://github.com/raydac/java-binary-block-parser/issues/28) added `JBBPOut#BinForceByteOrder` to override
byte order defined in `@Bin` annotations of written object.
[Full changelog](https://github.com/raydac/java-binary-block-parser/blob/master/changelog.txt)
# Maven dependency
The Framework has been published in the Maven Central and can be easily added as a dependency
```
com.igormaznitsa
jbbp
2.0.3
```
the precompiled library jar, javadoc and sources also can be downloaded directly
from [the Maven central.](https://search.maven.org/artifact/com.igormaznitsa/jbbp/2.0.3/jar)
# Hello world
The library is very easy in use because in many cases only two its classes are needed -
com.igormaznitsa.jbbp.JBBPParser (for data parsing) and com.igormaznitsa.jbbp.io.JBBPOut (for binary block writing).
Both these classes work over low-level IO classes - com.igormaznitsa.jbbp.io.JBBPBitInputStream and
com.igormaznitsa.jbbp.io.JBBPBitOutputStream, those bit stream classes are the core of the library.
The easiet use case shows parsing of whole byte array to bits.
```Java
byte[]parsedBits=JBBPParser.prepare("bit:1 [_];").parse(new byte[]{1,2,3,4,5}).
findFieldForType(JBBPFieldArrayBit.class).getArray();
```
On start it was the only functionality but then I found that it is no so comfort way to get result, so that added some
mapping of parsed result to pre-instantiated object. It works slower, because uses a lot of Java reflection but much
easy in some cases.
```Java
class Parsed {
@Bin(type = BinType.BIT_ARRAY)
byte[] parsed;
}
Parsed parsedBits = JBBPParser.prepare("bit:1 [_] parsed;").parse(new byte[] {1, 2, 3, 4, 5}).mapTo(new Parsed());
```
# Relative speed of different approaches in parsing
Mainly I developed the library to help in my development of ZX-Spectrum emulator where I needed to work with data
snapshots containing data on bit level. It didn't need much productivity in work. But since 1.3.0 version I added way to
generate Java classes from JBBP scripts, such classes work in about five times faster than dynamic parsing and mapping
approaches.

Chart below compares speed of three provided ways to parse data with JBBP:
* __Dynamic__ - the basic parsing through interpretation of prepared JBBP DSL script. It is no so fast, but provide way
to generate parsers on fly from text description.
* __Dynamic + map to class__ - parsing through interpretation of parsed JBBP script and mapping of parsed data to
pre-instantiated class instance. It provides compfortable way to work with data and get result but uses a lot of Java
reflection features and so fast.
* __Static class__ - the fastest way of JBBP use, some JBBP script is translated into Java class. There is no any
interpretation or reflection operators so that it is very
fast. [You can take a look at auxiliary class which I use in tests](https://github.com/raydac/java-binary-block-parser/blob/master/jbbp/src/test/java/com/igormaznitsa/jbbp/testaux/AbstractJBBPToJavaConverterTest.java)
.
# Generate sources from JBBP scripts
Since 1.3.0 version, the library provides Java source generator for JBBP scripts, __(keep in mind that generated sources
anyway depends on JBBP library and it is needed for their work)__. For instance such snippet can be used to generate
Java classes from a JBBP script. It also can generate multiple classes.
```Java
JBBPParser parser=JBBPParser.prepare("byte a; byte b; byte c;");
List generated=parser.convertToSrc(TargetSources.JAVA,"com.test.jbbp.gen.SomeClazz");
for(ResultSrcItem i:generated){
for(Map.Entry j:i.getResult().entrySet()){
System.out.println("Class file name "+j.getKey());
System.out.println("Class file content "+j.getValue());
}
}
```
also there are developed plug-ins for both Maven and Gradle to generate sources from JBBP scripts during source generate
phase.
in Maven it can be used through snippet:
```xml
com.igormaznitsa
jbbp-maven-plugin
2.0.3
gen-jbbp-src
generate
```
By default the maven plug-in looks for files with `jbbp` extension in `src/jbbp` folder of the project (it can be
changed through plug-in configuration) and produces resulting java classes into `target/generated-sources/jbbp`
folder. [For instance, I use such approach in my ZX-Poly emulator](https://github.com/raydac/zxpoly/tree/master/zxpoly-emul/src/jbbp)
.
# More complex example with features added as of 1.1.0
Example below shows how to parse a byte stream written in non-standard MSB0 order (Java has LSB0 bit order) into bit
fields, then print its values and pack fields back:
```Java
class Flags {
@Bin(order = 1, name = "f1", type = BinType.BIT, bitNumber = JBBPBitNumber.BITS_1, comment = "It's flag one")
byte flag1;
@Bin(order = 2, name = "f2", type = BinType.BIT, bitNumber = JBBPBitNumber.BITS_2, comment = "It's second flag")
byte flag2;
@Bin(order = 3, name = "f3", type = BinType.BIT, bitNumber = JBBPBitNumber.BITS_1, comment = "It's 3th flag")
byte flag3;
@Bin(order = 4, name = "f4", type = BinType.BIT, bitNumber = JBBPBitNumber.BITS_4, comment = "It's 4th flag")
byte flag4;
}
final int data = 0b10101010;
Flags parsed = JBBPParser.prepare("bit:1 f1; bit:2 f2; bit:1 f3; bit:4 f4;", JBBPBitOrder.MSB0).parse(new byte[]{(byte)data}).mapTo(new Flags());
assertEquals(1,parsed.flag1);
assertEquals(2,parsed.flag2);
assertEquals(0,parsed.flag3);
assertEquals(5,parsed.flag4);
System.out.println(new JBBPTextWriter().Bin(parsed).Close().toString());
assertEquals(data, JBBPOut.BeginBin(JBBPBitOrder.MSB0).Bin(parsed).End().toByteArray()[0] & 0xFF);
```
The Example will print in console the text below
```
;--------------------------------------------------------------------------------
; START : Flags
;--------------------------------------------------------------------------------
01; f1, It's flag one
02; f2, It's second flag
00; f3, It's 3th flag
05; f4, It's 4th flag
;--------------------------------------------------------------------------------
; END : Flags
;--------------------------------------------------------------------------------
```
# Fields
Each field can have case insensitive name which must not contain '.' (because dot is reserved for links to structure
field values) and '#'(because it is also reserved for internal library use). A field name must not be started with
either number or chars '$' and '_'. *Keep in mind that field names are case insensitive!*
```
int someNamedField;
byte field1;
byte field2;
byte field3;
```

## Primitive types
JBBP supports full set of Java numeric primitives with some extra types like ubyte and bit.

## Complex types
JBBP provides support both arrays and structures. __In expressions you can use links only to field values which already
read!__

## Custom types
It is possible to define processors for custom data types. For instance you can take a look
at [case processing three byte unsigned integer types](https://github.com/raydac/java-binary-block-parser/blob/master/jbbp/src/test/java/com/igormaznitsa/jbbp/it/CustomThreeByteIntegerTypeTest.java)
.
### Support of float, double and String types
Since 1.4.0 in JBBP was added support of Java float, double and String values. Because they have specific format, they
are named as `doublej`, `floatj` and `stringj`.
## Variable fields
If you have some data which internal structure is undefined and variable then you can use the `var` type to mark such
field and provide custom processor to read data of such value. Processor should implement
interface [JBBPVarFieldProcessor](https://github.com/raydac/java-binary-block-parser/blob/master/src/main/java/com/igormaznitsa/jbbp/JBBPVarFieldProcessor.java)
instance.
```
final JBBPParser parser = JBBPParser.prepare("short k; var; int;");
final JBBPIntCounter counter = new JBBPIntCounter();
final JBBPFieldStruct struct = parser.parse(new byte[]{9, 8, 33, 1, 2, 3, 4}, new JBBPVarFieldProcessor() {
public JBBPAbstractArrayField extends JBBPAbstractField> readVarArray(JBBPBitInputStream inStream, int arraySize, JBBPNamedFieldInfo fieldName, int extraValue, JBBPByteOrder byteOrder, JBBPNamedNumericFieldMap numericFieldMap) throws IOException {
fail("Must not be called");
return null;
}
public JBBPAbstractField readVarField(JBBPBitInputStream inStream, JBBPNamedFieldInfo fieldName, int extraValue, JBBPByteOrder byteOrder, JBBPNamedNumericFieldMap numericFieldMap) throws IOException {
final int value = inStream.readByte();
return new JBBPFieldByte(fieldName, (byte) value);
}
}, null);
```
*NB! Some programmers trying to use only parser for complex data, it is a 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.*
## Special types
Special types makes some actions to skip data in input stream

## Byte order
Multi-byte types can be read with different byte order.

# Expressions
Expressions are used for calculation of length of arrays and allow brackets and integer operators which work similar to
Java operators:
- Arithmetic operators: +,-,%,*,/,%
- Bit operators: &,|,^,~
- Shift operators: <<,>>,>>>
- Brackets: (, )
Inside expression you can use integer numbers and named field values through their names (if you use fields from the
same structure) or paths. Keep in your mind that you can't use array fields or fields placed inside structure arrays.
```
int field1;
struct1 {
int field2;
}
byte [field1+struct1.field2] data;
```
# Commentaries
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.
```
int;
// hello commentaries
byte field;
```
# Expression macroses
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.
# How to get result of parsing
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 automatically places values to fields of a Java class.
# Example
Example below shows how to parse a PNG file through JBBP parser:
```Java
final InputStream pngStream = getResourceAsInputStream("picture.png");
try {
final JBBPParser pngParser = JBBPParser.prepare(
"long header;"
+ "// chunks\n"
+ "chunk [_]{"
+ " int length; "
+ " int type; "
+ " byte[length] data; "
+ " int crc;"
+ "}"
);
JBBPFieldStruct result = pngParser.parse(pngStream);
assertEquals(0x89504E470D0A1A0AL,result.findFieldForNameAndType("header",JBBPFieldLong.class).getAsLong());
JBBPFieldArrayStruct chunks = result.findFieldForNameAndType("chunk", JBBPFieldArrayStruct.class);
String [] chunkNames = new String[]{"IHDR","gAMA","bKGD","pHYs","tIME","tEXt","IDAT","IEND"};
int [] chunkSizes = new int[]{0x0D, 0x04, 0x06, 0x09, 0x07, 0x19, 0x0E5F, 0x00};
assertEquals(chunkNames.length,chunks.size());
for(int i=0;i klazz){
return klazz == Chunk.class ? new Chunk() : null;
}
}
final Png png = pngParser.parse(pngStream).mapTo(new Png());
```
Example shows how to parse TCP frame:
```Java
final JBBPParser tcpParser = JBBPParser.prepare(
"skip:34; // skip bytes till the frame\n"
+ "ushort SourcePort;"
+ "ushort DestinationPort;"
+ "int SequenceNumber;"
+ "int AcknowledgementNumber;"
+ "bit:1 NONCE;"
+ "bit:3 RESERVED;"
+ "bit:4 HLEN;"
+ "bit:1 FIN;"
+ "bit:1 SYN;"
+ "bit:1 RST;"
+ "bit:1 PSH;"
+ "bit:1 ACK;"
+ "bit:1 URG;"
+ "bit:1 ECNECHO;"
+ "bit:1 CWR;"
+ "ushort WindowSize;"
+ "ushort TCPCheckSum;"
+ "ushort UrgentPointer;"
+ "byte [$$-34-HLEN*4] Option;"
+ "byte [_] Data;"
);
final JBBPFieldStruct result = pngParser.parse(tcpFrameStream);
```
# F.A.Q.
## Is it possible to use `@Bin` annotations for parsing and not only mapping?
`@Bin` annotations is used only for mapping and data writing, but there is special
class [JBBPDslBuilder](/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPDslBuilder.java) which can convert `@Bin`
marked class into JBBP script, for instance:
```java
JBBPDslBuilder.Begin().AnnotatedClass(SomeBinAnnotatetClass.class).End(true);
```
## My Binary data format is too complex one to be decoded by a JBBP script
No problems! JBBP parser works
over [com.igormaznitsa.jbbp.io.JBBPBitInputStream](/jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitInputStream.java)
class which can be used directly and allows read bits, bytes, count bytes and align data. For writing there is similar
class [JBBPBitOutputStream](https://github.com/raydac/java-binary-block-parser/blob/master/jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java)
.
## I want to make a binary data block instead of parsing!
Library provides special helper [JBBPOut](/jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPOut.java). The helper allows
to generate binary blocks and provides some kind of DSL
```Java
import static com.igormaznitsa.jbbp.io.JBBPOut.*;
...
final byte [] array =
BeginBin().
Bit(1, 2, 3, 0).
Bit(true, false, true).
Align().
Byte(5).
Short(1, 2, 3, 4, 5).
Bool(true, false, true, true).
Int(0xABCDEF23, 0xCAFEBABE).
Long(0x123456789ABCDEF1L, 0x212356239091AB32L).
End().toByteArray();
```
java-binary-block-parser-2.0.3/changelog.txt 0000664 0000000 0000000 00000011615 13774343126 0021007 0 ustar 00root root 0000000 0000000 2.0.3 (03-jan-2021)
- added service methods `JBBPUtils.traceData` to print dump of an input stream into a PrintStream
- improved `JBBPTokenizerException` to show marked error position [#30](https://github.com/raydac/java-binary-block-parser/issues/30)
2.0.2 (22-aug-2020)
- added `JBBPOut#Bin` variant to override `@Bin` annotation fields in written objects.
- [#28](https://github.com/raydac/java-binary-block-parser/issues/28) added `JBBPOut#BinForceByteOrder` to override byte order defined in `@Bin` annotations of written object.
2.0.1
- [#26](https://github.com/raydac/java-binary-block-parser/issues/26) fixed bug in array write with MSB0
2.0.0
- __removed DslBinCustom annotation, use @Bin annotation instead__
- __renamed attributes of @Bin annotation to their correct form__
- __reworked object mapping system, removed hacks to instantiate classes, now only mapping to objects allowed, support of private fields mapping is removed__
- __minimal JDK version now 1.8+__
- __minimal Android API now 3.0+__
- added support of getters and setters into mapping
- added `Object newInstance(Class)` method support of mapped classes to generate local class member instances
- added generating of `makeFIELD()` method for structure types in Java class converter
- refactoring
1.4.1
- fixed incompatibility in tokenizer regex syntax for Android SDK [#23](https://github.com/raydac/java-binary-block-parser/issues/23)
- added DslBinCustom annotation to provide way to mark custom type fields for JBBPDslBuilder
- fixed NPE in JBBPDslBuilder for not-provided outBitNumber attribute in annotated field marked as type BIT or BIT_ARRAY [#20](https://github.com/raydac/java-binary-block-parser/issues/20)
- naming of fields has been made more tolerant, now it is allowed to have field names with names similar to data types
- improved check of field names in JBBPDslBuilder [#21](https://github.com/raydac/java-binary-block-parser/issues/21)
1.4.0
- added type `val` which allows to create virtual field with calculated value, can play role of variable in scripts
- `val` and `var` have been added into reserved words and can't be used as field names
- added field `outByteOrder` attribute to `Bin` annotation, it affects logic of `JBBPOut#Bin` for output of annotated objects which fields should be saved with different byte order
- removed deprecated method `JBBPFinderException#getNameOrPath`
- added [auxiliary class to build JBBP script](https://github.com/raydac/java-binary-block-parser/blob/master/jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPDslBuilder.java)
- added flag `JBBPParser#FLAG_NEGATIVE_EXPRESSION_RESULT_AS_ZERO` to recognize negative expression result as zero
- improved Java 6 class source generator to process FLAG_SKIP_REMAINING_FIELDS_IF_EOF for structure fields
- added stable automatic module name `igormaznitsa.jbbp` into manifest file
- added support of float, double and string java types, as `floatj`,`doublej` and `stringj`
1.3.0
- fixed NPE when referencing a JBBPCustomFieldTypeProcessor parsed field
- added Maven plugin to generate sources from JBBP scripts
- added Gradle plugin to generate sources from JBBP scripts
- added extra byte array reading writing methods with byte order support into JBBPBitInputStream and JBBPBitOutputStream
- added converter of compiled parser data into Java class sources (1.6+)
- added method to read unsigned short values as char [] into JBBPBitInputStream
- Class version target has been changed to Java 1.6
- fixed compatibiity of tests with Java 1.6
- Minor refactoring
1.2.0
- Refactoring
- Improved tree of JBBP exceptions
- Fixed NPE in JBBPTextWriter for String field mapped to byte array
- Added support of custom field types through JBBPCustomFieldTypeProcessor
- Added JBBPCustomFieldTypeProcessorAggregator, auxiliary class to join several JBBPCustomFieldTypeProcessors
- Fixed JBBPTextWriter, added support of logging for JBBPAbstractField objects
- Added support of payload objects in JBBPAbstractField
- Improved inside script compiler and interpreter to support future extensions.
- Fixed expression evaluator to support single char field names in expressions.
- Added support of expressions in extra field numeric data part (example bit:(field*2))
1.1.0
- Added support to write mapped classes into JBBPOut
- Added JBBPTextWriter to log binary data as text with commentaries,tabs and separators
- Fixed read byte counter, now it counts only fully processed bytes, if only several bits have been read from byte then the byte will not be counted until whole read
- Fixed static fields including in mapping processes if class has marked by default Bin annotation
- Added flag JBBPParser#FLAG_SKIP_REMAINING_FIELDS_IF_EOF to ignore remaining fields during parsing if EOF without exception
- Added flag JBBPMapper#FLAG_IGNORE_MISSING_VALUES to ignore mapping for values which are not found in parsed source
- Added new auxiliary methods in JBBPUtils
1.0
- The Initial version
java-binary-block-parser-2.0.3/docs/ 0000775 0000000 0000000 00000000000 13774343126 0017243 5 ustar 00root root 0000000 0000000 java-binary-block-parser-2.0.3/docs/jbbp_byteorder.png 0000664 0000000 0000000 00000044737 13774343126 0022764 0 ustar 00root root 0000000 0000000 PNG
IHDR cǞ IIDATxxT!ADDD9HC!! H@Q vTV
Z-X[ G)x@}|x(Z}C"X~Zӕ֜YYkfd&}0 ^x/TE >P >4XW ! >> @@@ x:͜9sԩS?y]yޓyyy54+ Q)++dEEڱc:qݻUyyW^kdzVc MNyyɓ'P:J/hÇڭ\wrf7բeKJ;8b @cx