Vertx Binary Serializer

A simple binary serialization method for vertx which uses annotations and reflection like spring jpa / hibernate for databases.

License

License

GroupId

GroupId

com.jukusoft
ArtifactId

ArtifactId

vertx-binary-serializer-parent
Last Version

Last Version

1.0.8
Release Date

Release Date

Type

Type

pom
Description

Description

Vertx Binary Serializer
A simple binary serialization method for vertx which uses annotations and reflection like spring jpa / hibernate for databases.
Project URL

Project URL

https://github.com/JuKu/vertx-binary-serialization
Source Code Management

Source Code Management

https://github.com/JuKu/vertx-binary-serialization

Download vertx-binary-serializer-parent

How to add to project

<!-- https://jarcasting.com/artifacts/com.jukusoft/vertx-binary-serializer-parent/ -->
<dependency>
    <groupId>com.jukusoft</groupId>
    <artifactId>vertx-binary-serializer-parent</artifactId>
    <version>1.0.8</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/com.jukusoft/vertx-binary-serializer-parent/
implementation 'com.jukusoft:vertx-binary-serializer-parent:1.0.8'
// https://jarcasting.com/artifacts/com.jukusoft/vertx-binary-serializer-parent/
implementation ("com.jukusoft:vertx-binary-serializer-parent:1.0.8")
'com.jukusoft:vertx-binary-serializer-parent:pom:1.0.8'
<dependency org="com.jukusoft" name="vertx-binary-serializer-parent" rev="1.0.8">
  <artifact name="vertx-binary-serializer-parent" type="pom" />
</dependency>
@Grapes(
@Grab(group='com.jukusoft', module='vertx-binary-serializer-parent', version='1.0.8')
)
libraryDependencies += "com.jukusoft" % "vertx-binary-serializer-parent" % "1.0.8"
[com.jukusoft/vertx-binary-serializer-parent "1.0.8"]

Dependencies

compile (1)

Group / Artifact Type Version
io.vertx : vertx-core jar 3.5.4

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
io.vertx : vertx-unit jar 3.5.4
org.mockito : mockito-core jar 2.2.7

Project Modules

  • serializer
  • benchmark
  • connection

vertx-binary-serialization

A simple binary serialization method for vertx which uses annotations & reflection like spring jpa for databases.

Build Status Lines of Code Quality Gate Coverage Technical Debt Rating Code Smells Bugs Vulnerabilities Security Rating

Sonarcloud

Requirements

Maven Coordinates

Maven Central

<dependency>
  <groupId>com.jukusoft</groupId>
  <artifactId>vertx-binary-serializer</artifactId>
  <version>1.0.8</version>
</dependency>

<!-- If you want to use TCPServer and TCPClient, you need also this dependency -->
<dependency>
  <groupId>com.jukusoft</groupId>
  <artifactId>vertx-binary-serializer-connection</artifactId>
  <version>1.0.8</version>
</dependency>

HowTo

First create some message objects which contains some datatypes:

@MessageType(type = 0x01)
@ProtocolVersion(1)
public class Message implements SerializableObject {

    @SInteger
    public int test = 0;

}

@MessageType(type = 0x02)
@ProtocolVersion(2)
public class SecondMessage implements SerializableObject {
    
    @SFloat
    public float a = 0f;

    @SString
    public String myString = null;

}

You have to add the annotations MessageType with the type (1 byte as type, 1 byte as extended type) and ProtocolVersion to check, if Serializer on other side can unserialize this object.

Then you can serialize and unserialize this object easely:

//first, register this new message types
TypeLookup.register(Message.class);
TypeLookup.register(SecondMessage.class);

//create message object which implements SerializableObject
Message msg = new Message();
msg.test = 20;

SecondMessage msg1 = new SecondMessage();
msg1.a = 0.2f;
msg1.myString = "my-new-string";

//serialize object into byte buffer
Buffer buffer = Serializer.serialize(msg);

//unserialize object from byte buffer
Message obj1 = Serializer.unserialize(buffer);

//get value
System.out.println("test value: " + obj1.test);

//second message

//serialize object into byte buffer
Buffer buffer = Serializer.serialize(msg1);

//unserialize object from byte buffer
SecondMessage obj2 = Serializer.unserialize(buffer);

//get value(s)
System.out.println("float value: " + obj2.a);
System.out.println("string value: " + obj2.myString);

NOTICE: public variables aren't required, they can also be private or protected instead. But to avoid getters & setters here, we have accessed them directly in this example.

Protocol Header

Before adding the payload to buffer, there is adding a header with these fields:

  • maybe: 4x byte (integer) length of message (so it can check, if full message was received or we have to wait for other traffic)
  • 1x byte type
  • 1x byte extended byte (so you can use 65,536 different types, instead of 256 bytes)
  • 2x byte version (to check compatibility)
  • after that: payload data

Supported datatypes

All primitive datatypes in Java are supported:

  • byte (@SByte)
  • short (@SShort)
  • int (@SInteger)
  • long (@SLong)
  • float (@SFloat)
  • double (@SDouble)
  • boolean (@SBoolean)
  • char (@SChar)
  • Vertx. Buffer (@SBuffer)
  • byte array (max 4.294.967.296 bytes in an array, @SBytes)
  • json object & json array (@SJsonObject and @SJsonArray)

Complex datatypes (objects) are not supported!

Run Sonarcloud

clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=jukusoft -Dsonar.login=<Sonar-Token>

Support

If you have questions, found a bug or have a feature request:
Please open an issue! I try to answer as fast as possible.

Versions

Version
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.0