< Summary

Information
Class: Ice.Internal.ByteBuffer.NativeOrder
Assembly: Ice
File(s): /_/csharp/src/Ice/Internal/ByteBuffer.cs
Tag: 125_37167941578
Line coverage
33%
Covered lines: 1
Uncovered lines: 2
Coverable lines: 3
Total lines: 807
Line coverage: 33.3%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage
50%
Covered methods: 1
Fully covered methods: 1
Total methods: 2
Method coverage: 50%
Full method coverage: 50%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()50%22100%
.ctor()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    {
 11        if (capacity < 0)
 12        {
 13            throwOutOfRange("capacity", capacity, "capacity must be non-negative");
 14        }
 15        var ret = new ByteBuffer();
 16        ret._position = 0;
 17        ret._limit = capacity;
 18        ret._capacity = capacity;
 19        ret._bytes = new byte[capacity];
 20        ret._valBytes = new ValBytes();
 21        return ret;
 22    }
 23
 24    public static ByteBuffer wrap(byte[] bytes)
 25    {
 26        var ret = new ByteBuffer();
 27        ret._position = 0;
 28        ret._limit = bytes.Length;
 29        ret._capacity = bytes.Length;
 30        ret._bytes = bytes;
 31        ret._valBytes = new ValBytes();
 32        return ret;
 33    }
 34
 35    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
 53    public ByteOrder order() => _order;
 54
 55    public ByteBuffer order(ByteOrder bo)
 56    {
 57        _order = bo;
 58        return this;
 59    }
 60
 61    public int position() => _position;
 62
 63    public ByteBuffer position(int pos)
 64    {
 65        if (pos < 0)
 66        {
 67            throwOutOfRange("pos", pos, "position must be non-negative");
 68        }
 69        if (pos > _limit)
 70        {
 71            throwOutOfRange("pos", pos, "position must be less than limit");
 72        }
 73        _position = pos;
 74        return this;
 75    }
 76
 77    public int limit() => _limit;
 78
 79    public ByteBuffer limit(int newLimit)
 80    {
 81        if (newLimit < 0)
 82        {
 83            throwOutOfRange("newLimit", newLimit, "limit must be non-negative");
 84        }
 85        if (newLimit > _capacity)
 86        {
 87            throwOutOfRange("newLimit", newLimit, "limit must be less than capacity");
 88        }
 89        _limit = newLimit;
 90        return this;
 91    }
 92
 93    public void clear()
 94    {
 95        _position = 0;
 96        _limit = _capacity;
 97    }
 98
 99    public void flip()
 100    {
 101        _limit = _position;
 102        _position = 0;
 103    }
 104
 105    public void compact()
 106    {
 107        if (_position < _limit)
 108        {
 109            int n = _limit - _position;
 110            System.Buffer.BlockCopy(_bytes, _position, _bytes, 0, n);
 111            _position = n;
 112        }
 113        else
 114        {
 115            _position = 0;
 116        }
 117        _limit = _capacity;
 118    }
 119
 120    public int remaining() => _limit - _position;
 121
 122    public bool hasRemaining() => _position < _limit;
 123
 124    public int capacity() => _capacity;
 125
 126    public ByteBuffer put(ByteBuffer buf)
 127    {
 128        int len = buf.remaining();
 129        checkOverflow(len);
 130        System.Buffer.BlockCopy(buf._bytes, buf._position, _bytes, _position, len);
 131        _position += len;
 132        return this;
 133    }
 134
 135    public byte get()
 136    {
 137        checkUnderflow(1);
 138        return System.Buffer.GetByte(_bytes, _position++);
 139    }
 140
 141    public byte get(int pos) => System.Buffer.GetByte(_bytes, pos);
 142
 143    public ByteBuffer get(byte[] b) => get(b, 0, System.Buffer.ByteLength(b));
 144
 145    public ByteBuffer get(byte[] b, int offset, int length)
 146    {
 147        if (offset < 0)
 148        {
 149            throwOutOfRange("offset", offset, "offset must be non-negative");
 150        }
 151        if (offset + length > System.Buffer.ByteLength(b))
 152        {
 153            throwOutOfRange("length", length, "insufficient room beyond given offset in destination array");
 154        }
 155        checkUnderflow(length);
 156        System.Buffer.BlockCopy(_bytes, _position, b, offset, length);
 157        _position += length;
 158        return this;
 159    }
 160
 161    public ByteBuffer put(byte b)
 162    {
 163        checkOverflow(1);
 164        _bytes[_position++] = b;
 165        return this;
 166    }
 167
 168    public ByteBuffer put(int pos, byte b)
 169    {
 170        _bytes[pos] = b;
 171        return this;
 172    }
 173
 174    public ByteBuffer put(byte[] b) => put(b, 0, System.Buffer.ByteLength(b));
 175
 176    public ByteBuffer put(byte[] b, int offset, int length)
 177    {
 178        if (offset < 0)
 179        {
 180            throwOutOfRange("offset", offset, "offset must be non-negative");
 181        }
 182        if (offset + length > System.Buffer.ByteLength(b))
 183        {
 184            throwOutOfRange("length", length, "insufficient data beyond given offset in source array");
 185        }
 186        if (length > 0)
 187        {
 188            checkOverflow(length);
 189            System.Buffer.BlockCopy(b, offset, _bytes, _position, length);
 190            _position += length;
 191        }
 192        return this;
 193    }
 194
 195    public void getBoolSeq(bool[] seq)
 196    {
 197        int len = System.Buffer.ByteLength(seq);
 198        checkUnderflow(len);
 199        System.Buffer.BlockCopy(_bytes, _position, seq, 0, len);
 200        _position += len;
 201    }
 202
 203    public ByteBuffer putBool(bool b) => put(b ? (byte)1 : (byte)0);
 204
 205    public ByteBuffer putBoolSeq(bool[] seq)
 206    {
 207        int len = System.Buffer.ByteLength(seq);
 208        checkOverflow(len);
 209        System.Buffer.BlockCopy(seq, 0, _bytes, _position, len);
 210        _position += len;
 211        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    {
 252        short v = getShort(_position);
 253        _position += 2;
 254        return v;
 255    }
 256
 257    public short getShort(int pos)
 258    {
 259        checkUnderflow(pos, 2);
 260        if (_order == NativeOrder._o)
 261        {
 262            _valBytes.b0 = _bytes[pos];
 263            _valBytes.b1 = _bytes[pos + 1];
 264        }
 265        else
 266        {
 267            _valBytes.b1 = _bytes[pos];
 268            _valBytes.b0 = _bytes[pos + 1];
 269        }
 270        return _valBytes.shortVal;
 271    }
 272
 273    public void getShortSeq(short[] seq)
 274    {
 275        int len = System.Buffer.ByteLength(seq);
 276        checkUnderflow(len);
 277        if (_order == NativeOrder._o)
 278        {
 279            System.Buffer.BlockCopy(_bytes, _position, seq, 0, len);
 280        }
 281        else
 282        {
 283            for (int i = 0; i < seq.Length; ++i)
 284            {
 285                int index = _position + (i * 2);
 286                _valBytes.b1 = _bytes[index];
 287                _valBytes.b0 = _bytes[index + 1];
 288                seq[i] = _valBytes.shortVal;
 289            }
 290        }
 291        _position += len;
 292    }
 293
 294    public ByteBuffer putShort(short val)
 295    {
 296        checkOverflow(2);
 297        _valBytes.shortVal = val;
 298        if (_order == NativeOrder._o)
 299        {
 300            _bytes[_position] = _valBytes.b0;
 301            _bytes[_position + 1] = _valBytes.b1;
 302        }
 303        else
 304        {
 305            _bytes[_position + 1] = _valBytes.b0;
 306            _bytes[_position] = _valBytes.b1;
 307        }
 308        _position += 2;
 309        return this;
 310    }
 311
 312    public ByteBuffer putShortSeq(short[] seq)
 313    {
 314        int len = System.Buffer.ByteLength(seq);
 315        checkOverflow(len);
 316        if (_order == NativeOrder._o)
 317        {
 318            System.Buffer.BlockCopy(seq, 0, _bytes, _position, len);
 319        }
 320        else
 321        {
 322            for (int i = 0; i < seq.Length; ++i)
 323            {
 324                int index = _position + (i * 2);
 325                _valBytes.shortVal = seq[i];
 326                _bytes[index + 1] = _valBytes.b0;
 327                _bytes[index] = _valBytes.b1;
 328            }
 329        }
 330        _position += len;
 331        return this;
 332    }
 333
 334    public int getInt()
 335    {
 336        checkUnderflow(4);
 337        if (_order == NativeOrder._o)
 338        {
 339            _valBytes.b0 = _bytes[_position];
 340            _valBytes.b1 = _bytes[_position + 1];
 341            _valBytes.b2 = _bytes[_position + 2];
 342            _valBytes.b3 = _bytes[_position + 3];
 343        }
 344        else
 345        {
 346            _valBytes.b3 = _bytes[_position];
 347            _valBytes.b2 = _bytes[_position + 1];
 348            _valBytes.b1 = _bytes[_position + 2];
 349            _valBytes.b0 = _bytes[_position + 3];
 350        }
 351        _position += 4;
 352        return _valBytes.intVal;
 353    }
 354
 355    public void getIntSeq(int[] seq)
 356    {
 357        int len = System.Buffer.ByteLength(seq);
 358        checkUnderflow(len);
 359        if (_order == NativeOrder._o)
 360        {
 361            System.Buffer.BlockCopy(_bytes, _position, seq, 0, len);
 362        }
 363        else
 364        {
 365            for (int i = 0; i < seq.Length; ++i)
 366            {
 367                int index = _position + (i * 4);
 368                _valBytes.b3 = _bytes[index];
 369                _valBytes.b2 = _bytes[index + 1];
 370                _valBytes.b1 = _bytes[index + 2];
 371                _valBytes.b0 = _bytes[index + 3];
 372                seq[i] = _valBytes.intVal;
 373            }
 374        }
 375        _position += len;
 376    }
 377
 378    public ByteBuffer putInt(int val)
 379    {
 380        putInt(_position, val);
 381        _position += 4;
 382        return this;
 383    }
 384
 385    public ByteBuffer putInt(int pos, int val)
 386    {
 387        if (pos < 0)
 388        {
 389            throwOutOfRange("pos", pos, "position must be non-negative");
 390        }
 391        if (pos + 4 > _limit)
 392        {
 393            throwOutOfRange("pos", pos, "position must be less than limit - 4");
 394        }
 395        _valBytes.intVal = val;
 396        if (_order == NativeOrder._o)
 397        {
 398            _bytes[pos] = _valBytes.b0;
 399            _bytes[pos + 1] = _valBytes.b1;
 400            _bytes[pos + 2] = _valBytes.b2;
 401            _bytes[pos + 3] = _valBytes.b3;
 402        }
 403        else
 404        {
 405            _bytes[pos + 3] = _valBytes.b0;
 406            _bytes[pos + 2] = _valBytes.b1;
 407            _bytes[pos + 1] = _valBytes.b2;
 408            _bytes[pos] = _valBytes.b3;
 409        }
 410        return this;
 411    }
 412
 413    public ByteBuffer putIntSeq(int[] seq)
 414    {
 415        int len = System.Buffer.ByteLength(seq);
 416        checkOverflow(len);
 417        if (_order == NativeOrder._o)
 418        {
 419            System.Buffer.BlockCopy(seq, 0, _bytes, _position, len);
 420        }
 421        else
 422        {
 423            for (int i = 0; i < seq.Length; ++i)
 424            {
 425                int index = _position + (i * 4);
 426                _valBytes.intVal = seq[i];
 427                _bytes[index + 3] = _valBytes.b0;
 428                _bytes[index + 2] = _valBytes.b1;
 429                _bytes[index + 1] = _valBytes.b2;
 430                _bytes[index] = _valBytes.b3;
 431            }
 432        }
 433        _position += len;
 434        return this;
 435    }
 436
 437    public long getLong()
 438    {
 439        long v = getLong(_position);
 440        _position += 8;
 441        return v;
 442    }
 443
 444    public long getLong(int pos)
 445    {
 446        checkUnderflow(pos, 8);
 447        if (_order == NativeOrder._o)
 448        {
 449            _valBytes.b0 = _bytes[pos];
 450            _valBytes.b1 = _bytes[pos + 1];
 451            _valBytes.b2 = _bytes[pos + 2];
 452            _valBytes.b3 = _bytes[pos + 3];
 453            _valBytes.b4 = _bytes[pos + 4];
 454            _valBytes.b5 = _bytes[pos + 5];
 455            _valBytes.b6 = _bytes[pos + 6];
 456            _valBytes.b7 = _bytes[pos + 7];
 457        }
 458        else
 459        {
 460            _valBytes.b7 = _bytes[pos];
 461            _valBytes.b6 = _bytes[pos + 1];
 462            _valBytes.b5 = _bytes[pos + 2];
 463            _valBytes.b4 = _bytes[pos + 3];
 464            _valBytes.b3 = _bytes[pos + 4];
 465            _valBytes.b2 = _bytes[pos + 5];
 466            _valBytes.b1 = _bytes[pos + 6];
 467            _valBytes.b0 = _bytes[pos + 7];
 468        }
 469        return _valBytes.longVal;
 470    }
 471
 472    public void getLongSeq(long[] seq)
 473    {
 474        int len = System.Buffer.ByteLength(seq);
 475        checkUnderflow(len);
 476        if (_order == NativeOrder._o)
 477        {
 478            System.Buffer.BlockCopy(_bytes, _position, seq, 0, len);
 479        }
 480        else
 481        {
 482            for (int i = 0; i < seq.Length; ++i)
 483            {
 484                int index = _position + (i * 8);
 485                _valBytes.b7 = _bytes[index];
 486                _valBytes.b6 = _bytes[index + 1];
 487                _valBytes.b5 = _bytes[index + 2];
 488                _valBytes.b4 = _bytes[index + 3];
 489                _valBytes.b3 = _bytes[index + 4];
 490                _valBytes.b2 = _bytes[index + 5];
 491                _valBytes.b1 = _bytes[index + 6];
 492                _valBytes.b0 = _bytes[index + 7];
 493                seq[i] = _valBytes.longVal;
 494            }
 495        }
 496        _position += len;
 497    }
 498
 499    public ByteBuffer putLong(long val)
 500    {
 501        checkOverflow(8);
 502        _valBytes.longVal = val;
 503        if (_order == NativeOrder._o)
 504        {
 505            _bytes[_position] = _valBytes.b0;
 506            _bytes[_position + 1] = _valBytes.b1;
 507            _bytes[_position + 2] = _valBytes.b2;
 508            _bytes[_position + 3] = _valBytes.b3;
 509            _bytes[_position + 4] = _valBytes.b4;
 510            _bytes[_position + 5] = _valBytes.b5;
 511            _bytes[_position + 6] = _valBytes.b6;
 512            _bytes[_position + 7] = _valBytes.b7;
 513        }
 514        else
 515        {
 516            _bytes[_position + 7] = _valBytes.b0;
 517            _bytes[_position + 6] = _valBytes.b1;
 518            _bytes[_position + 5] = _valBytes.b2;
 519            _bytes[_position + 4] = _valBytes.b3;
 520            _bytes[_position + 3] = _valBytes.b4;
 521            _bytes[_position + 2] = _valBytes.b5;
 522            _bytes[_position + 1] = _valBytes.b6;
 523            _bytes[_position] = _valBytes.b7;
 524        }
 525        _position += 8;
 526        return this;
 527    }
 528
 529    public ByteBuffer putLongSeq(long[] seq)
 530    {
 531        int len = System.Buffer.ByteLength(seq);
 532        checkOverflow(len);
 533        if (_order == NativeOrder._o)
 534        {
 535            System.Buffer.BlockCopy(seq, 0, _bytes, _position, len);
 536        }
 537        else
 538        {
 539            for (int i = 0; i < seq.Length; ++i)
 540            {
 541                int index = _position + (i * 8);
 542                _valBytes.longVal = seq[i];
 543                _bytes[index + 7] = _valBytes.b0;
 544                _bytes[index + 6] = _valBytes.b1;
 545                _bytes[index + 5] = _valBytes.b2;
 546                _bytes[index + 4] = _valBytes.b3;
 547                _bytes[index + 3] = _valBytes.b4;
 548                _bytes[index + 2] = _valBytes.b5;
 549                _bytes[index + 1] = _valBytes.b6;
 550                _bytes[index] = _valBytes.b7;
 551            }
 552        }
 553        _position += len;
 554        return this;
 555    }
 556
 557    public float getFloat()
 558    {
 559        checkUnderflow(4);
 560        if (_order == NativeOrder._o)
 561        {
 562            _valBytes.b0 = _bytes[_position];
 563            _valBytes.b1 = _bytes[_position + 1];
 564            _valBytes.b2 = _bytes[_position + 2];
 565            _valBytes.b3 = _bytes[_position + 3];
 566        }
 567        else
 568        {
 569            _valBytes.b3 = _bytes[_position];
 570            _valBytes.b2 = _bytes[_position + 1];
 571            _valBytes.b1 = _bytes[_position + 2];
 572            _valBytes.b0 = _bytes[_position + 3];
 573        }
 574        _position += 4;
 575        return _valBytes.floatVal;
 576    }
 577
 578    public void getFloatSeq(float[] seq)
 579    {
 580        int len = System.Buffer.ByteLength(seq);
 581        checkUnderflow(len);
 582        if (_order == NativeOrder._o)
 583        {
 584            System.Buffer.BlockCopy(_bytes, _position, seq, 0, len);
 585        }
 586        else
 587        {
 588            for (int i = 0; i < seq.Length; ++i)
 589            {
 590                int index = _position + (i * 4);
 591                _valBytes.b3 = _bytes[index];
 592                _valBytes.b2 = _bytes[index + 1];
 593                _valBytes.b1 = _bytes[index + 2];
 594                _valBytes.b0 = _bytes[index + 3];
 595                seq[i] = _valBytes.floatVal;
 596            }
 597        }
 598        _position += len;
 599    }
 600
 601    public ByteBuffer putFloat(float val)
 602    {
 603        checkOverflow(4);
 604        _valBytes.floatVal = val;
 605        if (_order == NativeOrder._o)
 606        {
 607            _bytes[_position] = _valBytes.b0;
 608            _bytes[_position + 1] = _valBytes.b1;
 609            _bytes[_position + 2] = _valBytes.b2;
 610            _bytes[_position + 3] = _valBytes.b3;
 611        }
 612        else
 613        {
 614            _bytes[_position + 3] = _valBytes.b0;
 615            _bytes[_position + 2] = _valBytes.b1;
 616            _bytes[_position + 1] = _valBytes.b2;
 617            _bytes[_position] = _valBytes.b3;
 618        }
 619        _position += 4;
 620        return this;
 621    }
 622
 623    public ByteBuffer putFloatSeq(float[] seq)
 624    {
 625        int len = System.Buffer.ByteLength(seq);
 626        checkOverflow(len);
 627        if (_order == NativeOrder._o)
 628        {
 629            System.Buffer.BlockCopy(seq, 0, _bytes, _position, len);
 630        }
 631        else
 632        {
 633            for (int i = 0; i < seq.Length; ++i)
 634            {
 635                int index = _position + (i * 4);
 636                _valBytes.floatVal = seq[i];
 637                _bytes[index + 3] = _valBytes.b0;
 638                _bytes[index + 2] = _valBytes.b1;
 639                _bytes[index + 1] = _valBytes.b2;
 640                _bytes[index] = _valBytes.b3;
 641            }
 642        }
 643        _position += len;
 644        return this;
 645    }
 646
 647    public double getDouble()
 648    {
 649        checkUnderflow(8);
 650        if (_order == NativeOrder._o)
 651        {
 652            _valBytes.b0 = _bytes[_position];
 653            _valBytes.b1 = _bytes[_position + 1];
 654            _valBytes.b2 = _bytes[_position + 2];
 655            _valBytes.b3 = _bytes[_position + 3];
 656            _valBytes.b4 = _bytes[_position + 4];
 657            _valBytes.b5 = _bytes[_position + 5];
 658            _valBytes.b6 = _bytes[_position + 6];
 659            _valBytes.b7 = _bytes[_position + 7];
 660        }
 661        else
 662        {
 663            _valBytes.b7 = _bytes[_position];
 664            _valBytes.b6 = _bytes[_position + 1];
 665            _valBytes.b5 = _bytes[_position + 2];
 666            _valBytes.b4 = _bytes[_position + 3];
 667            _valBytes.b3 = _bytes[_position + 4];
 668            _valBytes.b2 = _bytes[_position + 5];
 669            _valBytes.b1 = _bytes[_position + 6];
 670            _valBytes.b0 = _bytes[_position + 7];
 671        }
 672        _position += 8;
 673        return _valBytes.doubleVal;
 674    }
 675
 676    public void getDoubleSeq(double[] seq)
 677    {
 678        int len = System.Buffer.ByteLength(seq);
 679        checkUnderflow(len);
 680        if (_order == NativeOrder._o)
 681        {
 682            System.Buffer.BlockCopy(_bytes, _position, seq, 0, len);
 683        }
 684        else
 685        {
 686            for (int i = 0; i < seq.Length; ++i)
 687            {
 688                int index = _position + (i * 8);
 689                _valBytes.b7 = _bytes[index];
 690                _valBytes.b6 = _bytes[index + 1];
 691                _valBytes.b5 = _bytes[index + 2];
 692                _valBytes.b4 = _bytes[index + 3];
 693                _valBytes.b3 = _bytes[index + 4];
 694                _valBytes.b2 = _bytes[index + 5];
 695                _valBytes.b1 = _bytes[index + 6];
 696                _valBytes.b0 = _bytes[index + 7];
 697                seq[i] = _valBytes.doubleVal;
 698            }
 699        }
 700        _position += len;
 701    }
 702
 703    public ByteBuffer putDouble(double val)
 704    {
 705        checkOverflow(8);
 706        _valBytes.doubleVal = val;
 707        if (_order == NativeOrder._o)
 708        {
 709            _bytes[_position] = _valBytes.b0;
 710            _bytes[_position + 1] = _valBytes.b1;
 711            _bytes[_position + 2] = _valBytes.b2;
 712            _bytes[_position + 3] = _valBytes.b3;
 713            _bytes[_position + 4] = _valBytes.b4;
 714            _bytes[_position + 5] = _valBytes.b5;
 715            _bytes[_position + 6] = _valBytes.b6;
 716            _bytes[_position + 7] = _valBytes.b7;
 717        }
 718        else
 719        {
 720            _bytes[_position + 7] = _valBytes.b0;
 721            _bytes[_position + 6] = _valBytes.b1;
 722            _bytes[_position + 5] = _valBytes.b2;
 723            _bytes[_position + 4] = _valBytes.b3;
 724            _bytes[_position + 3] = _valBytes.b4;
 725            _bytes[_position + 2] = _valBytes.b5;
 726            _bytes[_position + 1] = _valBytes.b6;
 727            _bytes[_position] = _valBytes.b7;
 728        }
 729        _position += 8;
 730        return this;
 731    }
 732
 733    public ByteBuffer putDoubleSeq(double[] seq)
 734    {
 735        int len = System.Buffer.ByteLength(seq);
 736        checkOverflow(len);
 737        if (_order == NativeOrder._o)
 738        {
 739            System.Buffer.BlockCopy(seq, 0, _bytes, _position, len);
 740        }
 741        else
 742        {
 743            for (int i = 0; i < seq.Length; ++i)
 744            {
 745                int index = _position + (i * 8);
 746                _valBytes.doubleVal = seq[i];
 747                _bytes[index + 7] = _valBytes.b0;
 748                _bytes[index + 6] = _valBytes.b1;
 749                _bytes[index + 5] = _valBytes.b2;
 750                _bytes[index + 4] = _valBytes.b3;
 751                _bytes[index + 3] = _valBytes.b4;
 752                _bytes[index + 2] = _valBytes.b5;
 753                _bytes[index + 1] = _valBytes.b6;
 754                _bytes[index] = _valBytes.b7;
 755            }
 756        }
 757        _position += len;
 758        return this;
 759    }
 760
 761    public byte[] rawBytes() => _bytes;
 762
 763    private void checkUnderflow(int size)
 764    {
 765        if (_position + size > _limit)
 766        {
 767            throw new InvalidOperationException("buffer underflow");
 768        }
 769    }
 770
 771    private void checkUnderflow(int pos, int size)
 772    {
 773        if (pos + size > _limit)
 774        {
 775            throw new InvalidOperationException("buffer underflow");
 776        }
 777    }
 778
 779    private void checkOverflow(int size)
 780    {
 781        if (_position + size > _limit)
 782        {
 783            throw new InvalidOperationException("buffer overflow");
 784        }
 785    }
 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) =>
 806        throw new ArgumentOutOfRangeException(param, value, message);
 807}

Methods/Properties

.cctor()
.ctor()