Skip to content

Commit 44392bd

Browse files
author
Evgeny Barabanov
committed
- Start to write a documentation
1 parent 6740390 commit 44392bd

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

README.md

+54-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,54 @@
1-
# java-binary-decoder
2-
[![Build Status](https://travis-ci.org/meltedspark/java-binary-decoder.svg?branch=master)](https://travis-ci.org/meltedspark/java-binary-decoder)
1+
# java-binary-decoder [![Build Status](https://travis-ci.org/meltedspark/java-binary-decoder.svg?branch=master)](https://travis-ci.org/meltedspark/java-binary-decoder)
2+
Simple library for decoding C++\C-like structures serialized to a binary buffer and converting them to Java classes.
3+
4+
## Purpose
5+
The library is intended to ease the maintenance of protocol between Java and the side that defines the binary structure.
6+
The decoding is reflection based, thus it eliminates the need for chaning the decoding code when the binary structure changes. The only thing that has to be changed is a corresponding Java class.
7+
8+
## Features
9+
* Signed\Unsigned integer types
10+
* Hierarchical structures
11+
* Nested structures
12+
* Arrays (primitives and complex structures)
13+
* Arrays with constant size
14+
* Arrays with size determined by another structure member
15+
16+
## How to use
17+
18+
### Simple structure:
19+
Given the following structure being serialized to a binary buffer:
20+
```c++
21+
struct mystruct
22+
{
23+
bool cBoolean;
24+
char cChar;
25+
unsigned char cByte;
26+
short cShort;
27+
int cInt;
28+
long cLong;
29+
float cFloat;
30+
double cDouble;
31+
}
32+
```
33+
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.
34+
On the Java side the corresponding class will look like this:
35+
```java
36+
@Decodable
37+
public class MyJavaClass {
38+
public boolean javaBoolean;
39+
public char javaChar;
40+
public byte javaByte;
41+
public short javaShort;
42+
public int javaInt;
43+
public long javaLong;
44+
public float javaFloat;
45+
public double javaDouble;
46+
}
47+
```
48+
The decoding itself:
49+
```java
50+
IDataInputDecoder decoder = new BinaryDataDecoder();
51+
try(DataInput dis = new DataInputStream(new BufferedInputStream(new ByteArrayInputStream(buffer)))){
52+
MyJavaClass instance = decoder.decode(MyJavaClass.class, dis);
53+
}
54+
```

0 commit comments

Comments
 (0)