perf[zfoo]: 放弃使用protostuff,protostuff在高版本的jdk中会出现warn,使用jprotobuf

This commit is contained in:
jaysunxiao
2021-12-29 19:31:57 +08:00
parent 26e3404a04
commit 70e51c8b00
14 changed files with 190 additions and 30 deletions
+1 -1
View File
@@ -43,7 +43,7 @@
<google.guava.version>30.1-jre</google.guava.version>
<google.protobuf.version>3.9.1</google.protobuf.version>
<google.gson.version>2.8.6</google.gson.version>
<protostuff.version>1.7.4</protostuff.version>
<jprotobuf.version>2.4.13</jprotobuf.version>
<kryo.version>5.0.3</kryo.version>
<caffeine.version>2.8.8</caffeine.version>
<jctools.version>3.2.0</jctools.version>
+1 -1
View File
@@ -43,7 +43,7 @@
<google.guava.version>30.1-jre</google.guava.version>
<google.protobuf.version>3.9.1</google.protobuf.version>
<google.gson.version>2.8.6</google.gson.version>
<protostuff.version>1.7.4</protostuff.version>
<jprotobuf.version>2.4.13</jprotobuf.version>
<kryo.version>5.0.3</kryo.version>
<caffeine.version>2.8.8</caffeine.version>
<jctools.version>3.2.0</jctools.version>
+1 -1
View File
@@ -42,7 +42,7 @@
<google.guava.version>30.1-jre</google.guava.version>
<google.protobuf.version>3.9.1</google.protobuf.version>
<google.gson.version>2.8.6</google.gson.version>
<protostuff.version>1.7.4</protostuff.version>
<jprotobuf.version>2.4.13</jprotobuf.version>
<kryo.version>5.0.3</kryo.version>
<caffeine.version>2.8.8</caffeine.version>
<jctools.version>3.2.0</jctools.version>
+1 -1
View File
@@ -42,7 +42,7 @@
<google.guava.version>30.1-jre</google.guava.version>
<google.protobuf.version>3.9.1</google.protobuf.version>
<google.gson.version>2.8.6</google.gson.version>
<protostuff.version>1.7.4</protostuff.version>
<jprotobuf.version>2.4.13</jprotobuf.version>
<kryo.version>5.0.3</kryo.version>
<caffeine.version>2.8.8</caffeine.version>
<jctools.version>3.2.0</jctools.version>
+1 -1
View File
@@ -43,7 +43,7 @@
<google.guava.version>30.1-jre</google.guava.version>
<google.protobuf.version>3.9.1</google.protobuf.version>
<google.gson.version>2.8.6</google.gson.version>
<protostuff.version>1.7.4</protostuff.version>
<jprotobuf.version>2.4.13</jprotobuf.version>
<kryo.version>5.0.3</kryo.version>
<caffeine.version>2.8.8</caffeine.version>
<jctools.version>3.2.0</jctools.version>
+1 -1
View File
@@ -42,7 +42,7 @@
<google.guava.version>30.1-jre</google.guava.version>
<google.protobuf.version>3.9.1</google.protobuf.version>
<google.gson.version>2.8.6</google.gson.version>
<protostuff.version>1.7.4</protostuff.version>
<jprotobuf.version>2.4.13</jprotobuf.version>
<kryo.version>5.0.3</kryo.version>
<caffeine.version>2.8.8</caffeine.version>
<jctools.version>3.2.0</jctools.version>
+1 -1
View File
@@ -69,7 +69,7 @@
<google.guava.version>30.1-jre</google.guava.version>
<google.protobuf.version>3.9.1</google.protobuf.version>
<google.gson.version>2.8.6</google.gson.version>
<protostuff.version>1.7.4</protostuff.version>
<jprotobuf.version>2.4.13</jprotobuf.version>
<kryo.version>5.0.3</kryo.version>
<caffeine.version>2.8.8</caffeine.version>
<jctools.version>3.2.0</jctools.version>
+31 -20
View File
@@ -43,7 +43,7 @@
<google.guava.version>30.1-jre</google.guava.version>
<google.protobuf.version>3.9.1</google.protobuf.version>
<google.gson.version>2.8.6</google.gson.version>
<protostuff.version>1.7.4</protostuff.version>
<jprotobuf.version>2.4.13</jprotobuf.version>
<kryo.version>5.0.3</kryo.version>
<caffeine.version>2.8.8</caffeine.version>
<jctools.version>3.2.0</jctools.version>
@@ -151,31 +151,18 @@
<version>${jackson.version}</version>
</dependency>
<!-- Protobuf -->
<dependency>
<groupId>io.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
<version>1.7.4</version>
<groupId>com.baidu</groupId>
<artifactId>jprotobuf</artifactId>
<version>${jprotobuf.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.protostuff</groupId>
<artifactId>protostuff-runtime</artifactId>
<version>1.7.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>${google.protobuf.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
@@ -204,6 +191,30 @@
<scope>test</scope>
</dependency>
<!-- slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- logback核心包 -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
<!-- logback的sl4j的实现 -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- 依赖的测试库 -->
<dependency>
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2020 The zfoo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.protocol.jprotobuf;
import com.baidu.bjf.remoting.protobuf.annotation.Protobuf;
import com.zfoo.protocol.IPacket;
import java.util.Map;
/**
* @author jaysunxiao
* @version 3.0
*/
public class ObjectA implements IPacket {
public static final transient short PROTOCOL_ID = 102;
@Protobuf(order = 1)
public int a;
@Protobuf(order = 2)
public Map<Integer, String> m;
@Protobuf(order = 3)
public ObjectB objectB;
@Override
public short protocolId() {
return PROTOCOL_ID;
}
}
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2020 The zfoo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.protocol.jprotobuf;
import com.baidu.bjf.remoting.protobuf.annotation.Protobuf;
import com.zfoo.protocol.IPacket;
/**
* @author jaysunxiao
* @version 3.0
*/
public class ObjectB implements IPacket {
public static final transient short PROTOCOL_ID = 103;
@Protobuf(order = 1)
public boolean flag;
@Override
public short protocolId() {
return PROTOCOL_ID;
}
}
@@ -0,0 +1,70 @@
/*
* Copyright (C) 2020 The zfoo Authors
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.protocol.jprotobuf;
import com.baidu.bjf.remoting.protobuf.ProtobufProxy;
import com.zfoo.protocol.packet.ProtobufObject;
import com.zfoo.protocol.util.JsonUtils;
import org.junit.Ignore;
import org.junit.Test;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* @author jaysunxiao
* @version 3.0
*/
@Ignore
public class ProtostuffTest {
private static final Map<Integer, String> mapWithInteger = new HashMap<>(Map.of(Integer.MIN_VALUE, "a", -99, "b", 0, "c", 99, "d", Integer.MAX_VALUE, "e"));
@Test
public void deserializerTest() throws IOException {
var simpleTypeCodec = ProtobufProxy.create(ObjectA.class);
var obj = new ObjectA();
obj.a = Integer.MAX_VALUE;
obj.m = mapWithInteger;
// 序列化
byte[] bytes = simpleTypeCodec.encode(obj);
// 反序列化
var newObj = simpleTypeCodec.decode(bytes);
// 反序列化到protobuf
var newProtobufObj = ProtobufObject.ObjectA.parseFrom(bytes);
System.out.println(JsonUtils.object2String(newObj));
}
@Test
public void serializerTest() throws IOException {
// 原生protobuf对象
var protobufObjectB = ProtobufObject.ObjectB.newBuilder().setFlag(false).build();
var protobufObjectA = ProtobufObject.ObjectA.newBuilder()
.setA(Integer.MAX_VALUE)
.putAllM(mapWithInteger)
.setObjectB(protobufObjectB)
.build();
byte[] bytes = protobufObjectA.toByteArray();
var simpleTypeCodec = ProtobufProxy.create(ObjectA.class);
var newObj = simpleTypeCodec.decode(bytes);
System.out.println(JsonUtils.object2String(newObj));
}
}
+1 -1
View File
@@ -43,7 +43,7 @@
<google.guava.version>30.1-jre</google.guava.version>
<google.protobuf.version>3.9.1</google.protobuf.version>
<google.gson.version>2.8.6</google.gson.version>
<protostuff.version>1.7.4</protostuff.version>
<jprotobuf.version>2.4.13</jprotobuf.version>
<kryo.version>5.0.3</kryo.version>
<caffeine.version>2.8.8</caffeine.version>
<jctools.version>3.2.0</jctools.version>
+1 -1
View File
@@ -43,7 +43,7 @@
<google.guava.version>30.1-jre</google.guava.version>
<google.protobuf.version>3.9.1</google.protobuf.version>
<google.gson.version>2.8.6</google.gson.version>
<protostuff.version>1.7.4</protostuff.version>
<jprotobuf.version>2.4.13</jprotobuf.version>
<kryo.version>5.0.3</kryo.version>
<caffeine.version>2.8.8</caffeine.version>
<jctools.version>3.2.0</jctools.version>
+1 -1
View File
@@ -43,7 +43,7 @@
<google.guava.version>30.1-jre</google.guava.version>
<google.protobuf.version>3.9.1</google.protobuf.version>
<google.gson.version>2.8.6</google.gson.version>
<protostuff.version>1.7.4</protostuff.version>
<jprotobuf.version>2.4.13</jprotobuf.version>
<kryo.version>5.0.3</kryo.version>
<caffeine.version>2.8.8</caffeine.version>
<jctools.version>3.2.0</jctools.version>