Ejemplo n.º 1
0
        public static void Decode(List <byte> bytes, int offset, int count,
                                  Action <bool> bitProceed)
        {
            for (int i = 0; i < count;)
            {
                byte leadB = bytes[offset + i];

                if (BitWise.Bit(leadB, 7) == 1)
                {
                    for (int b = 0; b < 7; b++)
                    {
                        bitProceed(BitWise.Bit(leadB, b) == 1);
                    }
                    i++;
                }
                else
                {
                    byte indexLB = bytes[offset + i + 1];
                    if (BitWise.Bit(indexLB, 7) == 0)
                    {
                        for (int cnt = 0; cnt < indexLB; cnt++)
                        {
                            for (int b = 0; b < 7; b++)
                            {
                                bitProceed(BitWise.Bit(leadB, b) == 1);
                            }
                        }
                        i += 2;
                    }
                    else
                    {
                        byte indexHB = bytes[offset + i + 2];
                        BitWise.ClearBit(ref indexLB, 7);
                        var l = BitConverter.ToUInt16(new byte[] { indexLB, indexHB }, 0);

                        for (int cnt = 0; cnt < l; cnt++)
                        {
                            for (int b = 0; b < 7; b++)
                            {
                                bitProceed(BitWise.Bit(leadB, b) == 1);
                            }
                        }

                        i += 3;
                    }
                }
            }
        }
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);
        }