Ejemplo n.º 1
0
        public static void init_token_info(ref token_info info)
        {
            int num = 23;

            int[]  name_lens     = { 0, 12, 0, 11, 0, 6, 0, 7, 0, 8, 0, 5, 0, 6, 0, 6, 0, 15, 0, 4, 0, 4, 0 };
            string str_long_name = "magic numberUDP SegmentHeaderVersionData_LenH_LenIP_SrcIP_DesHeader_ChecksumFlagData";

            char[]       long_name = str_long_name.ToCharArray();
            jsmntype_t[] types = { jsmntype_t.JSMN_OBJECT, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_OBJECT, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_OBJECT, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_STRING, jsmntype_t.JSMN_STRING };
            int[]        sons = { 2, 1, 0, 1, 2, 1, 7, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 };
            int          name_pos = 0;
            int          name_i, i;

            info.num = num;
            for (i = 0; i < info.num; i++)
            {
                info.name_lens[i] = name_lens[i];
                info.types[i]     = types[i];
                info.sons[i]      = sons[i];
            }
            for (name_i = 0; name_i < num; name_i++)
            {
                info.names[name_i] = new char[24];
                for (i = 0; i < name_lens[name_i]; i++)
                {
                    info.names[name_i][i] = long_name[name_pos];
                    name_pos++;
                }
                info.names[name_i][name_lens[name_i]] = '\0';
            }
        }
Ejemplo n.º 2
0
        public void decode(char[] input, ref JsonData jsonData, ref char[] data)
        {
            int data_in_i = 0;

            char[][] key = new char[1][];

            token_info info = new token_info();

            token_info.init_token_info(ref info);
            this.build_decoded(input, ref data_in_i, info, ref jsonData, 0);

            this.jsFileParser.init_token(ref jsonData);

            int i = 0;

            while (input[data_in_i + i] != '\0')
            {
                data[i] = input[data_in_i + i];
                i++;
            }
            data[i] = '\0';
            key[0]  = "Data\0".ToCharArray();



            this.jsFileParser.set_jsfile_single_value(data, key, 1, ref jsonData);
        }
Ejemplo n.º 3
0
        public void init_json_packet(ref JsonData jsonData)
        {
            char[]     zero_values = new char[JsFileParser.MAXPACKETSIZE * 2];
            int        i;
            token_info info = new token_info();

            token_info.init_token_info(ref info);

            for (i = 0; i < JsFileParser.MAXPACKETSIZE; i++)
            {
                zero_values[2 * i]     = '0';
                zero_values[2 * i + 1] = '\0';
            }
            //this.build_packetPrepare();
            jsonData.content_size = this.build_packet(zero_values, info, jsonData.content, 0);

            jsonData.content[jsonData.content_size] = '\0';
            this.jsFileParser.init_token(ref jsonData);
            //this.jsFileParser.init_token(packet_buffer,  ref token_size, ref token_buffer);
        }
Ejemplo n.º 4
0
        public int build_packet(char[] input, token_info info, char[] packet, int tab_num)
        {
            if (info_i == info.num)
            {
                return(packet_i);
            }
            int packet_size = 0;
            int i;
            int son;

            if (tab_num != 0)
            {
                Coder.arr_putc('\n', packet, ref packet_i);
            }
            for (i = 0; i < tab_num; i++)
            {
                Coder.arr_putc('\t', packet, ref packet_i);
            }
            if (info.name_lens[info_i] != 0)
            {
                Coder.arr_putc('"', packet, ref packet_i);
                Coder.arr_puts(info.names[info_i], packet, ref packet_i);
                Coder.arr_putc('"', packet, ref packet_i);
            }
            switch (info.types[info_i])
            {
            case jsmntype_t.JSMN_OBJECT:
                son = info.sons[info_i];
                Coder.arr_putc('{', packet, ref packet_i);
                for (i = 0; i < son; i++)
                {
                    info_i++;
                    build_packet(input, info, packet, tab_num + 1);
                    if (i != son - 1)
                    {
                        Coder.arr_putc(',', packet, ref packet_i);
                    }
                }
                Coder.arr_putc('\n', packet, ref packet_i);
                for (i = 0; i < tab_num; i++)
                {
                    Coder.arr_putc('\t', packet, ref packet_i);
                }
                Coder.arr_putc('}', packet, ref packet_i);

                if (tab_num == 0)
                {
                    packet_size   = this.packet_i;
                    this.packet_i = 0;
                    this.info_i   = 0;
                    this.in_i     = 0;
                }

                break;

            case jsmntype_t.JSMN_ARRAY:
                son = info.sons[info_i];
                Coder.arr_putc('[', packet, ref packet_i);
                for (i = 0; i < son; i++)
                {
                    info_i++;
                    build_packet(input, info, packet, tab_num + 1);
                    if (i != son - 1)
                    {
                        Coder.arr_putc(',', packet, ref packet_i);
                    }
                }
                Coder.arr_putc('\n', packet, ref packet_i);
                for (i = 0; i < tab_num; i++)
                {
                    Coder.arr_putc('\t', packet, ref packet_i);
                }
                Coder.arr_putc(']', packet, ref packet_i);
                break;

            default:
                if (info.sons[info_i] == 1)
                {
                    Coder.arr_putc(':', packet, ref packet_i);
                    if (info.types[info_i + 1] == jsmntype_t.JSMN_OBJECT || info.types[info_i + 1] == jsmntype_t.JSMN_ARRAY)
                    {
                        info_i++;
                        build_packet(input, info, packet, tab_num);
                    }
                    else
                    {
                        Coder.in_arr_puts(input, ref in_i, packet, ref packet_i);
                        info_i++;
                    }
                }
                break;
            }
            return(packet_size);
        }
Ejemplo n.º 5
0
        private void build_decoded(char[] input, ref int data_in_i, token_info info, ref JsonData jsonData, int tab_num)
        {
            //static int decoded_i = 0, info_i = 0, in_i = 0;

            //char[] decoded, ref int decoded_len

            char[] decoded = jsonData.content;

            int i;
            int son;

            if (info_i == info.num)
            {
                return;
            }

            if (tab_num != 0)
            {
                Coder.arr_putc('\n', decoded, ref decoded_i);
            }

            for (i = 0; i < tab_num; i++)
            {
                Coder.arr_putc('\t', decoded, ref decoded_i);
            }

            if (info.name_lens[info_i] != 0)
            {
                Coder.arr_putc('"', decoded, ref decoded_i);
                Coder.arr_puts(info.names[info_i], decoded, ref decoded_i);
                Coder.arr_putc('"', decoded, ref decoded_i);
            }

            switch (info.types[info_i])
            {
            case jsmntype_t.JSMN_OBJECT:
                son = info.sons[info_i];
                Coder.arr_putc('{', decoded, ref decoded_i);
                for (i = 0; i < son; i++)
                {
                    info_i++;
                    this.build_decoded(input, ref data_in_i, info, ref jsonData, tab_num + 1);
                    if (i != son - 1)
                    {
                        Coder.arr_putc(',', decoded, ref decoded_i);
                    }
                }
                Coder.arr_putc('\n', decoded, ref decoded_i);
                for (i = 0; i < tab_num; i++)
                {
                    Coder.arr_putc('\t', decoded, ref decoded_i);
                }
                Coder.arr_putc('}', decoded, ref decoded_i);
                if (tab_num == 0)
                {
                    jsonData.content_size = decoded_i;
                    data_in_i             = in_i;
                    decoded_i             = 0;
                    info_i = 0;
                    in_i   = 0;
                }
                break;

            case jsmntype_t.JSMN_ARRAY:
                son = info.sons[info_i];
                Coder.arr_putc('[', decoded, ref decoded_i);
                for (i = 0; i < son; i++)
                {
                    info_i++;
                    build_decoded(input, ref data_in_i, info, ref jsonData, tab_num + 1);
                    if (i != son - 1)
                    {
                        Coder.arr_putc(',', decoded, ref decoded_i);
                    }
                }
                Coder.arr_putc('\n', decoded, ref decoded_i);
                for (i = 0; i < tab_num; i++)
                {
                    Coder.arr_putc('\t', decoded, ref decoded_i);
                }
                Coder.arr_putc(']', decoded, ref decoded_i);
                break;

            default:
                if (info.sons[info_i] == 1)
                {
                    Coder.arr_putc(':', decoded, ref decoded_i);
                    if (info.types[info_i + 1] == jsmntype_t.JSMN_OBJECT || info.types[info_i + 1] == jsmntype_t.JSMN_ARRAY)
                    {
                        info_i++;
                        build_decoded(input, ref data_in_i, info, ref jsonData, tab_num);
                    }
                    else
                    {
                        if (jsFileParser.strcmp(info.names[info_i], "Data\0".ToCharArray()) == 0)
                        {
                            Coder.arr_putc('0', decoded, ref decoded_i);
                        }
                        else
                        {
                            in_arr_puts(input, ref in_i, decoded, ref decoded_i);
                        }
                        info_i++;
                    }
                }
                break;
            }
            return;
        }