del[net]: remove jprotobuf

This commit is contained in:
godotg
2023-12-10 23:13:41 +08:00
parent d0e83c6e1e
commit f1cb975715
28 changed files with 12 additions and 783 deletions
@@ -1,72 +0,0 @@
/*
* 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.ProtocolManager;
import com.zfoo.protocol.generate.GenerateOperation;
import com.zfoo.protocol.packet.ProtobufObject;
import com.zfoo.protocol.serializer.CodeLanguage;
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;
import java.util.Set;
/**
* @author godotg
*/
@Ignore
public class JProtobufTesting {
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,46 +0,0 @@
/*
* 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.anno.Protocol;
import java.util.Map;
/**
* protobuf的测试类型
* 包括了各种复杂的结构,对象,map
*
* @author godotg
*/
@Protocol(id = 102)
public class ObjectA {
// int类型,在protobuf中叫int32
@Protobuf(order = 1)
public int a;
// map类型
// protobuf中的map的key只能为基础类型
@Protobuf(order = 2)
public Map<Integer, String> m;
/**
* 对象类型
*/
@Protobuf(order = 3)
public ObjectB objectB;
}
@@ -1,29 +0,0 @@
/*
* 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.anno.Protocol;
/**
* @author godotg
*/
@Protocol(id = 103)
public class ObjectB {
@Protobuf(order = 1)
public boolean flag;
}
@@ -1,44 +0,0 @@
/*
* 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.anno.Protocol;
import java.util.Map;
/**
* ObjectC的测试类型
*
* @author godotg
*/
@Protocol(id = 104)
public class ObjectC {
// int类型,在protobuf中叫int32
@Protobuf(order = 1)
public int a;
// map类型
// protobuf中的map的key只能为基础类型
@Protobuf(order = 2)
public Map<Integer, String> m;
/**
* 对象类型
*/
@Protobuf(order = 3)
public ObjectB objectB;
}
@@ -1,50 +0,0 @@
/*
* 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.google.protobuf.CodedOutputStream;
import com.zfoo.protocol.buffer.ByteBufUtils;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.UnpooledUnsafeHeapByteBuf;
import org.junit.Ignore;
import org.junit.Test;
import java.io.IOException;
/**
* @author godotg
*/
@Ignore
public class ProtobufTagTesting {
@Test
public void test() throws IOException {
var buffer = new byte[1024 * 8];
var output = CodedOutputStream.newInstance(buffer);
output.writeSInt32NoTag(Integer.MAX_VALUE);
var length = output.getTotalBytesWritten();
for (int i = 0; i < length; i++) {
System.out.println(buffer[i]);
}
System.out.println("----------------------------------");
var byteBuf = new UnpooledUnsafeHeapByteBuf(ByteBufAllocator.DEFAULT, 100, 1_0000);
ByteBufUtils.writeInt(byteBuf, Integer.MAX_VALUE);
var bytes = ByteBufUtils.readAllBytes(byteBuf);
for (int i = 0; i < bytes.length; i++) {
System.out.println(bytes[i]);
}
}
}