< Summary

Information
Class: Ice.Internal.ByteBuffer
Assembly: Ice
File(s): /_/csharp/src/Ice/Internal/ByteBuffer.cs
Tag: 125_37167941578
Line coverage
67%
Covered lines: 273
Uncovered lines: 134
Coverable lines: 407
Total lines: 807
Line coverage: 67%
Branch coverage
45%
Covered branches: 43
Total branches: 94
Branch coverage: 45.7%
Method coverage
94%
Covered methods: 54
Fully covered methods: 30
Total methods: 57
Method coverage: 94.7%
Full method coverage: 52.6%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
allocate(...)50%2288.89%
wrap(...)100%11100%
.ctor()100%11100%
order()100%11100%
order(...)100%11100%
position()100%11100%
position(...)50%5466.67%
limit()100%11100%
limit(...)50%5466.67%
clear()100%210%
flip()100%11100%
compact()50%2285.71%
remaining()100%11100%
hasRemaining()100%11100%
capacity()100%11100%
put(...)100%11100%
get()100%11100%
get(...)100%11100%
get(...)100%11100%
get(...)50%4475%
put(...)100%11100%
put(...)100%11100%
put(...)100%11100%
put(...)66.67%6677.78%
getBoolSeq(...)100%11100%
putBool(...)100%11100%
putBoolSeq(...)100%11100%
getShort()100%11100%
getShort(...)100%22100%
getShortSeq(...)25%6454.55%
putShort(...)100%22100%
putShortSeq(...)25%6454.55%
getInt()50%2266.67%
getIntSeq(...)25%6446.15%
putInt(...)100%11100%
putInt(...)50%8660%
putIntSeq(...)25%6446.15%
getLong()100%11100%
getLong(...)100%22100%
getLongSeq(...)25%8435.29%
putLong(...)100%22100%
putLongSeq(...)25%8435.29%
getFloat()50%2266.67%
getFloatSeq(...)25%6446.15%
putFloat(...)50%2269.23%
putFloatSeq(...)25%6446.15%
getDouble()50%2260%
getDoubleSeq(...)25%8435.29%
putDouble(...)50%2261.9%
putDoubleSeq(...)25%8435.29%
rawBytes()100%11100%
checkUnderflow(...)100%22100%
checkUnderflow(...)50%2266.67%
checkOverflow(...)50%2266.67%
.cctor()50%22100%
.ctor()100%210%
throwOutOfRange(...)100%210%

File(s)

/_/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{
 9    public static ByteBuffer allocate(int capacity)
 10    {
 111        if (capacity < 0)
 12        {
 013            throwOutOfRange("capacity", capacity, "capacity must be non-negative");
 14        }
 115        var ret = new ByteBuffer();
 116        ret._position = 0;
 117        ret._limit = capacity;
 118        ret._capacity = capacity;
 119        ret._bytes = new byte[capacity];
 120        ret._valBytes = new ValBytes();
 121        return ret;
 22    }
 23
 24    public static ByteBuffer wrap(byte[] bytes)
 25    {
 126        var ret = new ByteBuffer();
 127        ret._position = 0;
 128        ret._limit = bytes.Length;
 129        ret._capacity = bytes.Length;
 130        ret._bytes = bytes;
 131        ret._valBytes = new ValBytes();
 132        return ret;
 33    }
 34
 135    public ByteBuffer() => _order = ByteOrder.BigEndian;
 36
 37    /// <summary>
 38    /// Represents the endianness of the buffer.
 39    /// </summary>
 40    public enum ByteOrder
 41    {
 42        /// <summary>
 43        /// Big endian byte order.
 44        /// </summary>
 45        BigEndian,
 46
 47        /// <summary>
 48        /// Little endian byte order.
 49        /// </summary>
 50        LittleEndian
 51    }
 52
 153    public ByteOrder order() => _order;
 54
 55    public ByteBuffer order(ByteOrder bo)
 56    {
 157        _order = bo;
 158        return this;
 59    }
 60
 161    public int position() => _position;
 62
 63    public ByteBuffer position(int pos)
 64    {
 165        if (pos < 0)
 66        {
 067            throwOutOfRange("pos", pos, "position must be non-negative");
 68        }
 169        if (pos > _limit)
 70        {
 071            throwOutOfRange("pos", pos, "position must be less than limit");
 72        }
 173        _position = pos;
 174        return this;
 75    }
 76
 177    public int limit() => _limit;
 78
 79    public ByteBuffer limit(int newLimit)
 80    {
 181        if (newLimit < 0)
 82        {
 083            throwOutOfRange("newLimit", newLimit, "limit must be non-negative");
 84        }
 185        if (newLimit > _capacity)
 86        {
 087            throwOutOfRange("newLimit", newLimit, "limit must be less than capacity");
 88        }
 189        _limit = newLimit;
 190        return this;
 91    }
 92
 93    public void clear()
 94    {
 095        _position = 0;
 096        _limit = _capacity;
 097    }
 98
 99    public void flip()
 100    {
 1101        _limit = _position;
 1102        _position = 0;
 1103    }
 104
 105    public void compact()
 106    {
 1107        if (_position < _limit)
 108        {
 1109            int n = _limit - _position;
 1110            System.Buffer.BlockCopy(_bytes, _position, _bytes, 0, n);
 1111            _position = n;
 112        }
 113        else
 114        {
 0115            _position = 0;
 116        }
 1117        _limit = _capacity;
 1118    }
 119
 1120    public int remaining() => _limit - _position;
 121
 1122    public bool hasRemaining() => _position < _limit;
 123
 1124    public int capacity() => _capacity;
 125
 126    public ByteBuffer put(ByteBuffer buf)
 127    {
 1128        int len = buf.remaining();
 1129        checkOverflow(len);
 1130        System.Buffer.BlockCopy(buf._bytes, buf._position, _bytes, _position, len);
 1131        _position += len;
 1132        return this;
 133    }
 134
 135    public byte get()
 136    {
 1137        checkUnderflow(1);
 1138        return System.Buffer.GetByte(_bytes, _position++);
 139    }
 140
 1141    public byte get(int pos) => System.Buffer.GetByte(_bytes, pos);
 142
 1143    public ByteBuffer get(byte[] b) => get(b, 0, System.Buffer.ByteLength(b));
 144
 145    public ByteBuffer get(byte[] b, int offset, int length)
 146    {
 1147        if (offset < 0)
 148        {
 0149            throwOutOfRange("offset", offset, "offset must be non-negative");
 150        }
 1151        if (offset + length > System.Buffer.ByteLength(b))
 152        {
 0153            throwOutOfRange("length", length, "insufficient room beyond given offset in destination array");
 154        }
 1155        checkUnderflow(length);
 1156        System.Buffer.BlockCopy(_bytes, _position, b, offset, length);
 1157        _position += length;
 1158        return this;
 159    }
 160
 161    public ByteBuffer put(byte b)
 162    {
 1163        checkOverflow(1);
 1164        _bytes[_position++] = b;
 1165        return this;
 166    }
 167
 168    public ByteBuffer put(int pos, byte b)
 169    {
 1170        _bytes[pos] = b;
 1171        return this;
 172    }
 173
 1174    public ByteBuffer put(byte[] b) => put(b, 0, System.Buffer.ByteLength(b));
 175
 176    public ByteBuffer put(byte[] b, int offset, int length)
 177    {
 1178        if (offset < 0)
 179        {
 0180            throwOutOfRange("offset", offset, "offset must be non-negative");
 181        }
 1182        if (offset + length > System.Buffer.ByteLength(b))
 183        {
 0184            throwOutOfRange("length", length, "insufficient data beyond given offset in source array");
 185        }
 1186        if (length > 0)
 187        {
 1188            checkOverflow(length);
 1189            System.Buffer.BlockCopy(b, offset, _bytes, _position, length);
 1190            _position += length;
 191        }
 1192        return this;
 193    }
 194
 195    public void getBoolSeq(bool[] seq)
 196    {
 1197        int len = System.Buffer.ByteLength(seq);
 1198        checkUnderflow(len);
 1199        System.Buffer.BlockCopy(_bytes, _position, seq, 0, len);
 1200        _position += len;
 1201    }
 202
 1203    public ByteBuffer putBool(bool b) => put(b ? (byte)1 : (byte)0);
 204
 205    public ByteBuffer putBoolSeq(bool[] seq)
 206    {
 1207        int len = System.Buffer.ByteLength(seq);
 1208        checkOverflow(len);
 1209        System.Buffer.BlockCopy(seq, 0, _bytes, _position, len);
 1210        _position += len;
 1211        return this;
 212    }
 213
 214    [StructLayout(LayoutKind.Explicit)]
 215    private struct ValBytes
 216    {
 217        [FieldOffset(0)]
 218        public short shortVal;
 219
 220        [FieldOffset(0)]
 221        public int intVal;
 222
 223        [FieldOffset(0)]
 224        public long longVal;
 225
 226        [FieldOffset(0)]
 227        public float floatVal;
 228
 229        [FieldOffset(0)]
 230        public double doubleVal;
 231
 232        [FieldOffset(0)]
 233        public byte b0;
 234        [FieldOffset(1)]
 235        public byte b1;
 236        [FieldOffset(2)]
 237        public byte b2;
 238        [FieldOffset(3)]
 239        public byte b3;
 240        [FieldOffset(4)]
 241        public byte b4;
 242        [FieldOffset(5)]
 243        public byte b5;
 244        [FieldOffset(6)]
 245        public byte b6;
 246        [FieldOffset(7)]
 247        public byte b7;
 248    }
 249
 250    public short getShort()
 251    {
 1252        short v = getShort(_position);
 1253        _position += 2;
 1254        return v;
 255    }
 256
 257    public short getShort(int pos)
 258    {
 1259        checkUnderflow(pos, 2);
 1260        if (_order == NativeOrder._o)
 261        {
 1262            _valBytes.b0 = _bytes[pos];
 1263            _valBytes.b1 = _bytes[pos + 1];
 264        }
 265        else
 266        {
 1267            _valBytes.b1 = _bytes[pos];
 1268            _valBytes.b0 = _bytes[pos + 1];
 269        }
 1270        return _valBytes.shortVal;
 271    }
 272
 273    public void getShortSeq(short[] seq)
 274    {
 1275        int len = System.Buffer.ByteLength(seq);
 1276        checkUnderflow(len);
 1277        if (_order == NativeOrder._o)
 278        {
 1279            System.Buffer.BlockCopy(_bytes, _position, seq, 0, len);
 280        }
 281        else
 282        {
 0283            for (int i = 0; i < seq.Length; ++i)
 284            {
 0285                int index = _position + (i * 2);
 0286                _valBytes.b1 = _bytes[index];
 0287                _valBytes.b0 = _bytes[index + 1];
 0288                seq[i] = _valBytes.shortVal;
 289            }
 290        }
 1291        _position += len;
 1292    }
 293
 294    public ByteBuffer putShort(short val)
 295    {
 1296        checkOverflow(2);
 1297        _valBytes.shortVal = val;
 1298        if (_order == NativeOrder._o)
 299        {
 1300            _bytes[_position] = _valBytes.b0;
 1301            _bytes[_position + 1] = _valBytes.b1;
 302        }
 303        else
 304        {
 1305            _bytes[_position + 1] = _valBytes.b0;
 1306            _bytes[_position] = _valBytes.b1;
 307        }
 1308        _position += 2;
 1309        return this;
 310    }
 311
 312    public ByteBuffer putShortSeq(short[] seq)
 313    {
 1314        int len = System.Buffer.ByteLength(seq);
 1315        checkOverflow(len);
 1316        if (_order == NativeOrder._o)
 317        {
 1318            System.Buffer.BlockCopy(seq, 0, _bytes, _position, len);
 319        }
 320        else
 321        {
 0322            for (int i = 0; i < seq.Length; ++i)
 323            {
 0324                int index = _position + (i * 2);
 0325                _valBytes.shortVal = seq[i];
 0326                _bytes[index + 1] = _valBytes.b0;
 0327                _bytes[index] = _valBytes.b1;
 328            }
 329        }
 1330        _position += len;
 1331        return this;
 332    }
 333
 334    public int getInt()
 335    {
 1336        checkUnderflow(4);
 1337        if (_order == NativeOrder._o)
 338        {
 1339            _valBytes.b0 = _bytes[_position];
 1340            _valBytes.b1 = _bytes[_position + 1];
 1341            _valBytes.b2 = _bytes[_position + 2];
 1342            _valBytes.b3 = _bytes[_position + 3];
 343        }
 344        else
 345        {
 0346            _valBytes.b3 = _bytes[_position];
 0347            _valBytes.b2 = _bytes[_position + 1];
 0348            _valBytes.b1 = _bytes[_position + 2];
 0349            _valBytes.b0 = _bytes[_position + 3];
 350        }
 1351        _position += 4;
 1352        return _valBytes.intVal;
 353    }
 354
 355    public void getIntSeq(int[] seq)
 356    {
 1357        int len = System.Buffer.ByteLength(seq);
 1358        checkUnderflow(len);
 1359        if (_order == NativeOrder._o)
 360        {
 1361            System.Buffer.BlockCopy(_bytes, _position, seq, 0, len);
 362        }
 363        else
 364        {
 0365            for (int i = 0; i < seq.Length; ++i)
 366            {
 0367                int index = _position + (i * 4);
 0368                _valBytes.b3 = _bytes[index];
 0369                _valBytes.b2 = _bytes[index + 1];
 0370                _valBytes.b1 = _bytes[index + 2];
 0371                _valBytes.b0 = _bytes[index + 3];
 0372                seq[i] = _valBytes.intVal;
 373            }
 374        }
 1375        _position += len;
 1376    }
 377
 378    public ByteBuffer putInt(int val)
 379    {
 1380        putInt(_position, val);
 1381        _position += 4;
 1382        return this;
 383    }
 384
 385    public ByteBuffer putInt(int pos, int val)
 386    {
 1387        if (pos < 0)
 388        {
 0389            throwOutOfRange("pos", pos, "position must be non-negative");
 390        }
 1391        if (pos + 4 > _limit)
 392        {
 0393            throwOutOfRange("pos", pos, "position must be less than limit - 4");
 394        }
 1395        _valBytes.intVal = val;
 1396        if (_order == NativeOrder._o)
 397        {
 1398            _bytes[pos] = _valBytes.b0;
 1399            _bytes[pos + 1] = _valBytes.b1;
 1400            _bytes[pos + 2] = _valBytes.b2;
 1401            _bytes[pos + 3] = _valBytes.b3;
 402        }
 403        else
 404        {
 0405            _bytes[pos + 3] = _valBytes.b0;
 0406            _bytes[pos + 2] = _valBytes.b1;
 0407            _bytes[pos + 1] = _valBytes.b2;
 0408            _bytes[pos] = _valBytes.b3;
 409        }
 1410        return this;
 411    }
 412
 413    public ByteBuffer putIntSeq(int[] seq)
 414    {
 1415        int len = System.Buffer.ByteLength(seq);
 1416        checkOverflow(len);
 1417        if (_order == NativeOrder._o)
 418        {
 1419            System.Buffer.BlockCopy(seq, 0, _bytes, _position, len);
 420        }
 421        else
 422        {
 0423            for (int i = 0; i < seq.Length; ++i)
 424            {
 0425                int index = _position + (i * 4);
 0426                _valBytes.intVal = seq[i];
 0427                _bytes[index + 3] = _valBytes.b0;
 0428                _bytes[index + 2] = _valBytes.b1;
 0429                _bytes[index + 1] = _valBytes.b2;
 0430                _bytes[index] = _valBytes.b3;
 431            }
 432        }
 1433        _position += len;
 1434        return this;
 435    }
 436
 437    public long getLong()
 438    {
 1439        long v = getLong(_position);
 1440        _position += 8;
 1441        return v;
 442    }
 443
 444    public long getLong(int pos)
 445    {
 1446        checkUnderflow(pos, 8);
 1447        if (_order == NativeOrder._o)
 448        {
 1449            _valBytes.b0 = _bytes[pos];
 1450            _valBytes.b1 = _bytes[pos + 1];
 1451            _valBytes.b2 = _bytes[pos + 2];
 1452            _valBytes.b3 = _bytes[pos + 3];
 1453            _valBytes.b4 = _bytes[pos + 4];
 1454            _valBytes.b5 = _bytes[pos + 5];
 1455            _valBytes.b6 = _bytes[pos + 6];
 1456            _valBytes.b7 = _bytes[pos + 7];
 457        }
 458        else
 459        {
 1460            _valBytes.b7 = _bytes[pos];
 1461            _valBytes.b6 = _bytes[pos + 1];
 1462            _valBytes.b5 = _bytes[pos + 2];
 1463            _valBytes.b4 = _bytes[pos + 3];
 1464            _valBytes.b3 = _bytes[pos + 4];
 1465            _valBytes.b2 = _bytes[pos + 5];
 1466            _valBytes.b1 = _bytes[pos + 6];
 1467            _valBytes.b0 = _bytes[pos + 7];
 468        }
 1469        return _valBytes.longVal;
 470    }
 471
 472    public void getLongSeq(long[] seq)
 473    {
 1474        int len = System.Buffer.ByteLength(seq);
 1475        checkUnderflow(len);
 1476        if (_order == NativeOrder._o)
 477        {
 1478            System.Buffer.BlockCopy(_bytes, _position, seq, 0, len);
 479        }
 480        else
 481        {
 0482            for (int i = 0; i < seq.Length; ++i)
 483            {
 0484                int index = _position + (i * 8);
 0485                _valBytes.b7 = _bytes[index];
 0486                _valBytes.b6 = _bytes[index + 1];
 0487                _valBytes.b5 = _bytes[index + 2];
 0488                _valBytes.b4 = _bytes[index + 3];
 0489                _valBytes.b3 = _bytes[index + 4];
 0490                _valBytes.b2 = _bytes[index + 5];
 0491                _valBytes.b1 = _bytes[index + 6];
 0492                _valBytes.b0 = _bytes[index + 7];
 0493                seq[i] = _valBytes.longVal;
 494            }
 495        }
 1496        _position += len;
 1497    }
 498
 499    public ByteBuffer putLong(long val)
 500    {
 1501        checkOverflow(8);
 1502        _valBytes.longVal = val;
 1503        if (_order == NativeOrder._o)
 504        {
 1505            _bytes[_position] = _valBytes.b0;
 1506            _bytes[_position + 1] = _valBytes.b1;
 1507            _bytes[_position + 2] = _valBytes.b2;
 1508            _bytes[_position + 3] = _valBytes.b3;
 1509            _bytes[_position + 4] = _valBytes.b4;
 1510            _bytes[_position + 5] = _valBytes.b5;
 1511            _bytes[_position + 6] = _valBytes.b6;
 1512            _bytes[_position + 7] = _valBytes.b7;
 513        }
 514        else
 515        {
 1516            _bytes[_position + 7] = _valBytes.b0;
 1517            _bytes[_position + 6] = _valBytes.b1;
 1518            _bytes[_position + 5] = _valBytes.b2;
 1519            _bytes[_position + 4] = _valBytes.b3;
 1520            _bytes[_position + 3] = _valBytes.b4;
 1521            _bytes[_position + 2] = _valBytes.b5;
 1522            _bytes[_position + 1] = _valBytes.b6;
 1523            _bytes[_position] = _valBytes.b7;
 524        }
 1525        _position += 8;
 1526        return this;
 527    }
 528
 529    public ByteBuffer putLongSeq(long[] seq)
 530    {
 1531        int len = System.Buffer.ByteLength(seq);
 1532        checkOverflow(len);
 1533        if (_order == NativeOrder._o)
 534        {
 1535            System.Buffer.BlockCopy(seq, 0, _bytes, _position, len);
 536        }
 537        else
 538        {
 0539            for (int i = 0; i < seq.Length; ++i)
 540            {
 0541                int index = _position + (i * 8);
 0542                _valBytes.longVal = seq[i];
 0543                _bytes[index + 7] = _valBytes.b0;
 0544                _bytes[index + 6] = _valBytes.b1;
 0545                _bytes[index + 5] = _valBytes.b2;
 0546                _bytes[index + 4] = _valBytes.b3;
 0547                _bytes[index + 3] = _valBytes.b4;
 0548                _bytes[index + 2] = _valBytes.b5;
 0549                _bytes[index + 1] = _valBytes.b6;
 0550                _bytes[index] = _valBytes.b7;
 551            }
 552        }
 1553        _position += len;
 1554        return this;
 555    }
 556
 557    public float getFloat()
 558    {
 1559        checkUnderflow(4);
 1560        if (_order == NativeOrder._o)
 561        {
 1562            _valBytes.b0 = _bytes[_position];
 1563            _valBytes.b1 = _bytes[_position + 1];
 1564            _valBytes.b2 = _bytes[_position + 2];
 1565            _valBytes.b3 = _bytes[_position + 3];
 566        }
 567        else
 568        {
 0569            _valBytes.b3 = _bytes[_position];
 0570            _valBytes.b2 = _bytes[_position + 1];
 0571            _valBytes.b1 = _bytes[_position + 2];
 0572            _valBytes.b0 = _bytes[_position + 3];
 573        }
 1574        _position += 4;
 1575        return _valBytes.floatVal;
 576    }
 577
 578    public void getFloatSeq(float[] seq)
 579    {
 1580        int len = System.Buffer.ByteLength(seq);
 1581        checkUnderflow(len);
 1582        if (_order == NativeOrder._o)
 583        {
 1584            System.Buffer.BlockCopy(_bytes, _position, seq, 0, len);
 585        }
 586        else
 587        {
 0588            for (int i = 0; i < seq.Length; ++i)
 589            {
 0590                int index = _position + (i * 4);
 0591                _valBytes.b3 = _bytes[index];
 0592                _valBytes.b2 = _bytes[index + 1];
 0593                _valBytes.b1 = _bytes[index + 2];
 0594                _valBytes.b0 = _bytes[index + 3];
 0595                seq[i] = _valBytes.floatVal;
 596            }
 597        }
 1598        _position += len;
 1599    }
 600
 601    public ByteBuffer putFloat(float val)
 602    {
 1603        checkOverflow(4);
 1604        _valBytes.floatVal = val;
 1605        if (_order == NativeOrder._o)
 606        {
 1607            _bytes[_position] = _valBytes.b0;
 1608            _bytes[_position + 1] = _valBytes.b1;
 1609            _bytes[_position + 2] = _valBytes.b2;
 1610            _bytes[_position + 3] = _valBytes.b3;
 611        }
 612        else
 613        {
 0614            _bytes[_position + 3] = _valBytes.b0;
 0615            _bytes[_position + 2] = _valBytes.b1;
 0616            _bytes[_position + 1] = _valBytes.b2;
 0617            _bytes[_position] = _valBytes.b3;
 618        }
 1619        _position += 4;
 1620        return this;
 621    }
 622
 623    public ByteBuffer putFloatSeq(float[] seq)
 624    {
 1625        int len = System.Buffer.ByteLength(seq);
 1626        checkOverflow(len);
 1627        if (_order == NativeOrder._o)
 628        {
 1629            System.Buffer.BlockCopy(seq, 0, _bytes, _position, len);
 630        }
 631        else
 632        {
 0633            for (int i = 0; i < seq.Length; ++i)
 634            {
 0635                int index = _position + (i * 4);
 0636                _valBytes.floatVal = seq[i];
 0637                _bytes[index + 3] = _valBytes.b0;
 0638                _bytes[index + 2] = _valBytes.b1;
 0639                _bytes[index + 1] = _valBytes.b2;
 0640                _bytes[index] = _valBytes.b3;
 641            }
 642        }
 1643        _position += len;
 1644        return this;
 645    }
 646
 647    public double getDouble()
 648    {
 1649        checkUnderflow(8);
 1650        if (_order == NativeOrder._o)
 651        {
 1652            _valBytes.b0 = _bytes[_position];
 1653            _valBytes.b1 = _bytes[_position + 1];
 1654            _valBytes.b2 = _bytes[_position + 2];
 1655            _valBytes.b3 = _bytes[_position + 3];
 1656            _valBytes.b4 = _bytes[_position + 4];
 1657            _valBytes.b5 = _bytes[_position + 5];
 1658            _valBytes.b6 = _bytes[_position + 6];
 1659            _valBytes.b7 = _bytes[_position + 7];
 660        }
 661        else
 662        {
 0663            _valBytes.b7 = _bytes[_position];
 0664            _valBytes.b6 = _bytes[_position + 1];
 0665            _valBytes.b5 = _bytes[_position + 2];
 0666            _valBytes.b4 = _bytes[_position + 3];
 0667            _valBytes.b3 = _bytes[_position + 4];
 0668            _valBytes.b2 = _bytes[_position + 5];
 0669            _valBytes.b1 = _bytes[_position + 6];
 0670            _valBytes.b0 = _bytes[_position + 7];
 671        }
 1672        _position += 8;
 1673        return _valBytes.doubleVal;
 674    }
 675
 676    public void getDoubleSeq(double[] seq)
 677    {
 1678        int len = System.Buffer.ByteLength(seq);
 1679        checkUnderflow(len);
 1680        if (_order == NativeOrder._o)
 681        {
 1682            System.Buffer.BlockCopy(_bytes, _position, seq, 0, len);
 683        }
 684        else
 685        {
 0686            for (int i = 0; i < seq.Length; ++i)
 687            {
 0688                int index = _position + (i * 8);
 0689                _valBytes.b7 = _bytes[index];
 0690                _valBytes.b6 = _bytes[index + 1];
 0691                _valBytes.b5 = _bytes[index + 2];
 0692                _valBytes.b4 = _bytes[index + 3];
 0693                _valBytes.b3 = _bytes[index + 4];
 0694                _valBytes.b2 = _bytes[index + 5];
 0695                _valBytes.b1 = _bytes[index + 6];
 0696                _valBytes.b0 = _bytes[index + 7];
 0697                seq[i] = _valBytes.doubleVal;
 698            }
 699        }
 1700        _position += len;
 1701    }
 702
 703    public ByteBuffer putDouble(double val)
 704    {
 1705        checkOverflow(8);
 1706        _valBytes.doubleVal = val;
 1707        if (_order == NativeOrder._o)
 708        {
 1709            _bytes[_position] = _valBytes.b0;
 1710            _bytes[_position + 1] = _valBytes.b1;
 1711            _bytes[_position + 2] = _valBytes.b2;
 1712            _bytes[_position + 3] = _valBytes.b3;
 1713            _bytes[_position + 4] = _valBytes.b4;
 1714            _bytes[_position + 5] = _valBytes.b5;
 1715            _bytes[_position + 6] = _valBytes.b6;
 1716            _bytes[_position + 7] = _valBytes.b7;
 717        }
 718        else
 719        {
 0720            _bytes[_position + 7] = _valBytes.b0;
 0721            _bytes[_position + 6] = _valBytes.b1;
 0722            _bytes[_position + 5] = _valBytes.b2;
 0723            _bytes[_position + 4] = _valBytes.b3;
 0724            _bytes[_position + 3] = _valBytes.b4;
 0725            _bytes[_position + 2] = _valBytes.b5;
 0726            _bytes[_position + 1] = _valBytes.b6;
 0727            _bytes[_position] = _valBytes.b7;
 728        }
 1729        _position += 8;
 1730        return this;
 731    }
 732
 733    public ByteBuffer putDoubleSeq(double[] seq)
 734    {
 1735        int len = System.Buffer.ByteLength(seq);
 1736        checkOverflow(len);
 1737        if (_order == NativeOrder._o)
 738        {
 1739            System.Buffer.BlockCopy(seq, 0, _bytes, _position, len);
 740        }
 741        else
 742        {
 0743            for (int i = 0; i < seq.Length; ++i)
 744            {
 0745                int index = _position + (i * 8);
 0746                _valBytes.doubleVal = seq[i];
 0747                _bytes[index + 7] = _valBytes.b0;
 0748                _bytes[index + 6] = _valBytes.b1;
 0749                _bytes[index + 5] = _valBytes.b2;
 0750                _bytes[index + 4] = _valBytes.b3;
 0751                _bytes[index + 3] = _valBytes.b4;
 0752                _bytes[index + 2] = _valBytes.b5;
 0753                _bytes[index + 1] = _valBytes.b6;
 0754                _bytes[index] = _valBytes.b7;
 755            }
 756        }
 1757        _position += len;
 1758        return this;
 759    }
 760
 1761    public byte[] rawBytes() => _bytes;
 762
 763    private void checkUnderflow(int size)
 764    {
 1765        if (_position + size > _limit)
 766        {
 1767            throw new InvalidOperationException("buffer underflow");
 768        }
 1769    }
 770
 771    private void checkUnderflow(int pos, int size)
 772    {
 1773        if (pos + size > _limit)
 774        {
 0775            throw new InvalidOperationException("buffer underflow");
 776        }
 1777    }
 778
 779    private void checkOverflow(int size)
 780    {
 1781        if (_position + size > _limit)
 782        {
 0783            throw new InvalidOperationException("buffer overflow");
 784        }
 1785    }
 786
 787    private int _position;
 788    private int _limit;
 789    private int _capacity;
 790    private byte[] _bytes;
 791    private ValBytes _valBytes;
 792    private ByteOrder _order;
 793
 794    private class NativeOrder // Native Order
 795    {
 1796        static NativeOrder() => _o = BitConverter.IsLittleEndian ? ByteOrder.LittleEndian : ByteOrder.BigEndian;
 797
 798        internal static readonly ByteOrder _o;
 799
 0800        private NativeOrder()
 801        {
 0802        }
 803    }
 804
 805    private static void throwOutOfRange(string param, object value, string message) =>
 0806        throw new ArgumentOutOfRangeException(param, value, message);
 807}