public Msg_Struct(XmlNode node) { struct_name_ = node.Name; XmlAttributeCollection attrc = node.Attributes; foreach (XmlAttribute attr in attrc) { if (attr.Name == "msg_id") { msg_id_ = int.Parse(attr.Value); } else if (attr.Name == "msg_name") { msg_name_ = attr.Value; } } if (node.HasChildNodes) { XmlNodeList sub_node_list = node.ChildNodes; foreach (XmlNode sub_node in sub_node_list) { Field_Info info = init_field(sub_node); field_list_.Add(info); } } }
Field_Info init_field(XmlNode node) { Field_Info info = new Field_Info(); info.field_label = node.Name; XmlAttributeCollection attrc = node.Attributes; foreach (XmlAttribute attr in attrc) { if (attr.Name == "type") { info.field_type = attr.Value; } else if (attr.Name == "bit") { info.field_bit = int.Parse(attr.Value); } else if (attr.Name == "name") { info.field_name = attr.Value; } else if (attr.Name == "vbit") { info.field_vbit = int.Parse(attr.Value); } else if (attr.Name == "key_type") { info.key_type = attr.Value; } else if (attr.Name == "key_bit") { info.key_bit = int.Parse(attr.Value); } else if (attr.Name == "key_name") { info.key_name = attr.Value; } else if (attr.Name == "val") { info.case_val = int.Parse(attr.Value); } } if (info.field_label == "if" || info.field_label == "switch" || info.field_label == "case") { if (node.HasChildNodes) { XmlNodeList sub_node_list = node.ChildNodes; foreach (XmlNode sub_node in sub_node_list) { Field_Info sub_field = init_field(sub_node); info.field_list.Add(sub_field); } } } return(info); }
private int set_struct_buffer(Field_Info info, Bit_Buffer buffer, JObject jobject) { Msg_Struct msg = Struct_Manager.instance.get_msg_struct(info.field_type); if (msg == null) { return(-1); } set_msg_buffer(msg.field_list, buffer, jobject); return(0); }
private string get_arg_string(Field_Info info, Bit_Buffer buffer, bool from_vector = false) { string ret = ""; if (!from_vector) { ret = (info.field_name + ":"); } if (info.field_type == "int") { int val = buffer.read_int(info.field_bit); ret += val.ToString(); } else if (info.field_type == "uint") { uint val = buffer.read_uint(info.field_bit); ret += val.ToString(); } else if (info.field_type == "int64") { long val = buffer.read_int64(); ret += val.ToString(); } else if (info.field_type == "uint64") { ulong val = buffer.read_uint64(); ret += val.ToString(); } else if (info.field_type == "float") { float val = buffer.read_decimal(32); ret += val.ToString(); } else if (info.field_type == "bool") { bool val = buffer.read_bool(); ret += val.ToString(); } else if (info.field_type == "string") { string val = buffer.read_string(); ret += "\"" + val + "\""; } return(ret + ", "); }
private int set_vector_buffer(Field_Info info, Bit_Buffer buffer, JArray jarray) { int ret = 0; uint length = (uint)jarray.Count; buffer.write_uint(length, info.field_vbit); for (int i = 0; i < (int)length; ++i) { if (is_struct(info.field_type)) { ret = set_struct_buffer(info, buffer, (JObject)jarray[i]); } else { ret = set_arg_buffer(info, buffer, (JValue)jarray[i]); } } return(0); }
private string get_struct_string(Field_Info info, Bit_Buffer buffer, bool from_vector = false) { string ret = "{"; if (!from_vector) { ret = (info.field_name + ":{"); } Msg_Struct msg = Struct_Manager.instance.get_msg_struct(info.field_type); string msg_str = msg.get_print_msg(msg.field_list, buffer); if (msg_str != "") { msg_str = msg_str.Substring(0, msg_str.Length - 2); } ret += msg_str; return(ret + "}, "); }
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); }
private string get_vector_string(Field_Info info, Bit_Buffer buffer) { string ret = info.field_name + ":["; uint length = buffer.read_uint(info.field_vbit); for (uint i = 0; i < length; ++i) { if (is_struct(info.field_type)) { ret += get_struct_string(info, buffer, true); } else { ret += get_arg_string(info, buffer, true); } } if (length > 0) { ret = ret.Substring(0, ret.Length - 2); } return(ret + "], "); }