Ejemplo n.º 1
0
        public IoElement Decode(IBitReader reader)
        {
            byte num1 = reader != null?reader.ReadByte() : throw new ArgumentNullException(nameof(reader));

            int num2 = 0;
            int id   = 0;
            List <IoProperty> properties = new List <IoProperty>(num1);

            while (num2 < num1)
            {
                bool bit;
                if (reader.ReadBit(out bit) != 1)
                {
                    throw new EndOfStreamException();
                }
                if (bit)
                {
                    long bits1;
                    if (reader.ReadBits(out bits1, 3) < 3)
                    {
                        throw new EndOfStreamException();
                    }
                    if (bits1 == 0L)
                    {
                        long bits2;
                        if (reader.ReadBits(out bits2, 1) < 1)
                        {
                            throw new EndOfStreamException();
                        }
                        properties.Add(IoProperty.Create(id, (byte)bits2));
                    }
                    else
                    {
                        if (bits1 != 1L)
                        {
                            throw new Exception("Unknown type");
                        }
                        long bits2;
                        if (reader.ReadBits(out bits2, 32) < 32)
                        {
                            throw new EndOfStreamException();
                        }
                        properties.Add(IoProperty.Create(id, (int)bits2));
                    }
                    ++num2;
                }
                ++id;
            }
            return(new IoElement(0, properties));
        }
Ejemplo n.º 2
0
 public static int ReadBitSequence(IBitReader reader, out long value, int length)
 {
     value = 0L;
     for (int index = 0; index < length; ++index)
     {
         bool bit;
         if (reader.ReadBit(out bit) != 1)
         {
             return(index);
         }
         long num = (bit ? 1L : 0L) << index;
         value |= num;
     }
     return(length);
 }
Ejemplo n.º 3
0
    public char DecodeChar(IBitReader reader)
    {
        var current = Root;

        while (!(current?.IsLeaf() ?? true))
        {
            if (reader.ReadBit())
            {
                if (current.Right is not null)
                {
                    current = current.Right;
                }
            }
            else
            {
                if (current.Left is not null)
                {
                    current = current.Left;
                }
            }
        }
        return(current?.Symbol ?? '\0');
    }
Ejemplo n.º 4
0
        public AvlData[] Decode(IBitReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            long y2Ktime;

            if (ReadBitSequence(reader, out y2Ktime, 35) != 35)
            {
                throw new Exception("Wrong timestamp bits count");
            }
            long timestamp = Y2K2Timestamp(y2Ktime);
            long bits;

            if (reader.ReadBits(out bits, 5) != 5)
            {
                throw new Exception("Wrong element count bits count");
            }
            long           num1           = Math.Min(bits, 24L);
            List <AvlData> avlDataList    = new List <AvlData>();
            long           compressedGws1 = 0;
            long           compressedGws2 = 0;

            for (int index = 0; index < num1; ++index)
            {
                bool bit1;
                if (reader.ReadBit(out bit1) != 1)
                {
                    throw new Exception("Wrong data bits count");
                }
                if (bit1)
                {
                    bool bit2;
                    if (reader.ReadBit(out bit2) != 1)
                    {
                        throw new Exception("Wrong data bits count");
                    }
                    if (bit2)
                    {
                        long num2;
                        if (ReadBitSequence(reader, out num2, 14) != 14)
                        {
                            throw new Exception("Wrong data bits count");
                        }
                        long num3;
                        if (ReadBitSequence(reader, out num3, 14) != 14)
                        {
                            throw new Exception("Wrong data bits count");
                        }
                        compressedGws1 = compressedGws1 - num2 + 8191L;
                        compressedGws2 = compressedGws2 - num3 + 8191L;
                    }
                    else
                    {
                        if (ReadBitSequence(reader, out compressedGws1, 21) != 21)
                        {
                            throw new Exception("Wrong data bits count");
                        }
                        if (ReadBitSequence(reader, out compressedGws2, 20) != 20)
                        {
                            throw new Exception("Wrong data bits count");
                        }
                    }
                    long    num4    = DecompressGws(compressedGws1, -1800000000L, 1800000000L, 3600000000L, 2097151L);
                    long    num5    = DecompressGws(compressedGws2, -900000000L, 900000000L, 1800000000L, 1048575L);
                    short   speed   = reader.ReadByte();
                    AvlData avlData = new AvlData(AvlDataPriority.Low, DateTimeExt.FromAvl(timestamp), new GpsElement((int)num4, (int)num5, 0, speed, 0, 3));
                    avlDataList.Add(avlData);
                }
                timestamp += 3600000L;
            }
            return(avlDataList.ToArray());
        }
        public void TestThatReadBitCallsInputStreamReadByteOnce()
        {
            bitReader.ReadBit();

            inputStreamMock.Verify(x => x.ReadByte(), Times.Once);
        }