Ejemplo n.º 1
0
        private static void AddBytes(ref List <byte> result, int count, byte val)
        {
            if (count == 1)
            {
                BitWise.SetBit(ref val, 7);
                result.Add(val);
            }
            else
            {
                result.Add(val);
                if (count <= 0x7F)
                {
                    //Always keep first bit as 0
                    result.Add((byte)count);
                }
                else
                {
                    if (count > 0x7FFF)
                    {
                        throw new ArithmeticException("Длина не может превышать 32767");
                    }

                    byte[] _bytes = BitConverter.GetBytes((UInt16)count);
                    BitWise.SetBit(ref _bytes[1], 7);
                    result.Add(_bytes[1]);
                    result.Add(_bytes[0]);
                }
            }
        }
Ejemplo n.º 2
0
        public List <byte> ToBytes()
        {
            List <byte> result = new List <byte>();

            result.AddRange(BitConverter.GetBytes(Offset));

            var len = Length;

            if (EncodeSymbol)
            {
                BitWise.SetBit(ref len, 15);
            }
            else
            {
                BitWise.ClearBit(ref len, 15);
            }

            result.AddRange(BitConverter.GetBytes(len));
            return(result);
        }