com.github.evgenbar:java-binary-decoder

Reflection based decoder for decoding binary stream of C-like structures

License

License

Categories

Categories

Java Languages
GroupId

GroupId

com.github.evgenbar
ArtifactId

ArtifactId

java-binary-decoder
Last Version

Last Version

1.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

com.github.evgenbar:java-binary-decoder
Reflection based decoder for decoding binary stream of C-like structures
Project URL

Project URL

https://github.com/evgenbar/java-binary-decoder
Source Code Management

Source Code Management

http://github.com/evgenbar/java-binary-decoder/tree/master

Download java-binary-decoder

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.evgenbar/java-binary-decoder/ -->
<dependency>
    <groupId>com.github.evgenbar</groupId>
    <artifactId>java-binary-decoder</artifactId>
    <version>1.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.evgenbar/java-binary-decoder/
implementation 'com.github.evgenbar:java-binary-decoder:1.0.3'
// https://jarcasting.com/artifacts/com.github.evgenbar/java-binary-decoder/
implementation ("com.github.evgenbar:java-binary-decoder:1.0.3")
'com.github.evgenbar:java-binary-decoder:jar:1.0.3'
<dependency org="com.github.evgenbar" name="java-binary-decoder" rev="1.0.3">
  <artifact name="java-binary-decoder" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.evgenbar', module='java-binary-decoder', version='1.0.3')
)
libraryDependencies += "com.github.evgenbar" % "java-binary-decoder" % "1.0.3"
[com.github.evgenbar/java-binary-decoder "1.0.3"]

Dependencies

compile (2)

Group / Artifact Type Version
com.google.guava : guava jar 18.0
org.apache.commons : commons-lang3 jar 3.0

test (2)

Group / Artifact Type Version
junit : junit jar 4.11
org.hamcrest : hamcrest-all jar 1.3

Project Modules

There are no modules declared in this project.

java-binary-decoder Build Status

Simple library for decoding C++\C-like structures serialized to a binary buffer and converting them to Java classes.

Purpose

The library is intended to ease the maintenance of protocol between Java and the side that defines the binary structure.
The decoding is reflection based, thus it eliminates the need for changing the decoding code when the binary structure changes. The only thing that has to be changed is a corresponding Java class.

Features

  • Signed\Unsigned integer types
  • Hierarchical structures
  • Nested structures
  • Arrays (primitives and complex structures)
    • Arrays with constant size
    • Arrays with size determined by another structure member

How to use

Simple structure:

Given the following structure being serialized to a binary buffer:

struct mystruct 
{
	bool cBoolean;
	char cChar;
    unsigned char cByte; 
    short cShort;
    int cInt;
    long cLong;
    float cFloat;
    double cDouble;    
}

Assuming that serialization is done by the following rules: boolean is 1 byte, char is 1 byte, short is 2 bytes, int is 4 bytes, long is 8 bytes, float is 4 bytes and double is 8 bytes, the specified binary buffer consists of 29 bytes and includes all the data according to its apearance in the structure.
On the Java side the corresponding class will look like this:

@Decodable
public class MyJavaClass {
	public boolean javaBoolean;
    public char javaChar;
    public byte javaByte;
    public short javaShort;
    public int javaInt;
    public long javaLong;
    public float javaFloat;
    public double javaDouble;
}

The decoding itself:

IDataInputDecoder decoder = new BinaryDataDecoder();
try(DataInput dis = new DataInputStream(new BufferedInputStream(new ByteArrayInputStream(buffer)))){
	MyJavaClass instance = decoder.decode(MyJavaClass.class, dis);
}

Versions

Version
1.0.3
1.0.2
1.0.1