public static TreeNode fromTLV(TLV data) { if (data == null) { return(null); } TreeNode result = new TreeNode(data.Tag); result.Name = data.Tag; // put the Length, Value, Description string[] content = { Conversion_BER_TLV.ConvertFromInt(data.Length), data.Value, data.Description }; result.Tag = content; //traverse each child if (data.child != null) { foreach (var child in data.child) { if (child != null) { result.Nodes.Add(DataConverter.fromTLV(child)); } } } return(result); }
public void TestBERTLVConvertFromString() { string val = "80053362265544"; int index = 2; int res = Conversion_BER_TLV.ConvertFromString(val, ref index); Assert.AreEqual(4, index); Assert.AreEqual(5, res); }
public static List <TLV> Parse(string value) { List <TLV> result = null; try { value = StringManipulator.removeSpace(value); result = new List <TLV>(); TLV tlv; int marker = 0; while (marker < value.Length) { //fill up the Tag tlv = new TLV(); tlv.Tag = value.Substring(marker, 2); marker += 2; if (marker + 2 > value.Length) { marker += 2; continue; } // ber-TLV processing tlv.Length = Conversion_BER_TLV.ConvertFromString(value, ref marker); //fill up the value part if (tlv.Length * 2 + marker > value.Length) { marker = value.Length + 1; continue; } //if it's only TL without V then add the TLV immediately if (tlv.Length < 1) { result.Add(tlv); continue; } tlv.Value = value.Substring(marker, tlv.Length * 2); marker += tlv.Length * 2; result.Add(tlv); } } catch (Exception) { } return(result); }
public void TestBERTLVConvertFromInt() { int val = 200; string tes = Conversion_BER_TLV.ConvertFromInt(val); Assert.AreEqual("81C8", tes); val = 14; tes = Conversion_BER_TLV.ConvertFromInt(val); Assert.AreEqual("0E", tes); val = 3399; tes = Conversion_BER_TLV.ConvertFromInt(val); Assert.AreEqual("820D47", tes); val = 128; tes = Conversion_BER_TLV.ConvertFromInt(val); Assert.AreEqual("8180", tes); }