Exemple #1
0
        public override Object Decode(DecodeBuffer input)
        {
            var v = input.ReadByte();

            switch (v)
            {
            case Zero: return(false);

            case One: return(true);

            case Two: return(null);

            default: throw new SchemaMismatchException($"Boolean value must be either {Zero}, {One} or {Two}, but {v} given.");
            }
        }
Exemple #2
0
        public static UInt64 Decode(DecodeBuffer input)
        {
#if DEBUG
            if (null == input)
            {
                throw new ArgumentNullException(nameof(input));
            }
#endif


            // Setup symbol
            UInt64 symbol = 0;
            var    bit    = 0;

            Int32 b;
            do
            {
                // Read byte
                b = input.ReadByte();

                // Add input bits to output
                var chunk = (UInt64)(b & Mask);
                var pre   = symbol;
                symbol += (chunk + 1) << bit;

#if DEBUG
                // Check for overflow
                if (symbol < pre)
                {
                    throw new OverflowException($"Symbol is corrupt, or larger than maximum supported value {UnsignedVlq.MaxValue}.");
                }
#endif

                // Increment bit offset
                bit += PacketSize;
            } while ((b & More) > 0); // If not final byte

            // Remove zero offset
            symbol--;

            // Add to output
            return(symbol);
        }