Giter Club home page Giter Club logo

javastruct's Introduction

What is Javastruct

javastruct is a library for using java objects as C or C++ structs. It was exported to github from https://code.google.com/archive/p/javastruct/. Please contact the original authors there. Licence information is retained according to the original.

Build Status

What is it used for?

For details please refer to Wiki page

This library could be useful for java applications communicating with embedded devices or other C, C++ applications. It could also be used as a simple but space efficent serialization method.

Primitives, arrays, C Strings and Nested classes are supported. Big Endian and Little Endian byte orders are also supported. javastruct can also handle fields whose length is defined in other fields, using ArrayLengthMarker annotation. Please refer to examples and documentation in wiki section.

How to use JavaStruct

Classes should be marked as StructClass annotation and fields must be annotated to be used as struct fields.

Look at the test classes to learn usage in detail. A Simple Example:

@StructClass
public class Foo{
    @StructField(order = 0)
    public byte b;
    @StructField(order = 1)
    public int i;
}

try{
    // Pack the class as a byte buffer
    Foo f = new Foo();
    f.b = (byte)1;
    f.i = 1;
    byte[] b = JavaStruct.pack(f);
    
    // Unpack it into an object
    Foo f2 = new Foo();
    JavaStruct.unpack(f2, b);
}
catch(StructException e){
}

Peformance

For simple classes , JavaStruct is faster than Java serialization, For complex and nested objects, generally same performance as Java serialization. Naturally JavaStruct produces 2-3 times smaller output.

Future Work

  • Better naming and unified Façade class
  • Detailed documentation
  • ByteBuffer based struct serialization (Currently it is stream based)
  • Better performance
  • More unit tests
  • Data alignment support
  • Bitfields
  • Unions. Requirements
  • Any Os with Java 5 or upper JVM

Similar Projects

Jean-Marie Dautelle's Javolution also has an excellent struct implementation. Javolution structs uses special classes for representing fields, JavaStruct has a different approach and uses POJO's and Java 5 annotations.

javastruct's People

Contributors

dependabot[bot] avatar dubrousky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

javastruct's Issues

Jar file is out of date

What steps will reproduce the problem?
1. n/a
2.
3.

What is the expected output? What do you see instead?
n/a

What version of the product are you using? On what operating system?
n/a

Please provide any additional information below.
the Jar file available at http://code.google.com/p/javastruct/downloads/list is 
from July 2007.  The source is newer.  Is it possible to get a jar file from 
the latest source available?

Original issue reported on code.google.com by [email protected] on 6 Jul 2011 at 4:39

Clarify license and copyright

I'm missing information about the license and copyright of the sources. The 
project page says GNU Lesser GPL, but I doubt all files in the subversion trunk 
are covered by this license. Please clarify.

/Mikael

Original issue reported on code.google.com by [email protected] on 11 Jul 2011 at 6:00

LITTLE_ENDIAN - does not work!

Your System almost works!!! BUT Conversion with little endian does not work. It 
seems like you forgot to impliment byteorder when unpacking?? It is really 
unfortunate because I am soo close to get it working a serial protocol for 
arduino. 

You can reproduce the problem with the code below:


@StructClass
public class Foo{
    @StructField(order = 0)
    public int b;
    @StructField(order = 1)
    public int i;
}

try{
    // Pack the class as a byte buffer
    Foo f = new Foo();
    f.b = (int)14;
    f.i = 12;
    byte[] b = JavaStruct.pack(f,ByteOrder.LITTLE_ENDIAN );

    // Unpack it into an object
    Foo f2 = new Foo();
    JavaStruct.unpack(f2, b,ByteOrder.LITTLE_ENDIAN );
    println(f2.b);
}
catch(StructException e){
}
  et_begin();
  size(800, 600);
}

Original issue reported on code.google.com by [email protected] on 26 Jun 2014 at 8:46

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.