protostuff :: me

protostuff for j2me

License

License

GroupId

GroupId

io.protostuff
ArtifactId

ArtifactId

protostuff-me
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

protostuff :: me
protostuff for j2me
Project URL

Project URL

http://code.google.com/p/protostuff/protostuff-me/

Download protostuff-me

How to add to project

<!-- https://jarcasting.com/artifacts/io.protostuff/protostuff-me/ -->
<dependency>
    <groupId>io.protostuff</groupId>
    <artifactId>protostuff-me</artifactId>
    <version>1.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.protostuff/protostuff-me/
implementation 'io.protostuff:protostuff-me:1.1.0'
// https://jarcasting.com/artifacts/io.protostuff/protostuff-me/
implementation ("io.protostuff:protostuff-me:1.1.0")
'io.protostuff:protostuff-me:jar:1.1.0'
<dependency org="io.protostuff" name="protostuff-me" rev="1.1.0">
  <artifact name="protostuff-me" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.protostuff', module='protostuff-me', version='1.1.0')
)
libraryDependencies += "io.protostuff" % "protostuff-me" % "1.1.0"
[io.protostuff/protostuff-me "1.1.0"]

Dependencies

provided (2)

Group / Artifact Type Version
org.microemu : cldcapi11 jar 2.0.4
org.microemu : midpapi20 jar 2.0.4

test (1)

Group / Artifact Type Version
junit : junit jar 3.8.2

Project Modules

There are no modules declared in this project.

Protostuff

A java serialization library with built-in support for forward-backward compatibility (schema evolution) and validation.

  • efficient, both in speed and memory
  • flexible, supporting pluggable formats

Usecase

  • messaging layer in RPC
  • storage format in the datastore or cache

For more information, go to https://protostuff.github.io/docs/

Maven

  1. For the core formats (protostuff, protobuf, graph)
<dependency>
  <groupId>io.protostuff</groupId>
  <artifactId>protostuff-core</artifactId>
  <version>1.7.2</version>
</dependency>
  1. For schemas generated at runtime
<dependency>
  <groupId>io.protostuff</groupId>
  <artifactId>protostuff-runtime</artifactId>
  <version>1.7.2</version>
</dependency>

Usage

public final class Foo
{
    String name;
    int id;
    
    public Foo(String name, int id)
    {
        this.name = name;
        this.id = id;
    }
}

static void roundTrip()
{
    Foo foo = new Foo("foo", 1);

    // this is lazily created and cached by RuntimeSchema
    // so its safe to call RuntimeSchema.getSchema(Foo.class) over and over
    // The getSchema method is also thread-safe
    Schema<Foo> schema = RuntimeSchema.getSchema(Foo.class);

    // Re-use (manage) this buffer to avoid allocating on every serialization
    LinkedBuffer buffer = LinkedBuffer.allocate(512);

    // ser
    final byte[] protostuff;
    try
    {
        protostuff = ProtostuffIOUtil.toByteArray(foo, schema, buffer);
    }
    finally
    {
        buffer.clear();
    }

    // deser
    Foo fooParsed = schema.newMessage();
    ProtostuffIOUtil.mergeFrom(protostuff, fooParsed, schema);
}

Important

If you are to purely use this to replace java serialization (no compatibility with protobuf), set the following system properties:

-Dprotostuff.runtime.always_use_sun_reflection_factory=true
-Dprotostuff.runtime.preserve_null_elements=true
-Dprotostuff.runtime.morph_collection_interfaces=true
-Dprotostuff.runtime.morph_map_interfaces=true
-Dprotostuff.runtime.morph_non_final_pojos=true

You can also customize it programmatically:

static final DefaultIdStrategy STRATEGY = new DefaultIdStrategy(IdStrategy.DEFAULT_FLAGS 
        | IdStrategy.PRESERVE_NULL_ELEMENTS
        | IdStrategy.MORPH_COLLECTION_INTERFACES
        | IdStrategy.MORPH_MAP_INTERFACES
        | IdStrategy.MORPH_NON_FINAL_POJOS);

Use it:

Schema<Foo> schema = RuntimeSchema.getSchema(Foo.class, STRATEGY);

Questions/Concerns/Suggestions

Requirements

Java 1.6 or higher

Build Requirements

Maven 3.2.3 or higher

Developing with eclipse

mvn install && mvn eclipse:eclipse
# Open eclipse, import existing project, navigate to the protostuff module you're after, then hit 'Finish'.
io.protostuff

protostuff

the stuff that leverages google's protobuf

Versions

Version
1.1.0