From fa42f8a3f77ed50372c942e4a340664be9390b6f Mon Sep 17 00:00:00 2001 From: godotg Date: Sun, 14 Jul 2024 18:39:44 +0800 Subject: [PATCH] ref[kotlin]: rename writeBoolean/readBoolean/writeOffset/readOffset to writeBool/readBool/getWriteOffset/getReadOffset --- .../serializer/kotlin/CodeGenerateKotlin.java | 2 +- .../src/main/resources/kotlin/ByteBuffer.kt | 20 +++++++++++-------- .../kotlin/ProtocolRegistrationTemplate.kt | 2 +- protocol/src/test/kotlin/Main.kt | 2 +- .../test/kotlin/com/zfoo/kotlin/ByteBuffer.kt | 20 +++++++++++-------- .../com/zfoo/kotlin/packet/ComplexObject.kt | 12 +++++------ .../com/zfoo/kotlin/packet/EmptyObject.kt | 2 +- .../com/zfoo/kotlin/packet/NormalObject.kt | 4 ++-- .../kotlin/com/zfoo/kotlin/packet/ObjectA.kt | 4 ++-- .../kotlin/com/zfoo/kotlin/packet/ObjectB.kt | 4 ++-- .../com/zfoo/kotlin/packet/SimpleObject.kt | 2 +- 11 files changed, 41 insertions(+), 33 deletions(-) diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/kotlin/CodeGenerateKotlin.java b/protocol/src/main/java/com/zfoo/protocol/serializer/kotlin/CodeGenerateKotlin.java index e6e6b9e0..72e7cac9 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/kotlin/CodeGenerateKotlin.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/kotlin/CodeGenerateKotlin.java @@ -292,7 +292,7 @@ public class CodeGenerateKotlin implements ICodeGenerate { var fieldRegistrations = registration.getFieldRegistrations(); var ktBuilder = new StringBuilder(); if (registration.isCompatible()) { - ktBuilder.append("val beforeWriteIndex = buffer.writeOffset()").append(LS); + ktBuilder.append("val beforeWriteIndex = buffer.getWriteOffset()").append(LS); ktBuilder.append(StringUtils.format("buffer.writeInt({})", registration.getPredictionLength())).append(LS); } else { ktBuilder.append("buffer.writeInt(-1)").append(LS); diff --git a/protocol/src/main/resources/kotlin/ByteBuffer.kt b/protocol/src/main/resources/kotlin/ByteBuffer.kt index e79ebf94..4ca31c88 100644 --- a/protocol/src/main/resources/kotlin/ByteBuffer.kt +++ b/protocol/src/main/resources/kotlin/ByteBuffer.kt @@ -29,7 +29,11 @@ class ByteBuffer { } // -------------------------------------------------get/set------------------------------------------------- - fun writeOffset(): Int { + fun getBuffer(): ByteArray { + return buffer; + } + + fun getWriteOffset(): Int { return writeOffset } @@ -43,7 +47,7 @@ class ByteBuffer { writeOffset = writeIndex } - fun readOffset(): Int { + fun getReadOffset(): Int { return readOffset } @@ -350,7 +354,7 @@ class ByteBuffer { return String(bytes) } - fun writeBooleanArray(array: Array) { + fun writeBoolArray(array: Array) { if (array.size == 0) { writeInt(0) } else { @@ -362,7 +366,7 @@ class ByteBuffer { } } - fun readBooleanArray(): Array { + fun readBoolArray(): Array { val size = readInt() val array = Array(size) { init -> false } if (size > 0) { @@ -534,7 +538,7 @@ class ByteBuffer { return array } - fun writeBooleanList(list: List) { + fun writeBoolList(list: List) { if (list.isEmpty()) { writeInt(0) } else { @@ -545,7 +549,7 @@ class ByteBuffer { } } - fun readBooleanList(): List { + fun readBoolList(): List { val size = readInt() val list: MutableList = ArrayList() if (size > 0) { @@ -734,7 +738,7 @@ class ByteBuffer { return list } - fun writeBooleanSet(set: Set) { + fun writeBoolSet(set: Set) { if (set.isEmpty()) { writeInt(0) } else { @@ -745,7 +749,7 @@ class ByteBuffer { } } - fun readBooleanSet(): Set { + fun readBoolSet(): Set { val size = readInt() val set: MutableSet = HashSet() if (size > 0) { diff --git a/protocol/src/main/resources/kotlin/ProtocolRegistrationTemplate.kt b/protocol/src/main/resources/kotlin/ProtocolRegistrationTemplate.kt index 44ba6a18..56edd2c2 100644 --- a/protocol/src/main/resources/kotlin/ProtocolRegistrationTemplate.kt +++ b/protocol/src/main/resources/kotlin/ProtocolRegistrationTemplate.kt @@ -18,7 +18,7 @@ class ${protocol_name}Registration : IProtocolRegistration { if (length == 0) { return packet } - val beforeReadIndex = buffer.readOffset() + val beforeReadIndex = buffer.getReadOffset() ${protocol_read_deserialization} if (length > 0) { buffer.setReadOffset(beforeReadIndex + length) diff --git a/protocol/src/test/kotlin/Main.kt b/protocol/src/test/kotlin/Main.kt index c3bf2495..e6c40aaa 100644 --- a/protocol/src/test/kotlin/Main.kt +++ b/protocol/src/test/kotlin/Main.kt @@ -163,7 +163,7 @@ fun compatibleTest() { var equal = 0 var notEqual = 0 - for (i in 0 until buffer.writeOffset()) { + for (i in 0 until buffer.getWriteOffset()) { val a = buffer.readByte() val b = newBuffer.readByte() if (a == b) { diff --git a/protocol/src/test/kotlin/com/zfoo/kotlin/ByteBuffer.kt b/protocol/src/test/kotlin/com/zfoo/kotlin/ByteBuffer.kt index f0276a91..53866f5d 100644 --- a/protocol/src/test/kotlin/com/zfoo/kotlin/ByteBuffer.kt +++ b/protocol/src/test/kotlin/com/zfoo/kotlin/ByteBuffer.kt @@ -29,7 +29,11 @@ class ByteBuffer { } // -------------------------------------------------get/set------------------------------------------------- - fun writeOffset(): Int { + fun getBuffer(): ByteArray { + return buffer; + } + + fun getWriteOffset(): Int { return writeOffset } @@ -43,7 +47,7 @@ class ByteBuffer { writeOffset = writeIndex } - fun readOffset(): Int { + fun getReadOffset(): Int { return readOffset } @@ -350,7 +354,7 @@ class ByteBuffer { return String(bytes) } - fun writeBooleanArray(array: Array) { + fun writeBoolArray(array: Array) { if (array.size == 0) { writeInt(0) } else { @@ -362,7 +366,7 @@ class ByteBuffer { } } - fun readBooleanArray(): Array { + fun readBoolArray(): Array { val size = readInt() val array = Array(size) { init -> false } if (size > 0) { @@ -534,7 +538,7 @@ class ByteBuffer { return array } - fun writeBooleanList(list: List) { + fun writeBoolList(list: List) { if (list.isEmpty()) { writeInt(0) } else { @@ -545,7 +549,7 @@ class ByteBuffer { } } - fun readBooleanList(): List { + fun readBoolList(): List { val size = readInt() val list: MutableList = ArrayList() if (size > 0) { @@ -734,7 +738,7 @@ class ByteBuffer { return list } - fun writeBooleanSet(set: Set) { + fun writeBoolSet(set: Set) { if (set.isEmpty()) { writeInt(0) } else { @@ -745,7 +749,7 @@ class ByteBuffer { } } - fun readBooleanSet(): Set { + fun readBoolSet(): Set { val size = readInt() val set: MutableSet = HashSet() if (size > 0) { diff --git a/protocol/src/test/kotlin/com/zfoo/kotlin/packet/ComplexObject.kt b/protocol/src/test/kotlin/com/zfoo/kotlin/packet/ComplexObject.kt index 42d4629b..6facec9d 100644 --- a/protocol/src/test/kotlin/com/zfoo/kotlin/packet/ComplexObject.kt +++ b/protocol/src/test/kotlin/com/zfoo/kotlin/packet/ComplexObject.kt @@ -72,7 +72,7 @@ class ComplexObjectRegistration : IProtocolRegistration { return } val message = packet as ComplexObject - val beforeWriteIndex = buffer.writeOffset() + val beforeWriteIndex = buffer.getWriteOffset() buffer.writeInt(36962) buffer.writeByte(message.a) buffer.writeByte(message.aa) @@ -100,8 +100,8 @@ class ComplexObjectRegistration : IProtocolRegistration { buffer.writeDoubleArray(message.ffff) buffer.writeBool(message.g) buffer.writeBool(message.gg) - buffer.writeBooleanArray(message.ggg) - buffer.writeBooleanArray(message.gggg) + buffer.writeBoolArray(message.ggg) + buffer.writeBoolArray(message.gggg) buffer.writeString(message.jj) buffer.writeStringArray(message.jjj) buffer.writePacket(message.kk, 102) @@ -188,7 +188,7 @@ class ComplexObjectRegistration : IProtocolRegistration { if (length == 0) { return packet } - val beforeReadIndex = buffer.readOffset() + val beforeReadIndex = buffer.getReadOffset() val result0 = buffer.readByte() packet.a = result0 val result1 = buffer.readByte() @@ -241,9 +241,9 @@ class ComplexObjectRegistration : IProtocolRegistration { packet.g = result24 val result25 = buffer.readBool() packet.gg = result25 - val array26 = buffer.readBooleanArray() + val array26 = buffer.readBoolArray() packet.ggg = array26 - val array27 = buffer.readBooleanArray() + val array27 = buffer.readBoolArray() packet.gggg = array27 val result28 = buffer.readString() packet.jj = result28 diff --git a/protocol/src/test/kotlin/com/zfoo/kotlin/packet/EmptyObject.kt b/protocol/src/test/kotlin/com/zfoo/kotlin/packet/EmptyObject.kt index d65824ab..da00ac79 100644 --- a/protocol/src/test/kotlin/com/zfoo/kotlin/packet/EmptyObject.kt +++ b/protocol/src/test/kotlin/com/zfoo/kotlin/packet/EmptyObject.kt @@ -27,7 +27,7 @@ class EmptyObjectRegistration : IProtocolRegistration { if (length == 0) { return packet } - val beforeReadIndex = buffer.readOffset() + val beforeReadIndex = buffer.getReadOffset() if (length > 0) { buffer.setReadOffset(beforeReadIndex + length) diff --git a/protocol/src/test/kotlin/com/zfoo/kotlin/packet/NormalObject.kt b/protocol/src/test/kotlin/com/zfoo/kotlin/packet/NormalObject.kt index 2424556c..0ae0a324 100644 --- a/protocol/src/test/kotlin/com/zfoo/kotlin/packet/NormalObject.kt +++ b/protocol/src/test/kotlin/com/zfoo/kotlin/packet/NormalObject.kt @@ -40,7 +40,7 @@ class NormalObjectRegistration : IProtocolRegistration { return } val message = packet as NormalObject - val beforeWriteIndex = buffer.writeOffset() + val beforeWriteIndex = buffer.getWriteOffset() buffer.writeInt(857) buffer.writeByte(message.a) buffer.writeByteArray(message.aaa) @@ -71,7 +71,7 @@ class NormalObjectRegistration : IProtocolRegistration { if (length == 0) { return packet } - val beforeReadIndex = buffer.readOffset() + val beforeReadIndex = buffer.getReadOffset() val result0 = buffer.readByte() packet.a = result0 val array1 = buffer.readByteArray() diff --git a/protocol/src/test/kotlin/com/zfoo/kotlin/packet/ObjectA.kt b/protocol/src/test/kotlin/com/zfoo/kotlin/packet/ObjectA.kt index d7dc8f52..f8c6d6ad 100644 --- a/protocol/src/test/kotlin/com/zfoo/kotlin/packet/ObjectA.kt +++ b/protocol/src/test/kotlin/com/zfoo/kotlin/packet/ObjectA.kt @@ -22,7 +22,7 @@ class ObjectARegistration : IProtocolRegistration { return } val message = packet as ObjectA - val beforeWriteIndex = buffer.writeOffset() + val beforeWriteIndex = buffer.getWriteOffset() buffer.writeInt(201) buffer.writeInt(message.a) buffer.writeIntStringMap(message.m) @@ -37,7 +37,7 @@ class ObjectARegistration : IProtocolRegistration { if (length == 0) { return packet } - val beforeReadIndex = buffer.readOffset() + val beforeReadIndex = buffer.getReadOffset() val result0 = buffer.readInt() packet.a = result0 val map1 = buffer.readIntStringMap() diff --git a/protocol/src/test/kotlin/com/zfoo/kotlin/packet/ObjectB.kt b/protocol/src/test/kotlin/com/zfoo/kotlin/packet/ObjectB.kt index fee4cb65..56778417 100644 --- a/protocol/src/test/kotlin/com/zfoo/kotlin/packet/ObjectB.kt +++ b/protocol/src/test/kotlin/com/zfoo/kotlin/packet/ObjectB.kt @@ -19,7 +19,7 @@ class ObjectBRegistration : IProtocolRegistration { return } val message = packet as ObjectB - val beforeWriteIndex = buffer.writeOffset() + val beforeWriteIndex = buffer.getWriteOffset() buffer.writeInt(4) buffer.writeBool(message.flag) buffer.writeInt(message.innerCompatibleValue) @@ -32,7 +32,7 @@ class ObjectBRegistration : IProtocolRegistration { if (length == 0) { return packet } - val beforeReadIndex = buffer.readOffset() + val beforeReadIndex = buffer.getReadOffset() val result0 = buffer.readBool() packet.flag = result0 if (buffer.compatibleRead(beforeReadIndex, length)) { diff --git a/protocol/src/test/kotlin/com/zfoo/kotlin/packet/SimpleObject.kt b/protocol/src/test/kotlin/com/zfoo/kotlin/packet/SimpleObject.kt index 01f45b2c..bb95fb03 100644 --- a/protocol/src/test/kotlin/com/zfoo/kotlin/packet/SimpleObject.kt +++ b/protocol/src/test/kotlin/com/zfoo/kotlin/packet/SimpleObject.kt @@ -30,7 +30,7 @@ class SimpleObjectRegistration : IProtocolRegistration { if (length == 0) { return packet } - val beforeReadIndex = buffer.readOffset() + val beforeReadIndex = buffer.getReadOffset() val result0 = buffer.readInt() packet.c = result0 val result1 = buffer.readBool()