Skip to content

Commit f71ddc5

Browse files
authored
Merge pull request #83 from eedalong/bug-fix/chinese-serilization-error
Change str length to uft-8 length
2 parents 6271bc9 + 0fd4db5 commit f71ddc5

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

src/Apache.IoTDB/DataStructure/ByteBuffer.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public bool GetBool()
5151
public int GetInt()
5252
{
5353
var intBuff = _buffer[_readPos..(_readPos + 4)];
54-
if (_isLittleEndian) intBuff = intBuff.Reverse().ToArray();
54+
if (_isLittleEndian) intBuff = intBuff.Reverse().ToArray();
5555
#if NET461_OR_GREATER || NETSTANDARD2_0
5656
var intValue = BitConverter.ToInt32(intBuff,0);
5757
#else
@@ -65,8 +65,8 @@ public int GetInt()
6565
public long GetLong()
6666
{
6767
var longBuff = _buffer[_readPos..(_readPos + 8)];
68-
69-
if (_isLittleEndian) longBuff = longBuff.Reverse().ToArray();
68+
69+
if (_isLittleEndian) longBuff = longBuff.Reverse().ToArray();
7070
#if NET461_OR_GREATER || NETSTANDARD2_0
7171
var longValue = BitConverter.ToInt64(longBuff,0);
7272
#else
@@ -80,8 +80,8 @@ public long GetLong()
8080
public float GetFloat()
8181
{
8282
var floatBuff = _buffer[_readPos..(_readPos + 4)];
83-
84-
if (_isLittleEndian) floatBuff = floatBuff.Reverse().ToArray();
83+
84+
if (_isLittleEndian) floatBuff = floatBuff.Reverse().ToArray();
8585
#if NET461_OR_GREATER || NETSTANDARD2_0
8686
var floatValue = BitConverter.ToSingle(floatBuff,0);
8787
#else
@@ -94,8 +94,8 @@ public float GetFloat()
9494
public double GetDouble()
9595
{
9696
var doubleBuff = _buffer[_readPos..(_readPos + 8)];
97-
98-
if (_isLittleEndian) doubleBuff = doubleBuff.Reverse().ToArray();
97+
98+
if (_isLittleEndian) doubleBuff = doubleBuff.Reverse().ToArray();
9999
#if NET461_OR_GREATER || NETSTANDARD2_0
100100
var doubleValue = BitConverter.ToDouble(doubleBuff,0);
101101
#else
@@ -135,7 +135,7 @@ private void ExtendBuffer(int spaceNeed)
135135
public void AddBool(bool value)
136136
{
137137
var boolBuffer = BitConverter.GetBytes(value);
138-
138+
139139
if (_isLittleEndian) boolBuffer = boolBuffer.Reverse().ToArray();
140140

141141
ExtendBuffer(boolBuffer.Length);
@@ -146,7 +146,7 @@ public void AddBool(bool value)
146146
public void AddInt(int value)
147147
{
148148
var intBuff = BitConverter.GetBytes(value);
149-
149+
150150
if (_isLittleEndian) intBuff = intBuff.Reverse().ToArray();
151151

152152
ExtendBuffer(intBuff.Length);
@@ -157,7 +157,7 @@ public void AddInt(int value)
157157
public void AddLong(long value)
158158
{
159159
var longBuff = BitConverter.GetBytes(value);
160-
160+
161161
if (_isLittleEndian) longBuff = longBuff.Reverse().ToArray();
162162

163163
ExtendBuffer(longBuff.Length);
@@ -168,7 +168,7 @@ public void AddLong(long value)
168168
public void AddFloat(float value)
169169
{
170170
var floatBuff = BitConverter.GetBytes(value);
171-
171+
172172
if (_isLittleEndian) floatBuff = floatBuff.Reverse().ToArray();
173173

174174
ExtendBuffer(floatBuff.Length);
@@ -179,7 +179,7 @@ public void AddFloat(float value)
179179
public void AddDouble(double value)
180180
{
181181
var doubleBuff = BitConverter.GetBytes(value);
182-
182+
183183
if (_isLittleEndian) doubleBuff = doubleBuff.Reverse().ToArray();
184184

185185
ExtendBuffer(doubleBuff.Length);
@@ -189,10 +189,10 @@ public void AddDouble(double value)
189189

190190
public void AddStr(string value)
191191
{
192-
AddInt(value.Length);
193-
194192
var strBuf = Encoding.UTF8.GetBytes(value);
195193

194+
AddInt(strBuf.Length);
195+
196196
ExtendBuffer(strBuf.Length);
197197
strBuf.CopyTo(_buffer, _writePos);
198198
_writePos += strBuf.Length;
@@ -201,14 +201,15 @@ public void AddStr(string value)
201201
public void AddChar(char value)
202202
{
203203
var charBuf = BitConverter.GetBytes(value);
204-
204+
205205
if (_isLittleEndian) charBuf = charBuf.Reverse().ToArray();
206206

207207
ExtendBuffer(charBuf.Length);
208208
charBuf.CopyTo(_buffer, _writePos);
209209
_writePos += charBuf.Length;
210210
}
211-
public void AddByte(byte value){
211+
public void AddByte(byte value)
212+
{
212213
ExtendBuffer(1);
213214
_buffer[_writePos] = value;
214215
_writePos += 1;

0 commit comments

Comments
 (0)