Пример #1
0
            public c_packet(c_bit_reader bits, ref UInt64 total_bits_read)
            {
                version = bits.read_number(3, ref total_bits_read);
                type_id = bits.read_number(3, ref total_bits_read);

                if (type_id == k_type_integer)
                {
                    value = new c_packet_integer_value(bits, ref total_bits_read);
                }
                else
                {
                    value = new c_packet_operator_value(bits, type_id, ref total_bits_read);
                }
            }
Пример #2
0
            public c_packet_integer_value(c_bit_reader bits, ref UInt64 total_bits_read)
            {
                payload = 0;

                bool continue_reading = true;

                while (continue_reading)
                {
                    continue_reading = bits.read_bit(ref total_bits_read);

                    payload = (payload << 4);

                    payload = (payload | bits.read_number(4, ref total_bits_read));
                }
            }
Пример #3
0
            public c_packet_operator_value(c_bit_reader bits, UInt64 type_id, ref UInt64 total_bits_read)
            {
                sub_packets = new List <c_packet>();

                if (bits.read_bit(ref total_bits_read))
                {
                    UInt64 sub_packet_count = bits.read_number(11, ref total_bits_read);

                    for (UInt64 i = 0; i < sub_packet_count; i++)
                    {
                        sub_packets.Add(new c_packet(bits, ref total_bits_read));
                    }
                }
                else
                {
                    UInt64 sub_packet_size = bits.read_number(15, ref total_bits_read);

                    UInt64 sub_packets_bits_read = 0;
                    while (sub_packet_size - sub_packets_bits_read >= c_packet.k_min_bit_count)
                    {
                        sub_packets.Add(new c_packet(bits, ref sub_packets_bits_read));
                    }
                    total_bits_read += sub_packets_bits_read;

                    bits.discard((int)(sub_packet_size - sub_packets_bits_read), ref total_bits_read);
                }

                switch (type_id)
                {
                case 0: operator_type = e_packet_operator_type.sum; break;

                case 1: operator_type = e_packet_operator_type.product; break;

                case 2: operator_type = e_packet_operator_type.min; break;

                case 3: operator_type = e_packet_operator_type.max; break;

                case 5: operator_type = e_packet_operator_type.greater_than; break;

                case 6: operator_type = e_packet_operator_type.less_than; break;

                case 7: operator_type = e_packet_operator_type.equal_to; break;
                }
            }