Skip to content

Commit

Permalink
⚡ protostuff 调成可选依赖.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunMengLu committed Aug 25, 2019
1 parent bd27b7c commit e4688ba
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
* @author L.cm
*/
public class ProtoStuffSerializer implements RedisSerializer<Object> {
private static final Schema<BytesWrapper> SCHEMA = RuntimeSchema.getSchema(BytesWrapper.class);
private final Schema<BytesWrapper> schema;

public ProtoStuffSerializer() {
this.schema = RuntimeSchema.getSchema(BytesWrapper.class);
}

@Override
public byte[] serialize(Object object) throws SerializationException {
Expand All @@ -39,7 +43,7 @@ public byte[] serialize(Object object) throws SerializationException {
}
LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
try {
return ProtostuffIOUtil.toByteArray(new BytesWrapper<>(object), SCHEMA, buffer);
return ProtostuffIOUtil.toByteArray(new BytesWrapper<>(object), schema, buffer);
} finally {
buffer.clear();
}
Expand All @@ -51,7 +55,7 @@ public Object deserialize(byte[] bytes) throws SerializationException {
return null;
}
BytesWrapper<Object> wrapper = new BytesWrapper<>();
ProtostuffIOUtil.mergeFrom(bytes, wrapper, SCHEMA);
ProtostuffIOUtil.mergeFrom(bytes, wrapper, schema);
return wrapper.getValue();
}
}

0 comments on commit e4688ba

Please sign in to comment.