TryPeekBits() public method

Attempts to read the specified number of bits from the packet, but may return fewer. Does not advance the position counter.
is not between 0 and 64.
public TryPeekBits ( int count, int &bitsRead ) : ulong
count int The number of bits to attempt to read.
bitsRead int The number of bits actually read.
return ulong
Beispiel #1
0
        internal int DecodeScalar(DataPacket packet)
        {
            int bitCnt;
            var bits = (int)packet.TryPeekBits(PrefixBitLength, out bitCnt);

            if (bitCnt == 0)
            {
                return(-1);
            }

            // try to get the value from the prefix list...
            var node = PrefixList[bits];

            if (node != null)
            {
                packet.SkipBits(node.Length);
                return(node.Value);
            }

            // nope, not possible... run the tree
            bits = (int)packet.TryPeekBits(MaxBits, out bitCnt);

            node = PrefixOverflowTree;
            do
            {
                if (node.Bits == (bits & node.Mask))
                {
                    packet.SkipBits(node.Length);
                    return(node.Value);
                }
            } while ((node = node.Next) != null);
            return(-1);
        }
        internal int DecodeScalar(DataPacket packet)
        {
            int index = (int)packet.TryPeekBits(PrefixBitLength, out int bitsRead);

            if (bitsRead == 0)
            {
                return(-1);
            }
            HuffmanListNode huffmanListNode = PrefixList[index];

            if (huffmanListNode != null)
            {
                packet.SkipBits(huffmanListNode.Length);
                return(huffmanListNode.Value);
            }
            index           = (int)packet.TryPeekBits(MaxBits, out bitsRead);
            huffmanListNode = PrefixOverflowTree;
            do
            {
                if (huffmanListNode.Bits == (index & huffmanListNode.Mask))
                {
                    packet.SkipBits(huffmanListNode.Length);
                    return(huffmanListNode.Value);
                }
            }while ((huffmanListNode = huffmanListNode.Next) != null);
            return(-1);
        }
Beispiel #3
0
        internal int DecodeScalar(DataPacket packet)
        {
            int bitCnt;
            var bits = (int)packet.TryPeekBits(PrefixBitLength, out bitCnt);
            if (bitCnt == 0) return -1;

            // try to get the value from the prefix list...
            var node = PrefixList[bits];
            if (node != null)
            {
                packet.SkipBits(node.Length);
                return node.Value;
            }

            // nope, not possible... run the tree
            bits = (int)packet.TryPeekBits(MaxBits, out bitCnt);

            node = PrefixOverflowTree;
            do
            {
                if (node.Bits == (bits & node.Mask))
                {
                    packet.SkipBits(node.Length);
                    return node.Value;
                }
            } while ((node = node.Next) != null);
            return -1;
        }
Beispiel #4
0
        internal int DecodeScalar(DataPacket packet)
        {
            // try to get as many bits as possible...
            int bitCnt; // we really don't care how many bits were read; try to decode anyway...
            var bits = (int)packet.TryPeekBits(MaxBits, out bitCnt);

            if (bitCnt == 0)
            {
                return(-1);
            }

            // now go through the list and find the matching entry
            var node = LTree;

            while (node != null)
            {
                if (node.Bits == (bits & node.Mask))
                {
                    node.HitCount++;
                    packet.SkipBits(node.Length);
                    return(node.Value);
                }
                node = node.Next;
            }
            return(-1);
        }
Beispiel #5
0
        internal int DecodeScalar(DataPacket packet)
        {
            int bitsRead;
            int num = (int)packet.TryPeekBits(this.MaxBits, out bitsRead);

            if (bitsRead == 0)
            {
                throw new InvalidDataException();
            }
            for (HuffmanListNode <int> huffmanListNode = this.LTree; huffmanListNode != null; huffmanListNode = huffmanListNode.Next)
            {
                if (huffmanListNode.Bits == (num & huffmanListNode.Mask))
                {
                    ++huffmanListNode.HitCount;
                    packet.SkipBits(huffmanListNode.Length);
                    return(huffmanListNode.Value);
                }
            }
            throw new InvalidDataException();
        }
Beispiel #6
0
        internal int DecodeScalar(DataPacket packet)
        {
            // try to get as many bits as possible...
            int bitCnt; // we really don't care how many bits were read; try to decode anyway...
            var bits = (int)packet.TryPeekBits(MaxBits, out bitCnt);
            if (bitCnt == 0) throw new InvalidDataException();

            // now go through the list and find the matching entry
            var node = LTree;
            while (node != null)
            {
                if (node.Bits == (bits & node.Mask))
                {
                    node.HitCount++;
                    packet.SkipBits(node.Length);
                    return node.Value;
                }
                node = node.Next;
            }
            throw new InvalidDataException();
        }
Beispiel #7
0
 internal int DecodeScalar(DataPacket packet)
 {
   int bitsRead;
   int num = (int) packet.TryPeekBits(this.MaxBits, out bitsRead);
   if (bitsRead == 0)
     throw new InvalidDataException();
   for (HuffmanListNode<int> huffmanListNode = this.LTree; huffmanListNode != null; huffmanListNode = huffmanListNode.Next)
   {
     if (huffmanListNode.Bits == (num & huffmanListNode.Mask))
     {
       ++huffmanListNode.HitCount;
       packet.SkipBits(huffmanListNode.Length);
       return huffmanListNode.Value;
     }
   }
   throw new InvalidDataException();
 }