Skip to content

Commit

Permalink
ref[cs]: rename get and set method
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Jul 15, 2024
1 parent 6dae8da commit 32b7cec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private String protocol_write_serialization(ProtocolRegistration registration) {
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);
Expand Down
25 changes: 15 additions & 10 deletions protocol/src/main/resources/csharp/Buffer/ByteBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Clear()

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);
Expand All @@ -71,11 +71,16 @@ public void AdjustPadding(int predictionLength, int beforeWriteIndex) {
}

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;
}
Expand All @@ -93,7 +98,7 @@ public void SetWriteOffset(int writeIndex)
writeOffset = writeIndex;
}

public int ReadOffset()
public int GetReadOffset()
{
return readOffset;
}
Expand Down Expand Up @@ -603,7 +608,7 @@ public string GetString(byte[] value)
return Encoding.UTF8.GetString(value, 0, value.Length);
}

public void WriteBooleanArray(bool[] array)
public void WriteBoolArray(bool[] array)
{
if ((array == null) || (array.Length == 0))
{
Expand All @@ -620,7 +625,7 @@ public void WriteBooleanArray(bool[] array)
}
}

public bool[] ReadBooleanArray()
public bool[] ReadBoolArray()
{
int size = ReadInt();
bool[] array = new bool[size];
Expand Down Expand Up @@ -893,7 +898,7 @@ public T[] ReadPacketArray<T>(short protocolId)
return array;
}

public void WriteBooleanList(List<bool> list)
public void WriteBoolList(List<bool> list)
{
if ((list == null) || (list.Count == 0))
{
Expand All @@ -910,7 +915,7 @@ public void WriteBooleanList(List<bool> list)
}
}

public List<bool> ReadBooleanList()
public List<bool> ReadBoolList()
{
int size = ReadInt();
List<bool> list = new List<bool>(size);
Expand Down Expand Up @@ -1183,7 +1188,7 @@ public List<T> ReadPacketList<T>(short protocolId)
return list;
}

public void WriteBooleanSet(HashSet<bool> set)
public void WriteBoolSet(HashSet<bool> set)
{
if ((set == null) || (set.Count == 0))
{
Expand All @@ -1199,7 +1204,7 @@ public void WriteBooleanSet(HashSet<bool> set)
}
}

public HashSet<bool> ReadBooleanSet()
public HashSet<bool> ReadBoolSet()
{
int size = ReadInt();
HashSet<bool> set = new HashSet<bool>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public object Read(ByteBuffer buffer)
{
return null;
}
int beforeReadIndex = buffer.ReadOffset();
int beforeReadIndex = buffer.GetReadOffset();
${protocol_name} packet = new ${protocol_name}();
${protocol_read_deserialization}
if (length > 0)
Expand Down

0 comments on commit 32b7cec

Please sign in to comment.