public ulong TakeUnsignedBE(out ulong value, uint length) { if (CheckAvailable(length)) { value = BufferIO.BytesToUIntBE(_packetBuffer, _pos, length); _pos += length; return(value); } throw _bufferErr; }
public byte[] TakeBytes(out byte[] value, Prefix prefixFlag) { uint length; bool reduce = (prefixFlag & Prefix.WithPrefix) > 0; uint preLen = ((uint)prefixFlag) & 15; switch (preLen) { case 0: // Read to end. length = (uint)(_packetLength - _pos); break; case 1: case 2: case 4: if (CheckAvailable(preLen)) { length = (uint)BufferIO.BytesToUIntBE(_packetBuffer, _pos, preLen); _pos += preLen; if (reduce) { if (length < preLen) { throw new IOException("Data length is less than prefix length."); } length -= preLen; } break; } throw _bufferErr; default: throw new ArgumentOutOfRangeException("Invalid prefix flag."); } if (CheckAvailable(length)) { value = new byte[length]; Buffer.BlockCopy(_packetBuffer, (int)_pos, value, 0, (int)length); _pos += length; return(value); } throw _bufferErr; }