The Codec module allows us to encode and decode custom objects in a fast and efficient way.
You can add Codec module to your project by inserting dependency in pom.xml:
CodecRegistry allows to easily access pre-defined codecs based on your custom data types. Use create() method to
create your CodecRegistry, and with() to setup the codec.
StructuredCodecs contains various implementations of StructuredCodec. StructuredCodec extends
StructuredEncoder and StructureDecoder interfaces. It wraps classes, lists, maps and other data structures for
Yet, you can create custom codecs. There are several ways to do so:
CodecRegistry has a method get, which returns a new StructuredCodec. So, you can first adjust your CodecRegistry
and then use it for this purpose.
There are lots of predefined methods that return StructuredCodec.
To run the examples, you need to clone DataKernel from GitHub:
$ git clone https://github.com/softindex/datakernel And import it as a Maven project. Check out branch v3.0. Before running the examples, build the project.
These examples are located at datakernel -> examples -> core -> codec.
All of these examples utilize two utility classes. The first one is a simple POJO Person with three values id, name,
dateOfBirth. The second one is Registry, which is needed for encoding/decoding:
Let’s now proceed to the examples.
Structured Binary Example
In this example we encode Person John to ByteBuf and then decode him back to Person. To perform such
operations, we first need to create a StructuredCodec and then use it for encode and decode operations.