< Summary

Information
Class: Ice.Internal.ByteBuffer
Assembly: Ice
File(s): /home/runner/work/ice/ice/csharp/src/Ice/Internal/ByteBuffer.cs
Tag: 71_18251537082
Line coverage
63%
Covered lines: 273
Uncovered lines: 156
Coverable lines: 429
Total lines: 853
Line coverage: 63.6%
Branch coverage
41%
Covered branches: 43
Total branches: 104
Branch coverage: 41.3%
Method coverage
87%
Covered methods: 54
Total methods: 62
Method coverage: 87%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
nativeOrder()100%210%
allocate(...)50%2.01288.89%
wrap(...)100%11100%
.ctor()100%11100%
order()100%11100%
order(...)100%11100%
position()100%11100%
position(...)50%4.59466.67%
limit()100%11100%
limit(...)50%4.59466.67%
clear()100%210%
flip()100%11100%
compact()50%2.01285.71%
remaining()100%11100%
hasRemaining()100%11100%
capacity()100%11100%
toArray()100%210%
toArray(...)0%7280%
put(...)100%11100%
get()100%11100%
get(...)100%11100%
get(...)100%11100%
get(...)50%4.25475%
put(...)100%11100%
put(...)100%11100%
put(...)100%11100%
put(...)66.67%6.39677.78%
getBool()100%210%
getBoolSeq(...)100%11100%
putBool(...)100%11100%
putBoolSeq(...)100%11100%
getShort()100%11100%
getShort(...)100%22100%
getShortSeq(...)25%5.5454.55%
putShort(...)100%22100%
putShortSeq(...)25%5.5454.55%
getInt()50%2.15266.67%
getIntSeq(...)25%6.5446.15%
putInt(...)100%11100%
putInt(...)50%8.3660%
putIntSeq(...)25%6.5446.15%
getLong()100%11100%
getLong(...)100%22100%
getLongSeq(...)25%8.34435.29%
putLong(...)100%22100%
putLongSeq(...)25%8.34435.29%
getFloat()50%2.15266.67%
getFloatSeq(...)25%6.5446.15%
putFloat(...)50%2.12269.23%
putFloatSeq(...)25%6.5446.15%
getDouble()50%2.26260%
getDoubleSeq(...)25%8.34435.29%
putDouble(...)50%2.22261.9%
putDoubleSeq(...)25%8.34435.29%
rawBytes()100%11100%
rawBytes(...)0%620%
checkUnderflow(...)100%22100%
checkUnderflow(...)50%2.15266.67%
checkOverflow(...)50%2.15266.67%
.cctor()50%22100%
.ctor()100%210%
throwOutOfRange(...)100%210%

File(s)

/home/runner/work/ice/ice/csharp/src/Ice/Internal/ByteBuffer.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using System.Runtime.InteropServices;
 4
 5namespace Ice.Internal;
 6
 7public class ByteBuffer
 8{
 09    public static ByteOrder nativeOrder() => NativeOrder._o;
 10
 11    public static ByteBuffer allocate(int capacity)
 12    {
 113        if (capacity < 0)
 14        {
 015            throwOutOfRange("capacity", capacity, "capacity must be non-negative");
 16        }
 117        var ret = new ByteBuffer();
 118        ret._position = 0;
 119        ret._limit = capacity;
 120        ret._capacity = capacity;
 121        ret._bytes = new byte[capacity];
 122        ret._valBytes = new ValBytes();
 123        return ret;
 24    }
 25
 26    public static ByteBuffer wrap(byte[] bytes)
 27    {
 128        var ret = new ByteBuffer();
 129        ret._position = 0;
 130        ret._limit = bytes.Length;
 131        ret._capacity = bytes.Length;
 132        ret._bytes = bytes;
 133        ret._valBytes = new ValBytes();
 134        return ret;
 35    }
 36
 137    public ByteBuffer() => _order = ByteOrder.BigEndian;
 38
 39    /// <summary>
 40    /// Represents the endianness of the buffer.
 41    /// </summary>
 42    public enum ByteOrder
 43    {
 44        /// <summary>
 45        /// Big endian byte order.
 46        /// </summary>
 47        BigEndian,
 48
 49        /// <summary>
 50        /// Little endian byte order.
 51        /// </summary>
 52        LittleEndian
 53    }
 54
 155    public ByteOrder order() => _order;
 56
 57    public ByteBuffer order(ByteOrder bo)
 58    {
 159        _order = bo;
 160        return this;
 61    }
 62
 163    public int position() => _position;
 64
 65    public ByteBuffer position(int pos)
 66    {
 167        if (pos < 0)
 68        {
 069            throwOutOfRange("pos", pos, "position must be non-negative");
 70        }
 171        if (pos > _limit)
 72        {
 073            throwOutOfRange("pos", pos, "position must be less than limit");
 74        }
 175        _position = pos;
 176        return this;
 77    }
 78
 179    public int limit() => _limit;
 80
 81    public ByteBuffer limit(int newLimit)
 82    {
 183        if (newLimit < 0)
 84        {
 085            throwOutOfRange("newLimit", newLimit, "limit must be non-negative");
 86        }
 187        if (newLimit > _capacity)
 88        {
 089            throwOutOfRange("newLimit", newLimit, "limit must be less than capacity");
 90        }
 191        _limit = newLimit;
 192        return this;
 93    }
 94
 95    public void clear()
 96    {
 097        _position = 0;
 098        _limit = _capacity;
 099    }
 100
 101    public void flip()
 102    {
 1103        _limit = _position;
 1104        _position = 0;
 1105    }
 106
 107    public void compact()
 108    {
 1109        if (_position < _limit)
 110        {
 1111            int n = _limit - _position;
 1112            System.Buffer.BlockCopy(_bytes, _position, _bytes, 0, n);
 1113            _position = n;
 114        }
 115        else
 116        {
 0117            _position = 0;
 118        }
 1119        _limit = _capacity;
 1120    }
 121
 1122    public int remaining() => _limit - _position;
 123
 1124    public bool hasRemaining() => _position < _limit;
 125
 1126    public int capacity() => _capacity;
 127
 128    public byte[] toArray()
 129    {
 0130        int len = remaining();
 0131        byte[] rc = new byte[len];
 0132        System.Buffer.BlockCopy(_bytes, 0, rc, 0, len);
 0133        return rc;
 134    }
 135
 136    public byte[] toArray(int startIndex, int length)
 137    {
 0138        if (startIndex < 0)
 139        {
 0140            throwOutOfRange("startIndex", startIndex, "startIndex must be non-negative");
 141        }
 0142        if (startIndex >= _position)
 143        {
 0144            throwOutOfRange("startIndex", startIndex, "startIndex must be less than position");
 145        }
 0146        if (length < 0)
 147        {
 0148            throwOutOfRange("length", length, "length must be non-negative");
 149        }
 0150        if (startIndex + length > _position)
 151        {
 0152            throw new ArgumentException("startIndex + length must not exceed end mark of buffer");
 153        }
 0154        byte[] rc = new byte[length];
 0155        System.Buffer.BlockCopy(_bytes, startIndex, rc, 0, length);
 0156        return rc;
 157    }
 158
 159    public ByteBuffer put(ByteBuffer buf)
 160    {
 1161        int len = buf.remaining();
 1162        checkOverflow(len);
 1163        System.Buffer.BlockCopy(buf._bytes, buf._position, _bytes, _position, len);
 1164        _position += len;
 1165        return this;
 166    }
 167
 168    public byte get()
 169    {
 1170        checkUnderflow(1);
 1171        return System.Buffer.GetByte(_bytes, _position++);
 172    }
 173
 1174    public byte get(int pos) => System.Buffer.GetByte(_bytes, pos);
 175
 1176    public ByteBuffer get(byte[] b) => get(b, 0, System.Buffer.ByteLength(b));
 177
 178    public ByteBuffer get(byte[] b, int offset, int length)
 179    {
 1180        if (offset < 0)
 181        {
 0182            throwOutOfRange("offset", offset, "offset must be non-negative");
 183        }
 1184        if (offset + length > System.Buffer.ByteLength(b))
 185        {
 0186            throwOutOfRange("length", length, "insufficient room beyond given offset in destination array");
 187        }
 1188        checkUnderflow(length);
 1189        System.Buffer.BlockCopy(_bytes, _position, b, offset, length);
 1190        _position += length;
 1191        return this;
 192    }
 193
 194    public ByteBuffer put(byte b)
 195    {
 1196        checkOverflow(1);
 1197        _bytes[_position++] = b;
 1198        return this;
 199    }
 200
 201    public ByteBuffer put(int pos, byte b)
 202    {
 1203        _bytes[pos] = b;
 1204        return this;
 205    }
 206
 1207    public ByteBuffer put(byte[] b) => put(b, 0, System.Buffer.ByteLength(b));
 208
 209    public ByteBuffer put(byte[] b, int offset, int length)
 210    {
 1211        if (offset < 0)
 212        {
 0213            throwOutOfRange("offset", offset, "offset must be non-negative");
 214        }
 1215        if (offset + length > System.Buffer.ByteLength(b))
 216        {
 0217            throwOutOfRange("length", length, "insufficient data beyond given offset in source array");
 218        }
 1219        if (length > 0)
 220        {
 1221            checkOverflow(length);
 1222            System.Buffer.BlockCopy(b, offset, _bytes, _position, length);
 1223            _position += length;
 224        }
 1225        return this;
 226    }
 227
 0228    public bool getBool() => get() == 1;
 229
 230    public void getBoolSeq(bool[] seq)
 231    {
 1232        int len = System.Buffer.ByteLength(seq);
 1233        checkUnderflow(len);
 1234        System.Buffer.BlockCopy(_bytes, _position, seq, 0, len);
 1235        _position += len;
 1236    }
 237
 1238    public ByteBuffer putBool(bool b) => put(b ? (byte)1 : (byte)0);
 239
 240    public ByteBuffer putBoolSeq(bool[] seq)
 241    {
 1242        int len = System.Buffer.ByteLength(seq);
 1243        checkOverflow(len);
 1244        System.Buffer.BlockCopy(seq, 0, _bytes, _position, len);
 1245        _position += len;
 1246        return this;
 247    }
 248
 249    [StructLayout(LayoutKind.Explicit)]
 250    private struct ValBytes
 251    {
 252        [FieldOffset(0)]
 253        public short shortVal;
 254
 255        [FieldOffset(0)]
 256        public int intVal;
 257
 258        [FieldOffset(0)]
 259        public long longVal;
 260
 261        [FieldOffset(0)]
 262        public float floatVal;
 263
 264        [FieldOffset(0)]
 265        public double doubleVal;
 266
 267        [FieldOffset(0)]
 268        public byte b0;
 269        [FieldOffset(1)]
 270        public byte b1;
 271        [FieldOffset(2)]
 272        public byte b2;
 273        [FieldOffset(3)]
 274        public byte b3;
 275        [FieldOffset(4)]
 276        public byte b4;
 277        [FieldOffset(5)]
 278        public byte b5;
 279        [FieldOffset(6)]
 280        public byte b6;
 281        [FieldOffset(7)]
 282        public byte b7;
 283    }
 284
 285    public short getShort()
 286    {
 1287        short v = getShort(_position);
 1288        _position += 2;
 1289        return v;
 290    }
 291
 292    public short getShort(int pos)
 293    {
 1294        checkUnderflow(pos, 2);
 1295        if (_order == NativeOrder._o)
 296        {
 1297            _valBytes.b0 = _bytes[pos];
 1298            _valBytes.b1 = _bytes[pos + 1];
 299        }
 300        else
 301        {
 1302            _valBytes.b1 = _bytes[pos];
 1303            _valBytes.b0 = _bytes[pos + 1];
 304        }
 1305        return _valBytes.shortVal;
 306    }
 307
 308    public void getShortSeq(short[] seq)
 309    {
 1310        int len = System.Buffer.ByteLength(seq);
 1311        checkUnderflow(len);
 1312        if (_order == NativeOrder._o)
 313        {
 1314            System.Buffer.BlockCopy(_bytes, _position, seq, 0, len);
 315        }
 316        else
 317        {
 0318            for (int i = 0; i < seq.Length; ++i)
 319            {
 0320                int index = _position + (i * 2);
 0321                _valBytes.b1 = _bytes[index];
 0322                _valBytes.b0 = _bytes[index + 1];
 0323                seq[i] = _valBytes.shortVal;
 324            }
 325        }
 1326        _position += len;
 1327    }
 328
 329    public ByteBuffer putShort(short val)
 330    {
 1331        checkOverflow(2);
 1332        _valBytes.shortVal = val;
 1333        if (_order == NativeOrder._o)
 334        {
 1335            _bytes[_position] = _valBytes.b0;
 1336            _bytes[_position + 1] = _valBytes.b1;
 337        }
 338        else
 339        {
 1340            _bytes[_position + 1] = _valBytes.b0;
 1341            _bytes[_position] = _valBytes.b1;
 342        }
 1343        _position += 2;
 1344        return this;
 345    }
 346
 347    public ByteBuffer putShortSeq(short[] seq)
 348    {
 1349        int len = System.Buffer.ByteLength(seq);
 1350        checkOverflow(len);
 1351        if (_order == NativeOrder._o)
 352        {
 1353            System.Buffer.BlockCopy(seq, 0, _bytes, _position, len);
 354        }
 355        else
 356        {
 0357            for (int i = 0; i < seq.Length; ++i)
 358            {
 0359                int index = _position + (i * 2);
 0360                _valBytes.shortVal = seq[i];
 0361                _bytes[index + 1] = _valBytes.b0;
 0362                _bytes[index] = _valBytes.b1;
 363            }
 364        }
 1365        _position += len;
 1366        return this;
 367    }
 368
 369    public int getInt()
 370    {
 1371        checkUnderflow(4);
 1372        if (_order == NativeOrder._o)
 373        {
 1374            _valBytes.b0 = _bytes[_position];
 1375            _valBytes.b1 = _bytes[_position + 1];
 1376            _valBytes.b2 = _bytes[_position + 2];
 1377            _valBytes.b3 = _bytes[_position + 3];
 378        }
 379        else
 380        {
 0381            _valBytes.b3 = _bytes[_position];
 0382            _valBytes.b2 = _bytes[_position + 1];
 0383            _valBytes.b1 = _bytes[_position + 2];
 0384            _valBytes.b0 = _bytes[_position + 3];
 385        }
 1386        _position += 4;
 1387        return _valBytes.intVal;
 388    }
 389
 390    public void getIntSeq(int[] seq)
 391    {
 1392        int len = System.Buffer.ByteLength(seq);
 1393        checkUnderflow(len);
 1394        if (_order == NativeOrder._o)
 395        {
 1396            System.Buffer.BlockCopy(_bytes, _position, seq, 0, len);
 397        }
 398        else
 399        {
 0400            for (int i = 0; i < seq.Length; ++i)
 401            {
 0402                int index = _position + (i * 4);
 0403                _valBytes.b3 = _bytes[index];
 0404                _valBytes.b2 = _bytes[index + 1];
 0405                _valBytes.b1 = _bytes[index + 2];
 0406                _valBytes.b0 = _bytes[index + 3];
 0407                seq[i] = _valBytes.intVal;
 408            }
 409        }
 1410        _position += len;
 1411    }
 412
 413    public ByteBuffer putInt(int val)
 414    {
 1415        putInt(_position, val);
 1416        _position += 4;
 1417        return this;
 418    }
 419
 420    public ByteBuffer putInt(int pos, int val)
 421    {
 1422        if (pos < 0)
 423        {
 0424            throwOutOfRange("pos", pos, "position must be non-negative");
 425        }
 1426        if (pos + 4 > _limit)
 427        {
 0428            throwOutOfRange("pos", pos, "position must be less than limit - 4");
 429        }
 1430        _valBytes.intVal = val;
 1431        if (_order == NativeOrder._o)
 432        {
 1433            _bytes[pos] = _valBytes.b0;
 1434            _bytes[pos + 1] = _valBytes.b1;
 1435            _bytes[pos + 2] = _valBytes.b2;
 1436            _bytes[pos + 3] = _valBytes.b3;
 437        }
 438        else
 439        {
 0440            _bytes[pos + 3] = _valBytes.b0;
 0441            _bytes[pos + 2] = _valBytes.b1;
 0442            _bytes[pos + 1] = _valBytes.b2;
 0443            _bytes[pos] = _valBytes.b3;
 444        }
 1445        return this;
 446    }
 447
 448    public ByteBuffer putIntSeq(int[] seq)
 449    {
 1450        int len = System.Buffer.ByteLength(seq);
 1451        checkOverflow(len);
 1452        if (_order == NativeOrder._o)
 453        {
 1454            System.Buffer.BlockCopy(seq, 0, _bytes, _position, len);
 455        }
 456        else
 457        {
 0458            for (int i = 0; i < seq.Length; ++i)
 459            {
 0460                int index = _position + (i * 4);
 0461                _valBytes.intVal = seq[i];
 0462                _bytes[index + 3] = _valBytes.b0;
 0463                _bytes[index + 2] = _valBytes.b1;
 0464                _bytes[index + 1] = _valBytes.b2;
 0465                _bytes[index] = _valBytes.b3;
 466            }
 467        }
 1468        _position += len;
 1469        return this;
 470    }
 471
 472    public long getLong()
 473    {
 1474        long v = getLong(_position);
 1475        _position += 8;
 1476        return v;
 477    }
 478
 479    public long getLong(int pos)
 480    {
 1481        checkUnderflow(pos, 8);
 1482        if (_order == NativeOrder._o)
 483        {
 1484            _valBytes.b0 = _bytes[pos];
 1485            _valBytes.b1 = _bytes[pos + 1];
 1486            _valBytes.b2 = _bytes[pos + 2];
 1487            _valBytes.b3 = _bytes[pos + 3];
 1488            _valBytes.b4 = _bytes[pos + 4];
 1489            _valBytes.b5 = _bytes[pos + 5];
 1490            _valBytes.b6 = _bytes[pos + 6];
 1491            _valBytes.b7 = _bytes[pos + 7];
 492        }
 493        else
 494        {
 1495            _valBytes.b7 = _bytes[pos];
 1496            _valBytes.b6 = _bytes[pos + 1];
 1497            _valBytes.b5 = _bytes[pos + 2];
 1498            _valBytes.b4 = _bytes[pos + 3];
 1499            _valBytes.b3 = _bytes[pos + 4];
 1500            _valBytes.b2 = _bytes[pos + 5];
 1501            _valBytes.b1 = _bytes[pos + 6];
 1502            _valBytes.b0 = _bytes[pos + 7];
 503        }
 1504        return _valBytes.longVal;
 505    }
 506
 507    public void getLongSeq(long[] seq)
 508    {
 1509        int len = System.Buffer.ByteLength(seq);
 1510        checkUnderflow(len);
 1511        if (_order == NativeOrder._o)
 512        {
 1513            System.Buffer.BlockCopy(_bytes, _position, seq, 0, len);
 514        }
 515        else
 516        {
 0517            for (int i = 0; i < seq.Length; ++i)
 518            {
 0519                int index = _position + (i * 8);
 0520                _valBytes.b7 = _bytes[index];
 0521                _valBytes.b6 = _bytes[index + 1];
 0522                _valBytes.b5 = _bytes[index + 2];
 0523                _valBytes.b4 = _bytes[index + 3];
 0524                _valBytes.b3 = _bytes[index + 4];
 0525                _valBytes.b2 = _bytes[index + 5];
 0526                _valBytes.b1 = _bytes[index + 6];
 0527                _valBytes.b0 = _bytes[index + 7];
 0528                seq[i] = _valBytes.longVal;
 529            }
 530        }
 1531        _position += len;
 1532    }
 533
 534    public ByteBuffer putLong(long val)
 535    {
 1536        checkOverflow(8);
 1537        _valBytes.longVal = val;
 1538        if (_order == NativeOrder._o)
 539        {
 1540            _bytes[_position] = _valBytes.b0;
 1541            _bytes[_position + 1] = _valBytes.b1;
 1542            _bytes[_position + 2] = _valBytes.b2;
 1543            _bytes[_position + 3] = _valBytes.b3;
 1544            _bytes[_position + 4] = _valBytes.b4;
 1545            _bytes[_position + 5] = _valBytes.b5;
 1546            _bytes[_position + 6] = _valBytes.b6;
 1547            _bytes[_position + 7] = _valBytes.b7;
 548        }
 549        else
 550        {
 1551            _bytes[_position + 7] = _valBytes.b0;
 1552            _bytes[_position + 6] = _valBytes.b1;
 1553            _bytes[_position + 5] = _valBytes.b2;
 1554            _bytes[_position + 4] = _valBytes.b3;
 1555            _bytes[_position + 3] = _valBytes.b4;
 1556            _bytes[_position + 2] = _valBytes.b5;
 1557            _bytes[_position + 1] = _valBytes.b6;
 1558            _bytes[_position] = _valBytes.b7;
 559        }
 1560        _position += 8;
 1561        return this;
 562    }
 563
 564    public ByteBuffer putLongSeq(long[] seq)
 565    {
 1566        int len = System.Buffer.ByteLength(seq);
 1567        checkOverflow(len);
 1568        if (_order == NativeOrder._o)
 569        {
 1570            System.Buffer.BlockCopy(seq, 0, _bytes, _position, len);
 571        }
 572        else
 573        {
 0574            for (int i = 0; i < seq.Length; ++i)
 575            {
 0576                int index = _position + (i * 8);
 0577                _valBytes.longVal = seq[i];
 0578                _bytes[index + 7] = _valBytes.b0;
 0579                _bytes[index + 6] = _valBytes.b1;
 0580                _bytes[index + 5] = _valBytes.b2;
 0581                _bytes[index + 4] = _valBytes.b3;
 0582                _bytes[index + 3] = _valBytes.b4;
 0583                _bytes[index + 2] = _valBytes.b5;
 0584                _bytes[index + 1] = _valBytes.b6;
 0585                _bytes[index] = _valBytes.b7;
 586            }
 587        }
 1588        _position += len;
 1589        return this;
 590    }
 591
 592    public float getFloat()
 593    {
 1594        checkUnderflow(4);
 1595        if (_order == NativeOrder._o)
 596        {
 1597            _valBytes.b0 = _bytes[_position];
 1598            _valBytes.b1 = _bytes[_position + 1];
 1599            _valBytes.b2 = _bytes[_position + 2];
 1600            _valBytes.b3 = _bytes[_position + 3];
 601        }
 602        else
 603        {
 0604            _valBytes.b3 = _bytes[_position];
 0605            _valBytes.b2 = _bytes[_position + 1];
 0606            _valBytes.b1 = _bytes[_position + 2];
 0607            _valBytes.b0 = _bytes[_position + 3];
 608        }
 1609        _position += 4;
 1610        return _valBytes.floatVal;
 611    }
 612
 613    public void getFloatSeq(float[] seq)
 614    {
 1615        int len = System.Buffer.ByteLength(seq);
 1616        checkUnderflow(len);
 1617        if (_order == NativeOrder._o)
 618        {
 1619            System.Buffer.BlockCopy(_bytes, _position, seq, 0, len);
 620        }
 621        else
 622        {
 0623            for (int i = 0; i < seq.Length; ++i)
 624            {
 0625                int index = _position + (i * 4);
 0626                _valBytes.b3 = _bytes[index];
 0627                _valBytes.b2 = _bytes[index + 1];
 0628                _valBytes.b1 = _bytes[index + 2];
 0629                _valBytes.b0 = _bytes[index + 3];
 0630                seq[i] = _valBytes.floatVal;
 631            }
 632        }
 1633        _position += len;
 1634    }
 635
 636    public ByteBuffer putFloat(float val)
 637    {
 1638        checkOverflow(4);
 1639        _valBytes.floatVal = val;
 1640        if (_order == NativeOrder._o)
 641        {
 1642            _bytes[_position] = _valBytes.b0;
 1643            _bytes[_position + 1] = _valBytes.b1;
 1644            _bytes[_position + 2] = _valBytes.b2;
 1645            _bytes[_position + 3] = _valBytes.b3;
 646        }
 647        else
 648        {
 0649            _bytes[_position + 3] = _valBytes.b0;
 0650            _bytes[_position + 2] = _valBytes.b1;
 0651            _bytes[_position + 1] = _valBytes.b2;
 0652            _bytes[_position] = _valBytes.b3;
 653        }
 1654        _position += 4;
 1655        return this;
 656    }
 657
 658    public ByteBuffer putFloatSeq(float[] seq)
 659    {
 1660        int len = System.Buffer.ByteLength(seq);
 1661        checkOverflow(len);
 1662        if (_order == NativeOrder._o)
 663        {
 1664            System.Buffer.BlockCopy(seq, 0, _bytes, _position, len);
 665        }
 666        else
 667        {
 0668            for (int i = 0; i < seq.Length; ++i)
 669            {
 0670                int index = _position + (i * 4);
 0671                _valBytes.floatVal = seq[i];
 0672                _bytes[index + 3] = _valBytes.b0;
 0673                _bytes[index + 2] = _valBytes.b1;
 0674                _bytes[index + 1] = _valBytes.b2;
 0675                _bytes[index] = _valBytes.b3;
 676            }
 677        }
 1678        _position += len;
 1679        return this;
 680    }
 681
 682    public double getDouble()
 683    {
 1684        checkUnderflow(8);
 1685        if (_order == NativeOrder._o)
 686        {
 1687            _valBytes.b0 = _bytes[_position];
 1688            _valBytes.b1 = _bytes[_position + 1];
 1689            _valBytes.b2 = _bytes[_position + 2];
 1690            _valBytes.b3 = _bytes[_position + 3];
 1691            _valBytes.b4 = _bytes[_position + 4];
 1692            _valBytes.b5 = _bytes[_position + 5];
 1693            _valBytes.b6 = _bytes[_position + 6];
 1694            _valBytes.b7 = _bytes[_position + 7];
 695        }
 696        else
 697        {
 0698            _valBytes.b7 = _bytes[_position];
 0699            _valBytes.b6 = _bytes[_position + 1];
 0700            _valBytes.b5 = _bytes[_position + 2];
 0701            _valBytes.b4 = _bytes[_position + 3];
 0702            _valBytes.b3 = _bytes[_position + 4];
 0703            _valBytes.b2 = _bytes[_position + 5];
 0704            _valBytes.b1 = _bytes[_position + 6];
 0705            _valBytes.b0 = _bytes[_position + 7];
 706        }
 1707        _position += 8;
 1708        return _valBytes.doubleVal;
 709    }
 710
 711    public void getDoubleSeq(double[] seq)
 712    {
 1713        int len = System.Buffer.ByteLength(seq);
 1714        checkUnderflow(len);
 1715        if (_order == NativeOrder._o)
 716        {
 1717            System.Buffer.BlockCopy(_bytes, _position, seq, 0, len);
 718        }
 719        else
 720        {
 0721            for (int i = 0; i < seq.Length; ++i)
 722            {
 0723                int index = _position + (i * 8);
 0724                _valBytes.b7 = _bytes[index];
 0725                _valBytes.b6 = _bytes[index + 1];
 0726                _valBytes.b5 = _bytes[index + 2];
 0727                _valBytes.b4 = _bytes[index + 3];
 0728                _valBytes.b3 = _bytes[index + 4];
 0729                _valBytes.b2 = _bytes[index + 5];
 0730                _valBytes.b1 = _bytes[index + 6];
 0731                _valBytes.b0 = _bytes[index + 7];
 0732                seq[i] = _valBytes.doubleVal;
 733            }
 734        }
 1735        _position += len;
 1736    }
 737
 738    public ByteBuffer putDouble(double val)
 739    {
 1740        checkOverflow(8);
 1741        _valBytes.doubleVal = val;
 1742        if (_order == NativeOrder._o)
 743        {
 1744            _bytes[_position] = _valBytes.b0;
 1745            _bytes[_position + 1] = _valBytes.b1;
 1746            _bytes[_position + 2] = _valBytes.b2;
 1747            _bytes[_position + 3] = _valBytes.b3;
 1748            _bytes[_position + 4] = _valBytes.b4;
 1749            _bytes[_position + 5] = _valBytes.b5;
 1750            _bytes[_position + 6] = _valBytes.b6;
 1751            _bytes[_position + 7] = _valBytes.b7;
 752        }
 753        else
 754        {
 0755            _bytes[_position + 7] = _valBytes.b0;
 0756            _bytes[_position + 6] = _valBytes.b1;
 0757            _bytes[_position + 5] = _valBytes.b2;
 0758            _bytes[_position + 4] = _valBytes.b3;
 0759            _bytes[_position + 3] = _valBytes.b4;
 0760            _bytes[_position + 2] = _valBytes.b5;
 0761            _bytes[_position + 1] = _valBytes.b6;
 0762            _bytes[_position] = _valBytes.b7;
 763        }
 1764        _position += 8;
 1765        return this;
 766    }
 767
 768    public ByteBuffer putDoubleSeq(double[] seq)
 769    {
 1770        int len = System.Buffer.ByteLength(seq);
 1771        checkOverflow(len);
 1772        if (_order == NativeOrder._o)
 773        {
 1774            System.Buffer.BlockCopy(seq, 0, _bytes, _position, len);
 775        }
 776        else
 777        {
 0778            for (int i = 0; i < seq.Length; ++i)
 779            {
 0780                int index = _position + (i * 8);
 0781                _valBytes.doubleVal = seq[i];
 0782                _bytes[index + 7] = _valBytes.b0;
 0783                _bytes[index + 6] = _valBytes.b1;
 0784                _bytes[index + 5] = _valBytes.b2;
 0785                _bytes[index + 4] = _valBytes.b3;
 0786                _bytes[index + 3] = _valBytes.b4;
 0787                _bytes[index + 2] = _valBytes.b5;
 0788                _bytes[index + 1] = _valBytes.b6;
 0789                _bytes[index] = _valBytes.b7;
 790            }
 791        }
 1792        _position += len;
 1793        return this;
 794    }
 795
 1796    public byte[] rawBytes() => _bytes;
 797
 798    public byte[] rawBytes(int offset, int len)
 799    {
 0800        if (offset + len > _limit)
 801        {
 0802            throw new InvalidOperationException("buffer underflow");
 803        }
 0804        byte[] rc = new byte[len];
 0805        Array.Copy(_bytes, offset, rc, 0, len);
 0806        return rc;
 807    }
 808
 809    private void checkUnderflow(int size)
 810    {
 1811        if (_position + size > _limit)
 812        {
 1813            throw new InvalidOperationException("buffer underflow");
 814        }
 1815    }
 816
 817    private void checkUnderflow(int pos, int size)
 818    {
 1819        if (pos + size > _limit)
 820        {
 0821            throw new InvalidOperationException("buffer underflow");
 822        }
 1823    }
 824
 825    private void checkOverflow(int size)
 826    {
 1827        if (_position + size > _limit)
 828        {
 0829            throw new InvalidOperationException("buffer overflow");
 830        }
 1831    }
 832
 833    private int _position;
 834    private int _limit;
 835    private int _capacity;
 836    private byte[] _bytes;
 837    private ValBytes _valBytes;
 838    private ByteOrder _order;
 839
 840    private class NativeOrder // Native Order
 841    {
 1842        static NativeOrder() => _o = BitConverter.IsLittleEndian ? ByteOrder.LittleEndian : ByteOrder.BigEndian;
 843
 844        internal static readonly ByteOrder _o;
 845
 0846        private NativeOrder()
 847        {
 0848        }
 849    }
 850
 851    private static void throwOutOfRange(string param, object value, string message) =>
 0852        throw new ArgumentOutOfRangeException(param, value, message);
 853}