Exemplo n.º 1
0
        internal int DecodeScalar(DataPacket packet)
        {
            var bits = (int)packet.TryPeekBits(PrefixBitLength, out var 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);
        }