Skip to content

Commit

Permalink
release 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
raydac committed Nov 20, 2019
1 parent 4e01b02 commit c8ed0d6
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 45 deletions.
6 changes: 3 additions & 3 deletions .projectKnowledge/JBBP.mmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Mind Map generated by NB MindMap plugin
> fillColor=`#CCCCFF`,leftSide=`true`


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


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


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

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

#### Maven plugin
> fillColor=`#D1FF9C`
Expand Down
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ For instance I have been very actively using the framework in [the ZX-Poly emula
![Use cases](https://github.com/raydac/java-binary-block-parser/blob/master/docs/jbbp_mm.png)

# Change log
- **2.0.0-SNAPSHOT**
- **2.0.0 (20-nov-2019)**
- __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 instances for local classes
- 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

Expand Down Expand Up @@ -67,7 +67,7 @@ The Framework has been published in the Maven Central and can be easily added as
<dependency>
<groupId>com.igormaznitsa</groupId>
<artifactId>jbbp</artifactId>
<version>1.4.1</version>
<version>2.0.0</version>
</dependency>
```
the precompiled library jar, javadoc and sources also can be downloaded directly from [the Maven central.](http://search.maven.org/#browse|808871750)
Expand All @@ -83,7 +83,7 @@ The Easiest case below shows how to parse byte array to bits.
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.
```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(Parsed.class);
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
Expand All @@ -100,7 +100,7 @@ Since 1.3.0 version, the framework can convert JBBP scripts into sources __(the
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
```Java
JBBPParser parser = JBBPParser.prepare("byte a; byte b; byte c;");
List<ResultSrcItem> generated = parser.convertToSrc(TargetSources.JAVA_1_6,"com.test.jbbp.gen.SomeClazz");
List<ResultSrcItem> generated = parser.convertToSrc(TargetSources.JAVA,"com.test.jbbp.gen.SomeClazz");
for(ResultSrcItem i : generated) {
for(Map.Entry<String,String> j :i.getResult().entrySet()) {
System.out.println("Class file name "+j.getKey());
Expand All @@ -114,7 +114,7 @@ in Maven you should just add such plugin execution
<plugin>
<groupId>com.igormaznitsa</groupId>
<artifactId>jbbp-maven-plugin</artifactId>
<version>1.4.1</version>
<version>2.0.0</version>
<executions>
<execution>
<id>gen-jbbp-src</id>
Expand All @@ -138,7 +138,7 @@ class Flags {
}

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(Flags.class);
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);
Expand Down Expand Up @@ -302,9 +302,12 @@ final JBBPParser pngParser = JBBPParser.prepare(
class Png {
long header;
Chunk [] chunk;
public Object newInstance(Class<?> klazz){
return klazz == Chunk.class ? new Chunk() : null;
}
}

final Png png = pngParser.parse(pngStream).mapTo(Png.class);
final Png png = pngParser.parse(pngStream).mapTo(new Png());
```
The Example from tests shows how to parse a tcp frame wrapped in a network frame
```Java
Expand Down
4 changes: 2 additions & 2 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
2.0.0-SNAPSHOT
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 instances for local classes
- 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

Expand Down
Binary file modified docs/jbbp_mm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion jbbp-plugins/jbbp-gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def getProp(name, dflt) {
}
}

def jbbpVersion = getProp('jbbp_plugin_version', '2.0.0-SNAPSHOT')
def jbbpVersion = getProp('jbbp_plugin_version', '2.0.0')
def metaLibVersion = getProp('meta_lib_version', '1.1.2')

group = 'com.igormaznitsa'
Expand Down
4 changes: 3 additions & 1 deletion jbbp-plugins/jbbp-gradle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.igormaznitsa</groupId>
<artifactId>jbbp-main-plugin-pom</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.0</version>
</parent>

<artifactId>jbbp-gradle-plugin</artifactId>
Expand All @@ -22,6 +22,8 @@
</dependencies>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<gradleGoal>install</gradleGoal>
</properties>

Expand Down
2 changes: 1 addition & 1 deletion jbbp-plugins/jbbp-maven/jbbp-maven-plugin-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.igormaznitsa</groupId>
<artifactId>jbbp-maven-plugin-pom</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.0</version>
</parent>

<artifactId>jbbp-maven-plugin-tests</artifactId>
Expand Down
10 changes: 9 additions & 1 deletion jbbp-plugins/jbbp-maven/jbbp-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.igormaznitsa</groupId>
<artifactId>jbbp-maven-plugin-pom</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.0</version>
</parent>

<artifactId>jbbp-maven-plugin</artifactId>
Expand All @@ -14,6 +14,11 @@
<name>JBBP Maven plugin</name>
<description>Generator of sources from JBBP scripts</description>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<profiles>
<profile>
<id>publish</id>
Expand Down Expand Up @@ -61,6 +66,9 @@
<goals>
<goal>jar</goal>
</goals>
<configuration>
<source>1.8</source>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<plugin>
<groupId>com.igormaznitsa</groupId>
<artifactId>jbbp-maven-plugin</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.0</version>
<goals>
<goal>generate</goal>
</goals>
Expand Down
2 changes: 1 addition & 1 deletion jbbp-plugins/jbbp-maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.igormaznitsa</groupId>
<artifactId>jbbp-main-plugin-pom</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.0</version>
</parent>

<artifactId>jbbp-maven-plugin-pom</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion jbbp-plugins/jbbp-plugin-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.igormaznitsa</groupId>
<artifactId>jbbp-main-plugin-pom</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.0</version>
</parent>

<artifactId>jbbp-plugin-common</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion jbbp-plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.igormaznitsa</groupId>
<artifactId>jbbp-main-pom</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.0</version>
</parent>

<artifactId>jbbp-main-plugin-pom</artifactId>
Expand Down
10 changes: 9 additions & 1 deletion jbbp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.igormaznitsa</groupId>
<artifactId>jbbp-main-pom</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.0</version>
</parent>

<artifactId>jbbp</artifactId>
Expand All @@ -16,6 +16,11 @@
own DSL to describe parsing data format
</description>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.openjdk.jmh</groupId>
Expand Down Expand Up @@ -164,6 +169,9 @@
<goals>
<goal>jar</goal>
</goals>
<configuration>
<source>1.8</source>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.igormaznitsa.jbbp.io;

import com.igormaznitsa.jbbp.utils.JBBPUtils;

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
Expand Down Expand Up @@ -418,6 +417,7 @@ public void writeString(final String value, final JBBPByteOrder order) throws IO
* <b>the byte order in saved char data will be BIG_ENDIAN</b>
*
* @param value array to be written, must not be null but can contain null values
* @param order byte order to write char data, must not be null
* @throws IOException it will be thrown for transport errors
* @see #writeString(String, JBBPByteOrder)
* @since 1.4.0
Expand Down
2 changes: 1 addition & 1 deletion jbbp/src/main/java/com/igormaznitsa/jbbp/mapper/Bin.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* from parsed a JBBP structure. Also it can be used for whole class but in the
* case be careful and use default name and path values. The Class is not thread safe.
*
* <b></>Since 2.0.0 was removed prefix 'out' for fields which contained it</b>.
* <b>Since 2.0.0 was removed prefix 'out' for fields which contained it</b>.
*
* @since 1.0
*/
Expand Down
45 changes: 26 additions & 19 deletions jbbp/src/main/java/com/igormaznitsa/jbbp/model/JBBPFieldStruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.igormaznitsa.jbbp.model;

import static com.igormaznitsa.jbbp.utils.JBBPUtils.ARRAY_FIELD_EMPTY;


import com.igormaznitsa.jbbp.compiler.JBBPNamedFieldInfo;
import com.igormaznitsa.jbbp.exceptions.JBBPFinderException;
import com.igormaznitsa.jbbp.exceptions.JBBPTooManyFieldsFoundException;
Expand All @@ -24,11 +27,8 @@
import com.igormaznitsa.jbbp.model.finder.JBBPFieldFinder;
import com.igormaznitsa.jbbp.utils.Function;
import com.igormaznitsa.jbbp.utils.JBBPUtils;

import java.util.List;

import static com.igormaznitsa.jbbp.utils.JBBPUtils.ARRAY_FIELD_EMPTY;

/**
* Describes a structure.
*
Expand Down Expand Up @@ -224,9 +224,10 @@ public <T extends JBBPAbstractField> T findFieldForPathAndType(final String fiel
* Find a structure by its path and map the structure fields to a class
* fields.
*
* @param <T> a class type
* @param path the path to the structure to be mapped, must not be null
* @param instance object instance to be filled by values, must not be null
* @param <T> a class type
* @param path the path to the structure to be mapped, must not be null
* @param instance object instance to be filled by values, must not be null
* @param instantiators array of functions which can instantiate object of required class, must not be null
* @return a mapped instance of the class, must not be null
* @since 2.0.0
*/
Expand All @@ -239,10 +240,11 @@ public final <T> T mapTo(final String path, final T instance, final Function<Cla
* Find a structure by its path and map the structure fields to a class
* fields.
*
* @param <T> a class type
* @param path the path to the structure to be mapped, must not be null
* @param instance object instance to be filled by values, must not be null
* @param flags special flags to tune mapping process
* @param <T> a class type
* @param path the path to the structure to be mapped, must not be null
* @param instance object instance to be filled by values, must not be null
* @param flags special flags to tune mapping process
* @param instantiators array of functions which can instantiate object of required class, must not be null
* @return a mapped instance of the class, must not be null
* @see JBBPMapper#FLAG_IGNORE_MISSING_VALUES
* @since 2.0.0
Expand All @@ -260,6 +262,7 @@ public final <T> T mapTo(final String path, final T instance, final int flags, f
* @param path the path to the structure to be mapped, must not be null
* @param instance object instance to be filled by values, must not be null
* @param customFieldProcessor a custom field processor to provide values for custom mapping fields, it can be null if there is not any custom field
* @param instantiators array of functions which can instantiate object of required class, must not be null
* @return a mapped instance of the class, must not be null
* @since 2.0.0
*/
Expand All @@ -277,6 +280,7 @@ public final <T> T mapTo(final String path, final T instance, final JBBPMapperCu
* @param instance object instance to be filled by values, must not be null
* @param customFieldProcessor a custom field processor to provide values for custom mapping fields, it can be null if there is not any custom field
* @param flags special flags to tune mapping process
* @param instantiators array of functions which can instantiate object of required class, must not be null
* @return a mapped instance of the class, must not be null
* @see JBBPMapper#FLAG_IGNORE_MISSING_VALUES
* @since 2.0.0
Expand All @@ -289,8 +293,10 @@ public final <T> T mapTo(final String path, final T instance, final JBBPMapperCu
/**
* Map the structure fields to object fields.
*
* @param objectToMap an object to map fields of the structure, must not be
* null
* @param <T> expected result type
* @param objectToMap an object to map fields of the structure, must not be
* null
* @param instantiators array of functions which can instantiate object of required class, must not be null
* @return the same object from the arguments but with filled fields by values
* of the structure
*/
Expand All @@ -302,8 +308,10 @@ public final <T> T mapTo(final T objectToMap, final Function<Class<?>, Object>..
/**
* Map the structure fields to object fields.
*
* @param instance object instance to be filled by values, must not be null
* @param flags special flags to tune mapping process
* @param <T> expected result type
* @param instance object instance to be filled by values, must not be null
* @param flags special flags to tune mapping process
* @param instantiators array of functions which can instantiate object of required class, must not be null
* @return the same object from the arguments but with filled fields by values
* of the structure
* @see JBBPMapper#FLAG_IGNORE_MISSING_VALUES
Expand All @@ -317,12 +325,12 @@ public final <T> T mapTo(final T instance, final int flags, final Function<Class
/**
* Map the structure fields to object fields.
*
* @param <T> the type of the input and the output to the function
* @param <T> expected result type
* @param instance an object to map fields of the structure, must not be
* null
* @param customFieldProcessor a custom field processor to provide values for
* custom mapping fields, it can be null if there is not any custom field
* @param instantiators auxiliary functions to generate instances of classes by request
* @param instantiators array of functions which can instantiate object of required class, must not be null
* @return the same object from the arguments but with filled fields by values
* of the structure
*/
Expand All @@ -334,14 +342,13 @@ public final <T> T mapTo(final T instance, final JBBPMapperCustomFieldProcessor
/**
* Map the structure fields to object fields.
*
* @param <T> the type of the input and the output to the function
* @param <T> expected result type
* @param objectToMap an object to map fields of the structure, must not be
* null
* @param customFieldProcessor a custom field processor to provide values for
* custom mapping fields, it can be null if there is not any custom field
* @param flags special flags to tune mapping process
* @param instantiators auxiliary functions to generate instances of
* classes by request
* @param instantiators array of functions which can instantiate object of required class, must not be null
* @return the same object from the arguments but with filled fields by values
* of the structure
* @see JBBPMapper#FLAG_IGNORE_MISSING_VALUES
Expand Down
Loading

0 comments on commit c8ed0d6

Please sign in to comment.