Java serialization library. Missing struct from C/C++? This is for you!
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Struct Build Status

Java serialization library.

This library tries to provide the functionality of a C-like struct - serialization of raw data. It's mainly a wrapper around DataOutputStream.

All primitive datatypes including Enum, String and Struct itself can be serialized natively by this lib. Other types are serialized dynamically with standard Java serialization.

See the javadocs for extended documentation.

Online Javadoc


Master branch is always unstable!



  • new major version => complete rewrite (no going to happen anyways)
  • new protocol version => incompatible to other (older) protocol version
  • fix => bug was fixed, improvements, new APIs, etc. Will not break compatibility.

Checkout latest release:

git clone --branch vX.X.X

Build with Gradle Wrapper

In project directory:

./gradlew build

Building with Gradle Wrapper ensures that you build with the right Gradle version.

JAR packaging

Add the following to your build.gradle:

In section repositories

maven { url '' }

In section dependencies

compile 'com.github.dckg:struct:vX.X.X'

Struct Definition

public final class MyStruct extends Struct {
    public int x;
    public int y;

This would be serialized to a byte array with a length of 8 bytes. No Object metainformation, nothing. Just raw data.

Struct Service

Struct Service provides basic RPC/RMI-like functionality.

Because it's a little inconvenient to have no type information associated with a Struct object, I created StructService.

"Struct, StructService UML Diagram"

StructService Definition

StructPacketTypes enumTypes = new StructPacketTypes();
// Service Struct definitions
// Can send and receive Structs of type AStruct, AnotherStruct, YetAnotherStruct.
enumTypes.add(new StructPacketType(AStruct.class));
enumTypes.add(new StructPacketType(AnotherStruct.class));
enumTypes.add(new StructPacketType(YetAnotherStruct.class));

StructService service = new StructService(enumTypes, new StructTypeCallback() {
	// Callback methods: 
	public void onDefault(Struct pStruct) {
		// receives any Struct type which has no method declared, here this would be
		// AnotherStruct and YetAnotherStruct
	public void onAStruct(AStruct s ) {
		// if a Struct of type AStruct is received, this method is called. 

See StructService testcases for a working example.