Exemplo n.º 1
0
        public static void WriteIntBlock(BufferedWriter writer, int[] values, int length)
        {
            int byteLength = 4 * length;

            writer.EnsureSpace(byteLength);
            Buffer.BlockCopy(values, 0, writer.Buffer, writer.Index, byteLength);
            writer.Index += byteLength;
        }
Exemplo n.º 2
0
 public static void Write(this BufferedWriter writer, int value)
 {
     writer.EnsureSpace(4);
     writer.Buffer[writer.Index + 0] = (byte)value;
     writer.Buffer[writer.Index + 1] = (byte)(value >> 8);
     writer.Buffer[writer.Index + 2] = (byte)(value >> 16);
     writer.Buffer[writer.Index + 3] = (byte)(value >> 24);
     writer.Index += 4;
 }
Exemplo n.º 3
0
        /// <summary>
        ///  Write value as a fixed length, 7-bit encoded integer.
        ///  All bytes start with a zero bit.
        /// </summary>
        /// <param name="value">Value to write</param>
        /// <param name="length">Byte length to write</param>
        /// <param name="writer">BufferedWriter to write to</param>
        public static void WriteSevenBitFixed(BufferedWriter writer, ulong value, int length)
        {
            writer.EnsureSpace(length);

            for (int i = 0; i < length; ++i)
            {
                writer.Buffer[writer.Index++] = (byte)(value & 0x7F);
                value = value >> 7;
            }
        }
Exemplo n.º 4
0
        public NumberBlockWriter(BufferedWriter writer, int blockSize)
        {
            if (blockSize % 4 != 0)
            {
                throw new ArgumentException("blockSize must be a multiple of 4.");
            }
            BlockSize = blockSize;

            _writer      = writer;
            _buffer      = new int[blockSize];
            _bufferCount = 0;
        }
Exemplo n.º 5
0
        /// <summary>
        ///  Write value as a variable length, 6-bit encoded integer.
        ///  All bytes start with a zero bit. The last byte starts with
        ///  01, the others start with 00.
        /// </summary>
        /// <param name="value">Value to write</param>
        /// <param name="writer">BufferedWriter to write to</param>
        public static void WriteSixBitTerminated(BufferedWriter writer, ulong value)
        {
            writer.EnsureSpace(11);

            while (value > 0x3F)
            {
                writer.Buffer[writer.Index++] = (byte)(value & 0x3F);
                value = value >> 6;
            }

            writer.Buffer[writer.Index++] = (byte)(value | 0x40);
        }
Exemplo n.º 6
0
        /// <summary>
        ///  Write value as a variable length, 7-bit encoded integer.
        ///  The last byte has a leading one bit, the others don't.
        /// </summary>
        /// <param name="value">Value to write</param>
        /// <param name="writer">BufferedWriter to write to</param>
        public static void WriteSevenBitTerminated(BufferedWriter writer, ulong value)
        {
            writer.EnsureSpace(10);

            while (value > 0x7F)
            {
                writer.Buffer[writer.Index++] = (byte)(value & 0x7F);
                value = value >> 7;
            }

            writer.Buffer[writer.Index++] = (byte)(value | 0x80);
        }
Exemplo n.º 7
0
        /// <summary>
        ///  Write value as a variable length, 7-bit encoded integer.
        ///  All bytes begin with a 0 bit.
        ///  The length is returned separately and must be known to read.
        /// </summary>
        /// <param name="value">Value to write</param>
        /// <param name="writer">BufferedWriter to write to</param>
        public static byte WriteSevenBitExplicit(BufferedWriter writer, ulong value)
        {
            writer.EnsureSpace(10);

            int start = writer.Index;

            while (value > 0x7F)
            {
                writer.Buffer[writer.Index++] = (byte)(value & 0x7F);
                value = value >> 7;
            }

            writer.Buffer[writer.Index++] = (byte)(value);
            return((byte)(writer.Index - start));
        }
Exemplo n.º 8
0
 public void Dispose()
 {
     _writer?.Dispose();
     _writer = null;
 }