Skip to content

Commit c8ed0d6

Browse files
committed
release 2.0.0
1 parent 4e01b02 commit c8ed0d6

File tree

19 files changed

+76
-45
lines changed

19 files changed

+76
-45
lines changed

.projectKnowledge/JBBP.mmd

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ Mind Map generated by NB MindMap plugin
1616
> fillColor=`#CCCCFF`,leftSide=`true`
1717

1818

19-
### Java 6\+
19+
### Java 1\.8\+
2020
> fillColor=`#3399FF`,textColor=`#FFFFCC`
2121

2222

23-
### Android 2\.0\+
23+
### Android 3\.0\+
2424
> fillColor=`#3399FF`,textColor=`#FFFFCC`
2525

2626

@@ -106,7 +106,7 @@ Mind Map generated by NB MindMap plugin
106106
> fillColor=`#D1FF9C`,topicLinkUID=`15E33F384B4A`
107107

108108
- FILE
109-
<pre>jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/conversion/JBBPToJava6Converter.java</pre>
109+
<pre>jbbp/src/main/java/com/igormaznitsa/jbbp/compiler/conversion/JBBPToJavaConverter.java</pre>
110110

111111
#### Maven plugin
112112
> fillColor=`#D1FF9C`

README.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ For instance I have been very actively using the framework in [the ZX-Poly emula
1515
![Use cases](https://github.com/raydac/java-binary-block-parser/blob/master/docs/jbbp_mm.png)
1616

1717
# Change log
18-
- **2.0.0-SNAPSHOT**
18+
- **2.0.0 (20-nov-2019)**
1919
- __removed DslBinCustom annotation, use @Bin annotation instead__
2020
- __renamed attributes of @Bin annotation to their correct form__
2121
- __reworked object mapping system, removed hacks to instantiate classes, now only mapping to objects allowed, support of private fields mapping is removed__
2222
- __minimal JDK version now 1.8+__
2323
- __minimal Android API now 3.0+__
2424
- added support of getters and setters into mapping
25-
- added `Object newInstance(Class)` method support of mapped classes to generate instances for local classes
25+
- added `Object newInstance(Class)` method support of mapped classes to generate local class member instances
2626
- added generating of `makeFIELD()` method for structure types in Java class converter
2727
- refactoring
2828

@@ -67,7 +67,7 @@ The Framework has been published in the Maven Central and can be easily added as
6767
<dependency>
6868
<groupId>com.igormaznitsa</groupId>
6969
<artifactId>jbbp</artifactId>
70-
<version>1.4.1</version>
70+
<version>2.0.0</version>
7171
</dependency>
7272
```
7373
the precompiled library jar, javadoc and sources also can be downloaded directly from [the Maven central.](http://search.maven.org/#browse|808871750)
@@ -83,7 +83,7 @@ The Easiest case below shows how to parse byte array to bits.
8383
Of course sometime it is not a comfortable way to look for parsed fields in the result, so you can use mapping of parsed data to class fields.
8484
```Java
8585
class Parsed {@Bin(type = BinType.BIT_ARRAY)byte[] parsed;}
86-
Parsed parsedBits = JBBPParser.prepare("bit:1 [_] parsed;").parse(new byte[]{1,2,3,4,5}).mapTo(Parsed.class);
86+
Parsed parsedBits = JBBPParser.prepare("bit:1 [_] parsed;").parse(new byte[]{1,2,3,4,5}).mapTo(new Parsed());
8787
```
8888

8989
# Relative speed of different approaches in parsing
@@ -100,7 +100,7 @@ Since 1.3.0 version, the framework can convert JBBP scripts into sources __(the
100100
For instance you can use such simple snippet to generate Java classes from JBBP script, potentially it can generate many classes but usually only one class
101101
```Java
102102
JBBPParser parser = JBBPParser.prepare("byte a; byte b; byte c;");
103-
List<ResultSrcItem> generated = parser.convertToSrc(TargetSources.JAVA_1_6,"com.test.jbbp.gen.SomeClazz");
103+
List<ResultSrcItem> generated = parser.convertToSrc(TargetSources.JAVA,"com.test.jbbp.gen.SomeClazz");
104104
for(ResultSrcItem i : generated) {
105105
for(Map.Entry<String,String> j :i.getResult().entrySet()) {
106106
System.out.println("Class file name "+j.getKey());
@@ -114,7 +114,7 @@ in Maven you should just add such plugin execution
114114
<plugin>
115115
<groupId>com.igormaznitsa</groupId>
116116
<artifactId>jbbp-maven-plugin</artifactId>
117-
<version>1.4.1</version>
117+
<version>2.0.0</version>
118118
<executions>
119119
<execution>
120120
<id>gen-jbbp-src</id>
@@ -138,7 +138,7 @@ class Flags {
138138
}
139139

140140
final int data = 0b10101010;
141-
Flags parsed = JBBPParser.prepare("bit:1 f1; bit:2 f2; bit:1 f3; bit:4 f4;", JBBPBitOrder.MSB0).parse(new byte[]{(byte)data}).mapTo(Flags.class);
141+
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());
142142
assertEquals(1,parsed.flag1);
143143
assertEquals(2,parsed.flag2);
144144
assertEquals(0,parsed.flag3);
@@ -302,9 +302,12 @@ final JBBPParser pngParser = JBBPParser.prepare(
302302
class Png {
303303
long header;
304304
Chunk [] chunk;
305+
public Object newInstance(Class<?> klazz){
306+
return klazz == Chunk.class ? new Chunk() : null;
307+
}
305308
}
306309

307-
final Png png = pngParser.parse(pngStream).mapTo(Png.class);
310+
final Png png = pngParser.parse(pngStream).mapTo(new Png());
308311
```
309312
The Example from tests shows how to parse a tcp frame wrapped in a network frame
310313
```Java

changelog.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
2.0.0-SNAPSHOT
1+
2.0.0
22
- __removed DslBinCustom annotation, use @Bin annotation instead__
33
- __renamed attributes of @Bin annotation to their correct form__
44
- __reworked object mapping system, removed hacks to instantiate classes, now only mapping to objects allowed, support of private fields mapping is removed__
55
- __minimal JDK version now 1.8+__
66
- __minimal Android API now 3.0+__
77
- added support of getters and setters into mapping
8-
- added `Object newInstance(Class)` method support of mapped classes to generate instances for local classes
8+
- added `Object newInstance(Class)` method support of mapped classes to generate local class member instances
99
- added generating of `makeFIELD()` method for structure types in Java class converter
1010
- refactoring
1111

docs/jbbp_mm.png

59.5 KB
Loading

jbbp-plugins/jbbp-gradle/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def getProp(name, dflt) {
77
}
88
}
99

10-
def jbbpVersion = getProp('jbbp_plugin_version', '2.0.0-SNAPSHOT')
10+
def jbbpVersion = getProp('jbbp_plugin_version', '2.0.0')
1111
def metaLibVersion = getProp('meta_lib_version', '1.1.2')
1212

1313
group = 'com.igormaznitsa'

jbbp-plugins/jbbp-gradle/pom.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.igormaznitsa</groupId>
88
<artifactId>jbbp-main-plugin-pom</artifactId>
9-
<version>2.0.0-SNAPSHOT</version>
9+
<version>2.0.0</version>
1010
</parent>
1111

1212
<artifactId>jbbp-gradle-plugin</artifactId>
@@ -22,6 +22,8 @@
2222
</dependencies>
2323

2424
<properties>
25+
<maven.compiler.source>1.8</maven.compiler.source>
26+
<maven.compiler.target>1.8</maven.compiler.target>
2527
<gradleGoal>install</gradleGoal>
2628
</properties>
2729

jbbp-plugins/jbbp-maven/jbbp-maven-plugin-tests/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.igormaznitsa</groupId>
77
<artifactId>jbbp-maven-plugin-pom</artifactId>
8-
<version>2.0.0-SNAPSHOT</version>
8+
<version>2.0.0</version>
99
</parent>
1010

1111
<artifactId>jbbp-maven-plugin-tests</artifactId>

jbbp-plugins/jbbp-maven/jbbp-maven-plugin/pom.xml

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.igormaznitsa</groupId>
77
<artifactId>jbbp-maven-plugin-pom</artifactId>
8-
<version>2.0.0-SNAPSHOT</version>
8+
<version>2.0.0</version>
99
</parent>
1010

1111
<artifactId>jbbp-maven-plugin</artifactId>
@@ -14,6 +14,11 @@
1414
<name>JBBP Maven plugin</name>
1515
<description>Generator of sources from JBBP scripts</description>
1616

17+
<properties>
18+
<maven.compiler.source>1.8</maven.compiler.source>
19+
<maven.compiler.target>1.8</maven.compiler.target>
20+
</properties>
21+
1722
<profiles>
1823
<profile>
1924
<id>publish</id>
@@ -61,6 +66,9 @@
6166
<goals>
6267
<goal>jar</goal>
6368
</goals>
69+
<configuration>
70+
<source>1.8</source>
71+
</configuration>
6472
</execution>
6573
</executions>
6674
</plugin>

jbbp-plugins/jbbp-maven/jbbp-maven-plugin/src/test/resources/com/igormaznitsa/jbbp/plugin/mvn/mojoConfig.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<plugin>
1515
<groupId>com.igormaznitsa</groupId>
1616
<artifactId>jbbp-maven-plugin</artifactId>
17-
<version>2.0.0-SNAPSHOT</version>
17+
<version>2.0.0</version>
1818
<goals>
1919
<goal>generate</goal>
2020
</goals>

jbbp-plugins/jbbp-maven/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.igormaznitsa</groupId>
77
<artifactId>jbbp-main-plugin-pom</artifactId>
8-
<version>2.0.0-SNAPSHOT</version>
8+
<version>2.0.0</version>
99
</parent>
1010

1111
<artifactId>jbbp-maven-plugin-pom</artifactId>

jbbp-plugins/jbbp-plugin-common/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.igormaznitsa</groupId>
88
<artifactId>jbbp-main-plugin-pom</artifactId>
9-
<version>2.0.0-SNAPSHOT</version>
9+
<version>2.0.0</version>
1010
</parent>
1111

1212
<artifactId>jbbp-plugin-common</artifactId>

jbbp-plugins/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.igormaznitsa</groupId>
77
<artifactId>jbbp-main-pom</artifactId>
8-
<version>2.0.0-SNAPSHOT</version>
8+
<version>2.0.0</version>
99
</parent>
1010

1111
<artifactId>jbbp-main-plugin-pom</artifactId>

jbbp/pom.xml

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.igormaznitsa</groupId>
77
<artifactId>jbbp-main-pom</artifactId>
8-
<version>2.0.0-SNAPSHOT</version>
8+
<version>2.0.0</version>
99
</parent>
1010

1111
<artifactId>jbbp</artifactId>
@@ -16,6 +16,11 @@
1616
own DSL to describe parsing data format
1717
</description>
1818

19+
<properties>
20+
<maven.compiler.source>1.8</maven.compiler.source>
21+
<maven.compiler.target>1.8</maven.compiler.target>
22+
</properties>
23+
1924
<dependencies>
2025
<dependency>
2126
<groupId>org.openjdk.jmh</groupId>
@@ -164,6 +169,9 @@
164169
<goals>
165170
<goal>jar</goal>
166171
</goals>
172+
<configuration>
173+
<source>1.8</source>
174+
</configuration>
167175
</execution>
168176
</executions>
169177
</plugin>

jbbp/src/main/java/com/igormaznitsa/jbbp/io/JBBPBitOutputStream.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.igormaznitsa.jbbp.io;
1818

1919
import com.igormaznitsa.jbbp.utils.JBBPUtils;
20-
2120
import java.io.FilterOutputStream;
2221
import java.io.IOException;
2322
import java.io.OutputStream;
@@ -418,6 +417,7 @@ public void writeString(final String value, final JBBPByteOrder order) throws IO
418417
* <b>the byte order in saved char data will be BIG_ENDIAN</b>
419418
*
420419
* @param value array to be written, must not be null but can contain null values
420+
* @param order byte order to write char data, must not be null
421421
* @throws IOException it will be thrown for transport errors
422422
* @see #writeString(String, JBBPByteOrder)
423423
* @since 1.4.0

jbbp/src/main/java/com/igormaznitsa/jbbp/mapper/Bin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* from parsed a JBBP structure. Also it can be used for whole class but in the
3434
* case be careful and use default name and path values. The Class is not thread safe.
3535
*
36-
* <b></>Since 2.0.0 was removed prefix 'out' for fields which contained it</b>.
36+
* <b>Since 2.0.0 was removed prefix 'out' for fields which contained it</b>.
3737
*
3838
* @since 1.0
3939
*/

jbbp/src/main/java/com/igormaznitsa/jbbp/model/JBBPFieldStruct.java

+26-19
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package com.igormaznitsa.jbbp.model;
1818

19+
import static com.igormaznitsa.jbbp.utils.JBBPUtils.ARRAY_FIELD_EMPTY;
20+
21+
1922
import com.igormaznitsa.jbbp.compiler.JBBPNamedFieldInfo;
2023
import com.igormaznitsa.jbbp.exceptions.JBBPFinderException;
2124
import com.igormaznitsa.jbbp.exceptions.JBBPTooManyFieldsFoundException;
@@ -24,11 +27,8 @@
2427
import com.igormaznitsa.jbbp.model.finder.JBBPFieldFinder;
2528
import com.igormaznitsa.jbbp.utils.Function;
2629
import com.igormaznitsa.jbbp.utils.JBBPUtils;
27-
2830
import java.util.List;
2931

30-
import static com.igormaznitsa.jbbp.utils.JBBPUtils.ARRAY_FIELD_EMPTY;
31-
3232
/**
3333
* Describes a structure.
3434
*
@@ -224,9 +224,10 @@ public <T extends JBBPAbstractField> T findFieldForPathAndType(final String fiel
224224
* Find a structure by its path and map the structure fields to a class
225225
* fields.
226226
*
227-
* @param <T> a class type
228-
* @param path the path to the structure to be mapped, must not be null
229-
* @param instance object instance to be filled by values, must not be null
227+
* @param <T> a class type
228+
* @param path the path to the structure to be mapped, must not be null
229+
* @param instance object instance to be filled by values, must not be null
230+
* @param instantiators array of functions which can instantiate object of required class, must not be null
230231
* @return a mapped instance of the class, must not be null
231232
* @since 2.0.0
232233
*/
@@ -239,10 +240,11 @@ public final <T> T mapTo(final String path, final T instance, final Function<Cla
239240
* Find a structure by its path and map the structure fields to a class
240241
* fields.
241242
*
242-
* @param <T> a class type
243-
* @param path the path to the structure to be mapped, must not be null
244-
* @param instance object instance to be filled by values, must not be null
245-
* @param flags special flags to tune mapping process
243+
* @param <T> a class type
244+
* @param path the path to the structure to be mapped, must not be null
245+
* @param instance object instance to be filled by values, must not be null
246+
* @param flags special flags to tune mapping process
247+
* @param instantiators array of functions which can instantiate object of required class, must not be null
246248
* @return a mapped instance of the class, must not be null
247249
* @see JBBPMapper#FLAG_IGNORE_MISSING_VALUES
248250
* @since 2.0.0
@@ -260,6 +262,7 @@ public final <T> T mapTo(final String path, final T instance, final int flags, f
260262
* @param path the path to the structure to be mapped, must not be null
261263
* @param instance object instance to be filled by values, must not be null
262264
* @param customFieldProcessor a custom field processor to provide values for custom mapping fields, it can be null if there is not any custom field
265+
* @param instantiators array of functions which can instantiate object of required class, must not be null
263266
* @return a mapped instance of the class, must not be null
264267
* @since 2.0.0
265268
*/
@@ -277,6 +280,7 @@ public final <T> T mapTo(final String path, final T instance, final JBBPMapperCu
277280
* @param instance object instance to be filled by values, must not be null
278281
* @param customFieldProcessor a custom field processor to provide values for custom mapping fields, it can be null if there is not any custom field
279282
* @param flags special flags to tune mapping process
283+
* @param instantiators array of functions which can instantiate object of required class, must not be null
280284
* @return a mapped instance of the class, must not be null
281285
* @see JBBPMapper#FLAG_IGNORE_MISSING_VALUES
282286
* @since 2.0.0
@@ -289,8 +293,10 @@ public final <T> T mapTo(final String path, final T instance, final JBBPMapperCu
289293
/**
290294
* Map the structure fields to object fields.
291295
*
292-
* @param objectToMap an object to map fields of the structure, must not be
293-
* null
296+
* @param <T> expected result type
297+
* @param objectToMap an object to map fields of the structure, must not be
298+
* null
299+
* @param instantiators array of functions which can instantiate object of required class, must not be null
294300
* @return the same object from the arguments but with filled fields by values
295301
* of the structure
296302
*/
@@ -302,8 +308,10 @@ public final <T> T mapTo(final T objectToMap, final Function<Class<?>, Object>..
302308
/**
303309
* Map the structure fields to object fields.
304310
*
305-
* @param instance object instance to be filled by values, must not be null
306-
* @param flags special flags to tune mapping process
311+
* @param <T> expected result type
312+
* @param instance object instance to be filled by values, must not be null
313+
* @param flags special flags to tune mapping process
314+
* @param instantiators array of functions which can instantiate object of required class, must not be null
307315
* @return the same object from the arguments but with filled fields by values
308316
* of the structure
309317
* @see JBBPMapper#FLAG_IGNORE_MISSING_VALUES
@@ -317,12 +325,12 @@ public final <T> T mapTo(final T instance, final int flags, final Function<Class
317325
/**
318326
* Map the structure fields to object fields.
319327
*
320-
* @param <T> the type of the input and the output to the function
328+
* @param <T> expected result type
321329
* @param instance an object to map fields of the structure, must not be
322330
* null
323331
* @param customFieldProcessor a custom field processor to provide values for
324332
* custom mapping fields, it can be null if there is not any custom field
325-
* @param instantiators auxiliary functions to generate instances of classes by request
333+
* @param instantiators array of functions which can instantiate object of required class, must not be null
326334
* @return the same object from the arguments but with filled fields by values
327335
* of the structure
328336
*/
@@ -334,14 +342,13 @@ public final <T> T mapTo(final T instance, final JBBPMapperCustomFieldProcessor
334342
/**
335343
* Map the structure fields to object fields.
336344
*
337-
* @param <T> the type of the input and the output to the function
345+
* @param <T> expected result type
338346
* @param objectToMap an object to map fields of the structure, must not be
339347
* null
340348
* @param customFieldProcessor a custom field processor to provide values for
341349
* custom mapping fields, it can be null if there is not any custom field
342350
* @param flags special flags to tune mapping process
343-
* @param instantiators auxiliary functions to generate instances of
344-
* classes by request
351+
* @param instantiators array of functions which can instantiate object of required class, must not be null
345352
* @return the same object from the arguments but with filled fields by values
346353
* of the structure
347354
* @see JBBPMapper#FLAG_IGNORE_MISSING_VALUES

0 commit comments

Comments
 (0)