Skip to content

nobloat/bare-jvm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bare-jvm

CircleCI codecov

bare-jvm-logo

This is a bare messages implementation for the JVM.

Features

  • Zero external dependencies and small, well structured code base
  • Parsing of bare schemas
  • Code generation for data structures, encoding and decoding methods out ouf bare schemas
  • Decoding primitive data types from InputStream
  • Decoding aggregate data types from InputStream
  • Encoding primitive data types to OutputStream
  • Encoding aggregate data types to OutputStream
  • Reflective decoding of data types from InputStream

Type mappings

Primitive type mappings

bare-jvm bare spec
String string
byte byte
boolean bool
byte[] data
byte[] data<length>
float f32
double f64
@Int(Int.Type.i64) long i64
@Int(Int.Type.u64) BigInteger u64
@Int(Int.Type.i32) int i32
@Int(Int.Type.u32) long u32
@Int(Int.Type.i16) short i16
@Int(Int.Type.u16) int i16
@Int(Int.Type.u8) byte u8
@Int(Int.Type.i8) byte i8
@Int(Int.Type.i) long int
@Int(Int.Type.ui) BigInteger uint

Aggregate types

bare-jvm bare spec
List<T> []type
Array<T> [length]type
Map<K,V> map[type A]type B
Optional<T> optional<type>
class Person {public String name;} struct
Union u = new Union(Person.class, Account.class) tagged union

Usage

  • Simply copy the required classes from org.nobloat.bare or add the dependency via

  • Generate the data structures, encoding and decoding structures with

    • java -jar bare-jvm.jar schema.bare org.example.Messages
    • This will create all data types in a class Messages under org/example/Messages.java

Limitations

  • Java has no concept of unsigned primitive data types, hence double the amount of memory is required to safely use unsigned types:
    • u64 becomes BigInteger
    • u32 becomes long
    • u16 becomes int
    • u8 becomes short
  • Anonymous structs are not supported by the code generator.