From 70e51c8b00a23cbb9a0f34763bc1e9439fec5f1f Mon Sep 17 00:00:00 2001 From: jaysunxiao Date: Wed, 29 Dec 2021 19:31:57 +0800 Subject: [PATCH] =?UTF-8?q?perf[zfoo]:=20=E6=94=BE=E5=BC=83=E4=BD=BF?= =?UTF-8?q?=E7=94=A8protostuff=EF=BC=8Cprotostuff=E5=9C=A8=E9=AB=98?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=9A=84jdk=E4=B8=AD=E4=BC=9A=E5=87=BA?= =?UTF-8?q?=E7=8E=B0warn=EF=BC=8C=E4=BD=BF=E7=94=A8jprotobuf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- boot/pom.xml | 2 +- event/pom.xml | 2 +- hotswap/pom.xml | 2 +- monitor/pom.xml | 2 +- net/pom.xml | 2 +- orm/pom.xml | 2 +- pom.xml | 2 +- protocol/pom.xml | 51 ++++++++------ .../com/zfoo/protocol/jprotobuf/ObjectA.java | 43 ++++++++++++ .../com/zfoo/protocol/jprotobuf/ObjectB.java | 36 ++++++++++ .../protocol/jprotobuf/ProtostuffTest.java | 70 +++++++++++++++++++ scheduler/pom.xml | 2 +- storage/pom.xml | 2 +- util/pom.xml | 2 +- 14 files changed, 190 insertions(+), 30 deletions(-) create mode 100644 protocol/src/test/java/com/zfoo/protocol/jprotobuf/ObjectA.java create mode 100644 protocol/src/test/java/com/zfoo/protocol/jprotobuf/ObjectB.java create mode 100644 protocol/src/test/java/com/zfoo/protocol/jprotobuf/ProtostuffTest.java diff --git a/boot/pom.xml b/boot/pom.xml index 62a1b061..0cf56921 100644 --- a/boot/pom.xml +++ b/boot/pom.xml @@ -43,7 +43,7 @@ 30.1-jre 3.9.1 2.8.6 - 1.7.4 + 2.4.13 5.0.3 2.8.8 3.2.0 diff --git a/event/pom.xml b/event/pom.xml index 32618590..2db45e6b 100644 --- a/event/pom.xml +++ b/event/pom.xml @@ -43,7 +43,7 @@ 30.1-jre 3.9.1 2.8.6 - 1.7.4 + 2.4.13 5.0.3 2.8.8 3.2.0 diff --git a/hotswap/pom.xml b/hotswap/pom.xml index dea1f823..ff7a3e81 100644 --- a/hotswap/pom.xml +++ b/hotswap/pom.xml @@ -42,7 +42,7 @@ 30.1-jre 3.9.1 2.8.6 - 1.7.4 + 2.4.13 5.0.3 2.8.8 3.2.0 diff --git a/monitor/pom.xml b/monitor/pom.xml index ce05c67d..b39ab914 100644 --- a/monitor/pom.xml +++ b/monitor/pom.xml @@ -42,7 +42,7 @@ 30.1-jre 3.9.1 2.8.6 - 1.7.4 + 2.4.13 5.0.3 2.8.8 3.2.0 diff --git a/net/pom.xml b/net/pom.xml index 2434f028..45a1ae06 100644 --- a/net/pom.xml +++ b/net/pom.xml @@ -43,7 +43,7 @@ 30.1-jre 3.9.1 2.8.6 - 1.7.4 + 2.4.13 5.0.3 2.8.8 3.2.0 diff --git a/orm/pom.xml b/orm/pom.xml index ff9a9c26..ce734996 100644 --- a/orm/pom.xml +++ b/orm/pom.xml @@ -42,7 +42,7 @@ 30.1-jre 3.9.1 2.8.6 - 1.7.4 + 2.4.13 5.0.3 2.8.8 3.2.0 diff --git a/pom.xml b/pom.xml index b376ea78..7b46a804 100644 --- a/pom.xml +++ b/pom.xml @@ -69,7 +69,7 @@ 30.1-jre 3.9.1 2.8.6 - 1.7.4 + 2.4.13 5.0.3 2.8.8 3.2.0 diff --git a/protocol/pom.xml b/protocol/pom.xml index d7f8d7ea..f01d1101 100644 --- a/protocol/pom.xml +++ b/protocol/pom.xml @@ -43,7 +43,7 @@ 30.1-jre 3.9.1 2.8.6 - 1.7.4 + 2.4.13 5.0.3 2.8.8 3.2.0 @@ -151,31 +151,18 @@ ${jackson.version} + - io.protostuff - protostuff-core - 1.7.4 + com.baidu + jprotobuf + ${jprotobuf.version} test - - - - io.protostuff - protostuff-runtime - 1.7.4 - test - - - - com.google.protobuf - protobuf-java - ${google.protobuf.version} - com.google.guava - guava + slf4j-api + org.slf4j - test @@ -204,6 +191,30 @@ test + + + org.slf4j + slf4j-api + ${slf4j.version} + + + + ch.qos.logback + logback-core + ${logback.version} + + + + ch.qos.logback + logback-classic + ${logback.version} + + + slf4j-api + org.slf4j + + + diff --git a/protocol/src/test/java/com/zfoo/protocol/jprotobuf/ObjectA.java b/protocol/src/test/java/com/zfoo/protocol/jprotobuf/ObjectA.java new file mode 100644 index 00000000..cc240d0c --- /dev/null +++ b/protocol/src/test/java/com/zfoo/protocol/jprotobuf/ObjectA.java @@ -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 m; + + @Protobuf(order = 3) + public ObjectB objectB; + + @Override + public short protocolId() { + return PROTOCOL_ID; + } + +} diff --git a/protocol/src/test/java/com/zfoo/protocol/jprotobuf/ObjectB.java b/protocol/src/test/java/com/zfoo/protocol/jprotobuf/ObjectB.java new file mode 100644 index 00000000..0a171c02 --- /dev/null +++ b/protocol/src/test/java/com/zfoo/protocol/jprotobuf/ObjectB.java @@ -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; + } + +} + diff --git a/protocol/src/test/java/com/zfoo/protocol/jprotobuf/ProtostuffTest.java b/protocol/src/test/java/com/zfoo/protocol/jprotobuf/ProtostuffTest.java new file mode 100644 index 00000000..b28cf513 --- /dev/null +++ b/protocol/src/test/java/com/zfoo/protocol/jprotobuf/ProtostuffTest.java @@ -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 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)); + } + +} diff --git a/scheduler/pom.xml b/scheduler/pom.xml index 27f456ae..d488c66e 100644 --- a/scheduler/pom.xml +++ b/scheduler/pom.xml @@ -43,7 +43,7 @@ 30.1-jre 3.9.1 2.8.6 - 1.7.4 + 2.4.13 5.0.3 2.8.8 3.2.0 diff --git a/storage/pom.xml b/storage/pom.xml index fd000b66..9b0dad2b 100644 --- a/storage/pom.xml +++ b/storage/pom.xml @@ -43,7 +43,7 @@ 30.1-jre 3.9.1 2.8.6 - 1.7.4 + 2.4.13 5.0.3 2.8.8 3.2.0 diff --git a/util/pom.xml b/util/pom.xml index d3bf9cca..1285a908 100644 --- a/util/pom.xml +++ b/util/pom.xml @@ -43,7 +43,7 @@ 30.1-jre 3.9.1 2.8.6 - 1.7.4 + 2.4.13 5.0.3 2.8.8 3.2.0