WriteUInt64() public static method

public static WriteUInt64 ( byte array, int offset, ulong value ) : void
array byte
offset int
value ulong
return void
Ejemplo n.º 1
0
        /// <summary>
        ///  Writes the compact encoding of value to a destination byte array, starting at offset.
        /// </summary>
        /// <returns>The number of bytes written to destination.</returns>
        public static int WriteCompact(byte[] destination, int offset, ulong value)
        {
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }

            if (value < 0xfd)
            {
                destination[offset] = (byte)value;
                return(1);
            }
            else if (value <= ushort.MaxValue)
            {
                destination[offset] = 0xfd;
                LittleEndian.WriteUInt16(destination, offset + 1, (ushort)value);
                return(3);
            }
            else if (value <= uint.MaxValue)
            {
                destination[offset] = 0xfe;
                LittleEndian.WriteUInt32(destination, offset + 1, (uint)value);
                return(5);
            }
            else
            {
                destination[offset] = 0xff;
                LittleEndian.WriteUInt64(destination, offset + 1, value);
                return(9);
            }
        }
Ejemplo n.º 2
0
 public void WriteUInt64(ulong value)
 {
     LittleEndian.WriteUInt64(_array, _cursor, value);
     _cursor += 8;
 }