From 32b7cec8c822f8cef2613bd7c2bc77975d905cf0 Mon Sep 17 00:00:00 2001 From: godotg Date: Mon, 15 Jul 2024 16:38:02 +0800 Subject: [PATCH] ref[cs]: rename get and set method --- .../serializer/csharp/CodeGenerateCsharp.java | 2 +- .../resources/csharp/Buffer/ByteBuffer.cs | 25 +++++++++++-------- .../csharp/ProtocolRegistrationTemplate.cs | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/csharp/CodeGenerateCsharp.java b/protocol/src/main/java/com/zfoo/protocol/serializer/csharp/CodeGenerateCsharp.java index eb9b116a..c56cf368 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/csharp/CodeGenerateCsharp.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/csharp/CodeGenerateCsharp.java @@ -242,7 +242,7 @@ public class CodeGenerateCsharp implements ICodeGenerate { var fieldRegistrations = registration.getFieldRegistrations(); var csBuilder = new StringBuilder(); if (registration.isCompatible()) { - csBuilder.append("int beforeWriteIndex = buffer.WriteOffset();").append(LS); + csBuilder.append("int beforeWriteIndex = buffer.GetWriteOffset();").append(LS); csBuilder.append(StringUtils.format("buffer.WriteInt({});", registration.getPredictionLength())).append(LS); } else { csBuilder.append("buffer.WriteInt(-1);").append(LS); diff --git a/protocol/src/main/resources/csharp/Buffer/ByteBuffer.cs b/protocol/src/main/resources/csharp/Buffer/ByteBuffer.cs index 373ea8a7..3234a786 100644 --- a/protocol/src/main/resources/csharp/Buffer/ByteBuffer.cs +++ b/protocol/src/main/resources/csharp/Buffer/ByteBuffer.cs @@ -52,7 +52,7 @@ namespace zfoocs public void AdjustPadding(int predictionLength, int beforeWriteIndex) { // 因为写入的是可变长的int,如果预留的位置过多,则清除多余的位置 - var currentWriteIndex = WriteOffset(); + var currentWriteIndex = GetWriteOffset(); var predictionCount = WriteIntCount(predictionLength); var length = currentWriteIndex - beforeWriteIndex - predictionCount; var lengthCount = WriteIntCount(length); @@ -71,11 +71,16 @@ namespace zfoocs } public bool CompatibleRead(int beforeReadIndex, int length) { - return length != -1 && ReadOffset() < length + beforeReadIndex; + return length != -1 && GetReadOffset() < length + beforeReadIndex; } // -------------------------------------------------get/set------------------------------------------------- - public int WriteOffset() + public byte[] GetBuffer() + { + return buffer; + } + + public int GetWriteOffset() { return writeOffset; } @@ -93,7 +98,7 @@ namespace zfoocs writeOffset = writeIndex; } - public int ReadOffset() + public int GetReadOffset() { return readOffset; } @@ -603,7 +608,7 @@ namespace zfoocs return Encoding.UTF8.GetString(value, 0, value.Length); } - public void WriteBooleanArray(bool[] array) + public void WriteBoolArray(bool[] array) { if ((array == null) || (array.Length == 0)) { @@ -620,7 +625,7 @@ namespace zfoocs } } - public bool[] ReadBooleanArray() + public bool[] ReadBoolArray() { int size = ReadInt(); bool[] array = new bool[size]; @@ -893,7 +898,7 @@ namespace zfoocs return array; } - public void WriteBooleanList(List list) + public void WriteBoolList(List list) { if ((list == null) || (list.Count == 0)) { @@ -910,7 +915,7 @@ namespace zfoocs } } - public List ReadBooleanList() + public List ReadBoolList() { int size = ReadInt(); List list = new List(size); @@ -1183,7 +1188,7 @@ namespace zfoocs return list; } - public void WriteBooleanSet(HashSet set) + public void WriteBoolSet(HashSet set) { if ((set == null) || (set.Count == 0)) { @@ -1199,7 +1204,7 @@ namespace zfoocs } } - public HashSet ReadBooleanSet() + public HashSet ReadBoolSet() { int size = ReadInt(); HashSet set = new HashSet(); diff --git a/protocol/src/main/resources/csharp/ProtocolRegistrationTemplate.cs b/protocol/src/main/resources/csharp/ProtocolRegistrationTemplate.cs index d32207eb..098cb391 100644 --- a/protocol/src/main/resources/csharp/ProtocolRegistrationTemplate.cs +++ b/protocol/src/main/resources/csharp/ProtocolRegistrationTemplate.cs @@ -23,7 +23,7 @@ public class ${protocol_name}Registration : IProtocolRegistration { return null; } - int beforeReadIndex = buffer.ReadOffset(); + int beforeReadIndex = buffer.GetReadOffset(); ${protocol_name} packet = new ${protocol_name}(); ${protocol_read_deserialization} if (length > 0)