コード例 #1
0
        public override void Encode()
        {
            base.Encode();

            BinaryStream stream = new BinaryStream();

            int records = 0;
            int count   = this.Packets.Length;

            if (count > 1)
            {
                Array.Reverse(this.Packets);
            }

            if (count > 0)
            {
                int pointer = 1;
                int start   = this.Packets[0];
                int last    = this.Packets[0];

                while (pointer < count)
                {
                    int current = this.Packets[pointer++];
                    int diff    = current - last;
                    if (diff == 1)
                    {
                        last = current;
                    }
                    else if (diff > 1)
                    {
                        if (start == last)
                        {
                            stream.WriteByte(1);
                            stream.WriteLTriad(start);
                            start = last = current;
                        }
                        else
                        {
                            stream.WriteByte(0);
                            stream.WriteLTriad(start);
                            stream.WriteLTriad(last);
                            start = last = current;
                        }
                        ++records;
                    }
                }

                if (start == last)
                {
                    stream.WriteByte(1);
                    stream.WriteLTriad(start);
                }
                else
                {
                    stream.WriteByte(0);
                    stream.WriteLTriad(start);
                    stream.WriteLTriad(last);
                }
                ++records;
            }

            this.WriteShort((short)records);
            this.WriteBytes(stream.ToArray());

            stream.Clone();
        }