GithubHelp home page GithubHelp logo

ggrandes / packer Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 75 KB

Packer is a Simple Data Serializer for Java (like Kryo or native Serializable/Externalizable) but Zen-style

License: Apache License 2.0

Java 100.00%
serializer kryo encryption java

packer's Introduction

packer

Simple Data Packer for Java (like Kryo,... but very simplified). Open Source Java project under Apache License v2.0

Current Stable Version is 1.1.2


DOC

Supported data types

  • Fixed length types:
    • byte, char, short, int, long, double, float
  • Variable length types (optimized space):
    • int, long, negative int, negative long
  • Complex types:
    • String and byte[] (using Variable Length Int or Fixed Int32 for sizes)
    • HexString
    • String Collection
    • String Map

Features

  • Compression (Deflate)
  • Encryption (AES/GCM/NoPadding; randomIV) java 8+ note-1
  • Encryption (AES/CBC/PKCS5Padding) note-1
    • Default IV
    • Shared IV
    • Random IV
    • Random Integer IV (compact IV)
  • Encryption (RSA/ECB/PKCS1Padding) note-1
  • CRC-8 (CRC-8 poly 0xD5)
  • Hash (MessageDigest)
  • HMAC (Mac)
  • Buffer AutoExtend
note-1: It is encouraged not to reuse instances of the Packer object when using encryption (IV are initialized only once).

Usage Example

import org.javastack.packer.Packer;

public class Example {
	public static void main(final String[] args) {
		// Sample usage (output):
		Packer p = new Packer(16);
		p.setAutoExtendPolicy(AutoExtendPolicy.AUTO);	// Enable AutoExtend
		p.useCompress(true);               				// Enable Compression
		p.useCRC(true);                    				// Enable CRC
		String s1 = "hello", s2 = "world";
		String hs = "df0c290eae2b";
		byte b = 42;
		long l = 0x648C9A7109B4L;
		int ni = -192813;
		p.putString(s1).putString(s2);
		p.putHexString(hs);
		p.putByte(b);
		p.putVLong(l);
		p.putVNegInt(ni);
		p.flip();
		String out = p.outputStringBase64URLSafe();
		System.out.println(out.length() + "\t" + out);

		// Sample usage (load):
		p = new Packer(16);
		p.setAutoExtendPolicy(AutoExtendPolicy.AUTO);	// Enable AutoExtend
		p.useCompress(true);               				// Enable Compression
		p.useCRC(true);                    				// Enable CRC
		p.loadStringBase64URLSafe(out);
		System.out.println(p.getString());
		System.out.println(p.getString());
		System.out.println(p.getHexStringUpper());
		System.out.println(p.getByte());
		System.out.println(p.getVLong());
		System.out.println(p.getVNegInt());
	}
}

MAVEN

Add the dependency to your pom.xml:

<dependency>
    <groupId>org.javastack</groupId>
    <artifactId>packer</artifactId>
    <version>1.1.2</version>
</dependency>

Benchmarks

TODO

Inspired in Kryo and Perl-Pack, this code is Java-minimalistic version.

packer's People

Contributors

ggrandes avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

packer's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.