在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:protostuff/protostuff开源软件地址:https://github.com/protostuff/protostuff开源编程语言:Java 99.0%开源软件介绍:A java serialization library with built-in support for forward-backward compatibility (schema evolution) and validation.
Usecase
For more information, go to https://protostuff.github.io/docs/ Maven
<dependency>
<groupId>io.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
<version>1.7.4</version>
</dependency>
<dependency>
<groupId>io.protostuff</groupId>
<artifactId>protostuff-runtime</artifactId>
<version>1.7.4</version>
</dependency> Usagepublic 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 (for version 1.8.x)If you are to purely use this to replace java serialization (no compatibility with protobuf), set the following system properties:
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
RequirementsJava 1.6 or higher Build RequirementsMaven 3.2.3 or higher Developing with eclipsemvn install && mvn eclipse:eclipse
# Open eclipse, import existing project, navigate to the protostuff module you're after, then hit 'Finish'. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论