Esempio n. 1
0
        /// <summary>
        ///  Read the next bytes from the reader as a variable length,
        ///  7-bit encoded integer.
        /// </summary>
        /// <param name="reader">BufferedReader to read from</param>
        /// <returns>Value read</returns>
        public static ulong ReadSevenBitTerminated(BufferedReader reader)
        {
            reader.EnsureSpace(10);

            ulong value = 0;
            int   current = 0, shift = 0;

            while (current <= 0x7F)
            {
                current = reader.Buffer[reader.Index++];
                value  += (ulong)(current & 0x7F) << shift;
                shift  += 7;
            }

            return(value);
        }
Esempio n. 2
0
        /// <summary>
        ///  Read the next bytes from the reader as a variable length,
        ///  6-bit encoded integer.
        /// </summary>
        /// <param name="reader">BufferedReader to read from</param>
        /// <returns>Value read</returns>
        public static int ReadSixBitTerminatedBlock(BufferedReader reader, ulong[] block)
        {
            reader.EnsureSpace(block.Length * 11);

            int index = 0;

            while (index < block.Length && !reader.EndOfStream)
            {
                ulong value = 0;
                int   current = 0, shift = 0;

                while (current <= 0x3F)
                {
                    current = reader.Buffer[reader.Index++];
                    value  += (ulong)(current & 0x3F) << shift;
                    shift  += 6;
                }

                block[index++] = value;
            }

            return(index);
        }
Esempio n. 3
0
 public void Dispose()
 {
     _reader?.Dispose();
     _reader = null;
 }
Esempio n. 4
0
 /// <summary>
 ///  Construct a BufferedReader to read a String8 value.
 /// </summary>
 /// <param name="text">String8 to read</param>
 /// <returns>BufferedReader reading String8 value only</returns>
 public static BufferedReader FromString(String8 text)
 {
     return(BufferedReader.FromArray(text.Array, text.Index, text.Length));
 }