Skip to content

Commit f494ac2

Browse files
authored
ByteBuffer: replace LINQ reversals with Array.Reverse for compatibility (#41)
1 parent bbf0506 commit f494ac2

File tree

2 files changed

+51
-19
lines changed

2 files changed

+51
-19
lines changed

.github/workflows/pre-commit-format.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ on:
44
workflow_dispatch:
55
pull_request:
66
branches:
7-
- '**'
7+
- "**"
88
merge_group:
9-
branches: [ main ]
9+
branches: [main]
1010
# schedule:
1111
# - cron: "0 0 * * *"
1212

@@ -17,19 +17,22 @@ concurrency:
1717
jobs:
1818
formatting-checks:
1919
runs-on: ubuntu-22.04
20+
env:
21+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
22+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
2023

2124
steps:
2225
- uses: actions/checkout@v4
2326

2427
- name: Setup dotnet
2528
uses: actions/setup-dotnet@v4
2629
with:
27-
dotnet-version: '9.0.x'
30+
dotnet-version: "9.0.x"
2831

2932
- name: Setup Python environment (for pre-commit)
3033
uses: actions/setup-python@v5
3134
with:
32-
python-version: '3.10'
35+
python-version: "3.10"
3336

3437
- name: Clean dotnet temporary folder
3538
run: |

src/Apache.IoTDB/DataStructure/ByteBuffer.cs

Lines changed: 44 additions & 15 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
@@ -85,9 +87,12 @@ public long GetLong()
8587
{
8688
var longBuff = _buffer[_readPos..(_readPos + 8)];
8789

88-
if (_isLittleEndian) longBuff = longBuff.Reverse().ToArray();
90+
if (_isLittleEndian)
91+
{
92+
Array.Reverse(longBuff);
93+
}
8994
#if NET461_OR_GREATER || NETSTANDARD2_0
90-
var longValue = BitConverter.ToInt64(longBuff,0);
95+
var longValue = BitConverter.ToInt64(longBuff, 0);
9196
#else
9297
var longValue = BitConverter.ToInt64(longBuff);
9398
#endif
@@ -100,9 +105,12 @@ public float GetFloat()
100105
{
101106
var floatBuff = _buffer[_readPos..(_readPos + 4)];
102107

103-
if (_isLittleEndian) floatBuff = floatBuff.Reverse().ToArray();
108+
if (_isLittleEndian)
109+
{
110+
Array.Reverse(floatBuff);
111+
}
104112
#if NET461_OR_GREATER || NETSTANDARD2_0
105-
var floatValue = BitConverter.ToSingle(floatBuff,0);
113+
var floatValue = BitConverter.ToSingle(floatBuff, 0);
106114
#else
107115
var floatValue = BitConverter.ToSingle(floatBuff);
108116
#endif
@@ -114,9 +122,12 @@ public double GetDouble()
114122
{
115123
var doubleBuff = _buffer[_readPos..(_readPos + 8)];
116124

117-
if (_isLittleEndian) doubleBuff = doubleBuff.Reverse().ToArray();
125+
if (_isLittleEndian)
126+
{
127+
Array.Reverse(doubleBuff);
128+
}
118129
#if NET461_OR_GREATER || NETSTANDARD2_0
119-
var doubleValue = BitConverter.ToDouble(doubleBuff,0);
130+
var doubleValue = BitConverter.ToDouble(doubleBuff, 0);
120131
#else
121132
var doubleValue = BitConverter.ToDouble(doubleBuff);
122133
#endif
@@ -173,7 +184,10 @@ public void AddBool(bool value)
173184
{
174185
var boolBuffer = BitConverter.GetBytes(value);
175186

176-
if (_isLittleEndian) boolBuffer = boolBuffer.Reverse().ToArray();
187+
if (_isLittleEndian)
188+
{
189+
Array.Reverse(boolBuffer);
190+
}
177191

178192
ExtendBuffer(boolBuffer.Length);
179193
boolBuffer.CopyTo(_buffer, _writePos);
@@ -184,7 +198,10 @@ public void AddInt(int value)
184198
{
185199
var intBuff = BitConverter.GetBytes(value);
186200

187-
if (_isLittleEndian) intBuff = intBuff.Reverse().ToArray();
201+
if (_isLittleEndian)
202+
{
203+
Array.Reverse(intBuff);
204+
}
188205

189206
ExtendBuffer(intBuff.Length);
190207
intBuff.CopyTo(_buffer, _writePos);
@@ -195,7 +212,10 @@ public void AddLong(long value)
195212
{
196213
var longBuff = BitConverter.GetBytes(value);
197214

198-
if (_isLittleEndian) longBuff = longBuff.Reverse().ToArray();
215+
if (_isLittleEndian)
216+
{
217+
Array.Reverse(longBuff);
218+
}
199219

200220
ExtendBuffer(longBuff.Length);
201221
longBuff.CopyTo(_buffer, _writePos);
@@ -206,7 +226,10 @@ public void AddFloat(float value)
206226
{
207227
var floatBuff = BitConverter.GetBytes(value);
208228

209-
if (_isLittleEndian) floatBuff = floatBuff.Reverse().ToArray();
229+
if (_isLittleEndian)
230+
{
231+
Array.Reverse(floatBuff);
232+
}
210233

211234
ExtendBuffer(floatBuff.Length);
212235
floatBuff.CopyTo(_buffer, _writePos);
@@ -217,7 +240,10 @@ public void AddDouble(double value)
217240
{
218241
var doubleBuff = BitConverter.GetBytes(value);
219242

220-
if (_isLittleEndian) doubleBuff = doubleBuff.Reverse().ToArray();
243+
if (_isLittleEndian)
244+
{
245+
Array.Reverse(doubleBuff);
246+
}
221247

222248
ExtendBuffer(doubleBuff.Length);
223249
doubleBuff.CopyTo(_buffer, _writePos);
@@ -248,7 +274,10 @@ public void AddChar(char value)
248274
{
249275
var charBuf = BitConverter.GetBytes(value);
250276

251-
if (_isLittleEndian) charBuf = charBuf.Reverse().ToArray();
277+
if (_isLittleEndian)
278+
{
279+
Array.Reverse(charBuf);
280+
}
252281

253282
ExtendBuffer(charBuf.Length);
254283
charBuf.CopyTo(_buffer, _writePos);

0 commit comments

Comments
 (0)