Example #1
0
        private int set_msg_buffer(List <Field_Info> info_list, Bit_Buffer buffer, JObject jobject)
        {
            foreach (Field_Info info in info_list)
            {
                if (info.field_label == "arg")
                {
                    JValue obj = (JValue)jobject[info.field_name];
                    set_arg_buffer(info, buffer, obj);
                }
                else if (info.field_label == "vector")
                {
                    JArray jarray = (JArray)jobject[info.field_name];
                    set_vector_buffer(info, buffer, jarray);
                }
                else if (info.field_label == "struct")
                {
                    JObject obj = (JObject)jobject[info.field_name];
                    set_struct_buffer(info, buffer, obj);
                }
                else if (info.field_label == "if")
                {
                    buffer.write_bool(true);
                    int ret = set_msg_buffer(info.field_list, buffer, jobject);
                    if (ret < 0)
                    {
                        return(ret);
                    }
                }
                else if (info.field_label == "switch")
                {
                    uint case_val = uint.Parse(jobject[info.field_name].ToString());
                    buffer.write_uint(case_val, info.field_bit);

                    foreach (Field_Info sub_info in info.field_list)
                    {
                        if (sub_info.field_label == "case" && sub_info.case_val == case_val)
                        {
                            //找到对应的case标签,对case标签内的child数组进行build
                            int ret = set_msg_buffer(sub_info.field_list, buffer, jobject);
                            if (ret < 0)
                            {
                                return(ret);
                            }
                            break;
                        }
                    }
                }
            }
            return(0);
        }
Example #2
0
 private int set_arg_buffer(Field_Info info, Bit_Buffer buffer, JValue value)
 {
     if (info.field_type == "int")
     {
         int val = int.Parse(value.ToString());
         buffer.write_int(val, info.field_bit);
     }
     else if (info.field_type == "uint")
     {
         uint val = uint.Parse(value.ToString());
         buffer.write_uint(val, info.field_bit);
     }
     else if (info.field_type == "int64")
     {
         long val = long.Parse(value.ToString());
         buffer.write_int64(val);
     }
     else if (info.field_type == "uint64")
     {
         ulong val = ulong.Parse(value.ToString());
         buffer.write_uint64(val);
     }
     else if (info.field_type == "float")
     {
         float val = float.Parse(value.ToString());
         buffer.write_decimal(val, 32);
     }
     else if (info.field_type == "bool")
     {
         bool val = bool.Parse(value.ToString());
         buffer.write_bool(val);
     }
     else if (info.field_type == "string")
     {
         string val = value.ToString();
         buffer.write_string(val);
     }
     return(0);
 }