Skip to content

Commit 4a78ff8

Browse files
committed
fix ByteBuffer build error ,use Array.Reverse()
1 parent 5b0e6bf commit 4a78ff8

File tree

1 file changed

+44
-24
lines changed

1 file changed

+44
-24
lines changed

src/Apache.IoTDB/DataStructure/ByteBuffer.cs

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919

2020
using System;
21-
using System.Linq;
2221
using System.Text;
2322

2423
namespace Apache.IoTDB.DataStructure
@@ -70,9 +69,12 @@ public bool GetBool()
7069
public int GetInt()
7170
{
7271
var intBuff = _buffer[_readPos..(_readPos + 4)];
73-
if (_isLittleEndian) intBuff = intBuff.Reverse().ToArray();
72+
if (_isLittleEndian)
73+
{
74+
Array.Reverse(intBuff);
75+
}
7476
#if NET461_OR_GREATER || NETSTANDARD2_0
75-
var intValue = BitConverter.ToInt32(intBuff,0);
77+
var intValue = BitConverter.ToInt32(intBuff, 0);
7678
#else
7779
var intValue = BitConverter.ToInt32(intBuff);
7880
#endif
@@ -84,10 +86,12 @@ public int GetInt()
8486
public long GetLong()
8587
{
8688
var longBuff = _buffer[_readPos..(_readPos + 8)];
87-
88-
if (_isLittleEndian) longBuff = longBuff.Reverse().ToArray();
89+
if (_isLittleEndian)
90+
{
91+
Array.Reverse(longBuff);
92+
}
8993
#if NET461_OR_GREATER || NETSTANDARD2_0
90-
var longValue = BitConverter.ToInt64(longBuff,0);
94+
var longValue = BitConverter.ToInt64(longBuff, 0);
9195
#else
9296
var longValue = BitConverter.ToInt64(longBuff);
9397
#endif
@@ -99,10 +103,12 @@ public long GetLong()
99103
public float GetFloat()
100104
{
101105
var floatBuff = _buffer[_readPos..(_readPos + 4)];
102-
103-
if (_isLittleEndian) floatBuff = floatBuff.Reverse().ToArray();
106+
if (_isLittleEndian)
107+
{
108+
Array.Reverse(floatBuff);
109+
}
104110
#if NET461_OR_GREATER || NETSTANDARD2_0
105-
var floatValue = BitConverter.ToSingle(floatBuff,0);
111+
var floatValue = BitConverter.ToSingle(floatBuff, 0);
106112
#else
107113
var floatValue = BitConverter.ToSingle(floatBuff);
108114
#endif
@@ -113,10 +119,12 @@ public float GetFloat()
113119
public double GetDouble()
114120
{
115121
var doubleBuff = _buffer[_readPos..(_readPos + 8)];
116-
117-
if (_isLittleEndian) doubleBuff = doubleBuff.Reverse().ToArray();
122+
if (_isLittleEndian)
123+
{
124+
Array.Reverse(doubleBuff);
125+
}
118126
#if NET461_OR_GREATER || NETSTANDARD2_0
119-
var doubleValue = BitConverter.ToDouble(doubleBuff,0);
127+
var doubleValue = BitConverter.ToDouble(doubleBuff, 0);
120128
#else
121129
var doubleValue = BitConverter.ToDouble(doubleBuff);
122130
#endif
@@ -162,8 +170,10 @@ private void ExtendBuffer(int spaceNeed)
162170
public void AddBool(bool value)
163171
{
164172
var boolBuffer = BitConverter.GetBytes(value);
165-
166-
if (_isLittleEndian) boolBuffer = boolBuffer.Reverse().ToArray();
173+
if (_isLittleEndian)
174+
{
175+
Array.Reverse(boolBuffer);
176+
}
167177

168178
ExtendBuffer(boolBuffer.Length);
169179
boolBuffer.CopyTo(_buffer, _writePos);
@@ -173,8 +183,10 @@ public void AddBool(bool value)
173183
public void AddInt(int value)
174184
{
175185
var intBuff = BitConverter.GetBytes(value);
176-
177-
if (_isLittleEndian) intBuff = intBuff.Reverse().ToArray();
186+
if (_isLittleEndian)
187+
{
188+
Array.Reverse(intBuff);
189+
}
178190

179191
ExtendBuffer(intBuff.Length);
180192
intBuff.CopyTo(_buffer, _writePos);
@@ -184,8 +196,10 @@ public void AddInt(int value)
184196
public void AddLong(long value)
185197
{
186198
var longBuff = BitConverter.GetBytes(value);
187-
188-
if (_isLittleEndian) longBuff = longBuff.Reverse().ToArray();
199+
if (_isLittleEndian)
200+
{
201+
Array.Reverse(longBuff);
202+
}
189203

190204
ExtendBuffer(longBuff.Length);
191205
longBuff.CopyTo(_buffer, _writePos);
@@ -195,8 +209,10 @@ public void AddLong(long value)
195209
public void AddFloat(float value)
196210
{
197211
var floatBuff = BitConverter.GetBytes(value);
198-
199-
if (_isLittleEndian) floatBuff = floatBuff.Reverse().ToArray();
212+
if (_isLittleEndian)
213+
{
214+
Array.Reverse(floatBuff);
215+
}
200216

201217
ExtendBuffer(floatBuff.Length);
202218
floatBuff.CopyTo(_buffer, _writePos);
@@ -206,8 +222,10 @@ public void AddFloat(float value)
206222
public void AddDouble(double value)
207223
{
208224
var doubleBuff = BitConverter.GetBytes(value);
209-
210-
if (_isLittleEndian) doubleBuff = doubleBuff.Reverse().ToArray();
225+
if (_isLittleEndian)
226+
{
227+
Array.Reverse(doubleBuff);
228+
}
211229

212230
ExtendBuffer(doubleBuff.Length);
213231
doubleBuff.CopyTo(_buffer, _writePos);
@@ -237,8 +255,10 @@ public void AddBinary(byte[] value)
237255
public void AddChar(char value)
238256
{
239257
var charBuf = BitConverter.GetBytes(value);
240-
241-
if (_isLittleEndian) charBuf = charBuf.Reverse().ToArray();
258+
if (_isLittleEndian)
259+
{
260+
Array.Reverse(charBuf);
261+
}
242262

243263
ExtendBuffer(charBuf.Length);
244264
charBuf.CopyTo(_buffer, _writePos);

0 commit comments

Comments
 (0)