Beispiel #1
0
 public void AddTLVDef(TLVDef field)
 {
     if (mMap == null)
     {
         mMap = new TLVDefs();
     }
     mMap.AddField(field);
 }
Beispiel #2
0
 public void AddField(TLVDef field)
 {
     if (field == null)
     {
         throw new ArgumentNullException("field");
     }
     if (this.fields.ContainsKey(field.Tag))
     {
         throw new Exception("Tag:" + field.Tag + ",标签定义已经存在。");
     }
     this.fields.Add(field.Tag, field);
 }
Beispiel #3
0
            private string ExportToXml()
            {
                TLVDef[] array = new TLVDef[this.fields.Count];
                int      i     = 0;

                foreach (KeyValuePair <string, TLVDef> kvp in this.fields)
                {
                    array[i++] = kvp.Value;
                }
                XmlSerializer serial = new XmlSerializer(typeof(TLVDef[]));
                StringBuilder sb     = new StringBuilder();
                StringWriter  writer = new StringWriter(sb);

                serial.Serialize(writer, array);
                return(sb.ToString());
            }
Beispiel #4
0
            public TLVElement(string tag, string value, TLVDef def, bool isPack)
            {
                Tag     = Utility.str2Bcd(tag);
                Value   = Encoding.Default.GetBytes(value);
                mTLVDef = def;
                if (def == null || def.ValueType == TLVDef.DataType.A || def.ValueType == TLVDef.DataType.B)
                {
                    R = false;
                }
                else
                {
                    R = true;
                }

                if (R)
                {
                    throw new Exception("Tag:" + tag + ",内容格式不合法");
                }
            }
Beispiel #5
0
            public TLVElement(string tag, byte[] value, TLVDef def, bool isPack)
            {
                Tag     = Utility.str2Bcd(tag);
                Value   = value;
                mTLVDef = def;
                if ((def == null && isPack) || (def != null && def.ValueType == TLVDef.DataType.R && isPack))
                {
                    R = true;
                }
                else
                {
                    R = false;
                }

                if (!R && isPack)
                {
                    throw new Exception("Tag:" + tag + ",内容格式不合法");
                }
            }