From 442c66b64291850bf197b29e1c20b858a70d8329 Mon Sep 17 00:00:00 2001 From: godotg Date: Sun, 10 Jul 2022 18:18:53 +0800 Subject: [PATCH] =?UTF-8?q?test[protocol]:=20=E5=A2=9E=E5=8A=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/jprotobuf/ProtobufTagTest.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 protocol/src/test/java/com/zfoo/protocol/jprotobuf/ProtobufTagTest.java diff --git a/protocol/src/test/java/com/zfoo/protocol/jprotobuf/ProtobufTagTest.java b/protocol/src/test/java/com/zfoo/protocol/jprotobuf/ProtobufTagTest.java new file mode 100644 index 00000000..881a179f --- /dev/null +++ b/protocol/src/test/java/com/zfoo/protocol/jprotobuf/ProtobufTagTest.java @@ -0,0 +1,51 @@ +/* + * 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 + * @version 3.0 + */ +@Ignore +public class ProtobufTagTest { + + @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]); + } + } + +}