Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jyotindersingh/cerealib
A high performance serialization library for Java.
https://github.com/jyotindersingh/cerealib
Last synced: about 6 hours ago
JSON representation
A high performance serialization library for Java.
- Host: GitHub
- URL: https://github.com/jyotindersingh/cerealib
- Owner: JyotinderSingh
- Created: 2021-07-01T15:25:42.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-07-15T20:06:00.000Z (over 3 years ago)
- Last Synced: 2023-09-10T13:36:05.111Z (about 1 year ago)
- Language: Java
- Homepage:
- Size: 1.26 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
![Cerealib Banner](./cerealibBanner.png)
## Cerealib - A High Performance Serialization Library for Java
Cerealib is a fast serialization library for Java which supports all Java Primitives, Strings, and Primitive Arrays -
and offers many performance benefits over the default Java Serialization implementation.For real world usage and reference, try out the code in the [CerealibSandbox](./CerealibSandbox/src) module!
## Why did I build yet another serialization library?
While working on another side project, I ended up requiring a serialization solution. As I was going through Java's
official implementation, I came across quite a few comments which said that it wasn't really performant, and one was
better off using third party libraries. This kind of felt odd in a way, that a language's official implementation would
be critiqued for performance (after all, the entire world writes their code in Java).This led me to fall into a rabbit hole, trying to learn more about how serialization is actually implemented, and what
makes Java's implementation sub par (the reasons were things which I could safely circumvent, given that I didn't need
to support any legacy implementations, reflection, or versioning). This felt like a nice way to spend a weekend.# Usage Guide
## Concepts:
### CLDatabase
Every serialized file is referred to as a CLDatabase. A CLDatabase contains all the information needed to write / read
the data to / from a binary file.A CLDatabase is made up of multiple CLObjects.
- ### CLObjects
A CLObject is an entity, which can contain related *CLFields*, *CLStrings*, *CLArrays*. Think of it as a class / class
object, that contains all the different properties related to that instance / object.
- ### CLField
- CLFields correspond to the Java Primitives such as **Byte, Short, Char, Int, Long, Float, Double, Boolean**.
- When you want to serialize one of the Java primitives, you use one of these CLFields.- ### CLString
- Since Strings are not a Primitive Java type, you need to use the special CLString to serialize a string.- ### CLArray
- Whenever you have an array sequence of a particular type, you need to use the CLArray class to serialize it.## Serializing:
Create a new CLDatabase instance
```java
CLDatabase database=new CLDatabase("Database");
```Create an object to store in the database (you can have as many of these as you want in a single CLDatabase)
```java
CLObject object=new CLObject("ObjectName");
```Start adding CLFields, CLArrays, CLStrings to the object
```java
// To add a string to the object, we use the Create method in the CLString class
object.addString(CLString.Create("colour","red"));// To add one of the primitive types, we call the corresponding method on the CLField class.
object.addField(CLField.Integer("age",24));
object.addField(CLField.Boolean("ranked",true));
object.addField(CLField.Short("num",50));
object.addField(CLField.Byte("byteNum",4));
object.addField(CLField.Double("doubleNum",234.35));
// and so on...// Adding an array sequence to the object.
// Generating a random integer array.
int[]data=new int[50000];
for(int i=0;i