コード例 #1
0
        internal int DecodeScalar(DataPacket packet)
        {
            int bits = (int)packet.TryPeekU64Bits(PrefixBitLength, out int bitCnt);

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

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

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

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

            node = PrefixOverflowTree;
            do
            {
                if (node.Bits == (bits & node.Mask))
                {
                    packet.SkipBits(node.Length);
                    return(node.Value);
                }
            } while ((node = node.Next) != null);
            return(-1);
        }