Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support serialization feature from Kaitai 0.11-SNAPSHOT #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,24 @@ See [kaitai-java-demo](https://github.com/valery1707/kaitai-java-demo).

## Plugin parameters

| Name | Type | Since | Description |
|-----------------|--------------|-------|-------------------------------------------------------------------------------------------------------------------------|
| skip | boolean | 0.1.0 | Skip plugin execution (don't read/validate any files, don't generate any java types).<br><br>**Default**: `false` |
| url | java.net.URL | 0.1.0 | Direct link onto [KaiTai universal zip archive](http://kaitai.io/#download).<br><br>**Default**: Detected from version |
| version | String | 0.1.0 | Version of [KaiTai](http://kaitai.io/#download) library.<br><br>**Default**: `0.8` |
| cacheDir | java.io.File | 0.1.0 | Cache directory for download KaiTai library.<br><br>**Default**: `build/tmp/kaitai-cache` |
| sourceDirectory | java.io.File | 0.1.0 | Source directory with [Kaitai Struct language](http://formats.kaitai.io/) files.<br><br>**Default**: src/main/resources/kaitai |
| includes | String[] | 0.1.0 | Include wildcard pattern list.<br><br>**Default**: ["*.ksy"] |
| excludes | String[] | 0.1.0 | Exclude wildcard pattern list.<br><br>**Default**: [] |
| output | java.io.File | 0.1.0 | Target directory for generated Java source files.<br><br>**Default**: `build/generated/kaitai` |
| exactOutput | Boolean | 0.1.5 | Move root of packages directory structure exact inside configured output path and remove `src` item.<br><br>**Default**: `false`|
| packageName | String | 0.1.0 | Target package for generated Java source files.<br><br>**Default**: Trying to get project's group or `kaitai` otherwise |
| executionTimeout| Long | 0.1.3 | Timeout for execution operations.<br><br>**Default**: `5000` |
| fromFileClass | String | 0.1.3 | Classname with custom KaitaiStream implementations for static builder `fromFile(...)`|
| opaqueTypes | Boolean | 0.1.3 | Allow use opaque (external) types in ksy. See more in [documentation](http://doc.kaitai.io/user_guide.html#opaque-types).|
| noVersionCheck | Boolean | 0.1.6 | Allow to disable Java version check. For non-Windows only.<br><br>**Default**: `false` |
| noAutoRead | Boolean | 0.1.7 | Allow to disable auto-running `_read` in constructor <br><br>**Default**: `false` |
| Name | Type | Since | Description |
|------------------|--------------|-------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
| skip | boolean | 0.1.0 | Skip plugin execution (don't read/validate any files, don't generate any java types).<br><br>**Default**: `false` |
| url | java.net.URL | 0.1.0 | Direct link onto [KaiTai universal zip archive](http://kaitai.io/#download).<br><br>**Default**: Detected from version |
| version | String | 0.1.0 | Version of [KaiTai](http://kaitai.io/#download) library.<br><br>**Default**: `0.8` |
| cacheDir | java.io.File | 0.1.0 | Cache directory for download KaiTai library.<br><br>**Default**: `build/tmp/kaitai-cache` |
| sourceDirectory | java.io.File | 0.1.0 | Source directory with [Kaitai Struct language](http://formats.kaitai.io/) files.<br><br>**Default**: src/main/resources/kaitai |
| includes | String[] | 0.1.0 | Include wildcard pattern list.<br><br>**Default**: ["*.ksy"] |
| excludes | String[] | 0.1.0 | Exclude wildcard pattern list.<br><br>**Default**: [] |
| output | java.io.File | 0.1.0 | Target directory for generated Java source files.<br><br>**Default**: `build/generated/kaitai` |
| exactOutput | Boolean | 0.1.5 | Move root of packages directory structure exact inside configured output path and remove `src` item.<br><br>**Default**: `false` |
| packageName | String | 0.1.0 | Target package for generated Java source files.<br><br>**Default**: Trying to get project's group or `kaitai` otherwise |
| executionTimeout | Long | 0.1.3 | Timeout for execution operations.<br><br>**Default**: `5000` |
| fromFileClass | String | 0.1.3 | Classname with custom KaitaiStream implementations for static builder `fromFile(...)` |
| opaqueTypes | Boolean | 0.1.3 | Allow use opaque (external) types in ksy. See more in [documentation](http://doc.kaitai.io/user_guide.html#opaque-types). |
| noVersionCheck | Boolean | 0.1.6 | Allow to disable Java version check. For non-Windows only.<br><br>**Default**: `false` |
| noAutoRead | Boolean | 0.1.7 | Allow to disable auto-running `_read` in constructor <br><br>**Default**: `false` |
| readWrite | Boolean | 0.1.8 | Generate in read-write mode. Requires Kaitai 0.11-SNAPSHOT. See: [Serialization Guide](https://doc.kaitai.io/serialization.html) <br><br>**Default**: `false` |

### Useful commands

Expand Down
Binary file added kaitai-struct-compiler-0.11-SNAPSHOT.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>name.valery1707.kaitai</groupId>
<artifactId>kaitai-maven-plugin</artifactId>
<version>0.1.7-SNAPSHOT</version>
<version>0.1.8-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>Kaitai Maven Plugin</name>
Expand Down
34 changes: 33 additions & 1 deletion src/main/java/name/valery1707/kaitai/KaitaiGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class KaitaiGenerator {
private Boolean opaqueTypes;
private boolean noVersionCheck;
private boolean noAutoRead;
private boolean readWrite;

/**
* Build {@code KaitaiGenerator} with preconfigured state.
Expand Down Expand Up @@ -274,6 +275,34 @@ public KaitaiGenerator noAutoRead(boolean noAutoRead) {
return this;
}

/**
* Get read write mode.
*
* @return read write mode
*/
public boolean isReadWrite() {
return readWrite;
}

/**
* Set read write mode.
*
* @param readWrite read write mode
*/
public void setReadWrite(boolean readWrite) {
this.readWrite = readWrite;
}

/**
* Set read write mode.
*
* @param readWrite read write mode
* @return self
*/
public KaitaiGenerator readWrite(boolean readWrite) {
setReadWrite(readWrite);
return this;
}

private ProcBuilder process(Logger log) {
ProcBuilder builder = new ProcBuilder(getKaitai().normalize().toAbsolutePath().toString())
Expand Down Expand Up @@ -340,9 +369,12 @@ public Path generate(Logger log) throws KaitaiException {
.withArgs("--target", "java")
.withArgs("--outdir", output.toFile().getAbsolutePath())
.withArgs("--java-package", getPackageName());
if (isNoAutoRead()) {
if (isNoAutoRead() || isReadWrite()) {
builder.withArgs("--no-auto-read");
}
if(isReadWrite()) {
builder.withArgs("--read-write");
}
if (isNotBlank(getFromFileClass())) {
builder.withArgs("--java-from-file-class", getFromFileClass());
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/name/valery1707/kaitai/KaitaiMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ public class KaitaiMojo extends AbstractMojo {
@Parameter(property = "kaitai.noAutoRead", defaultValue = "false")
private Boolean noAutoRead;

/**
* Generate in read-write mode.
*/
@Parameter(property = "kaitai.readWrite", defaultValue = "false")
private Boolean readWrite;

/**
* Allow to disable Java version check.
*
Expand Down Expand Up @@ -237,6 +243,7 @@ private void executeInt() throws KaitaiException {
.opaqueTypes(opaqueTypes)
.noVersionCheck(noVersionCheck)
.noAutoRead(noAutoRead)
.readWrite(readWrite)
.generate(logger);

//Add generated directory into Maven's build scope
Expand Down
Loading