internal new void ParseIdentifier(byte[] arr, ref int idx, TypeWrapper type) { TLVDecoder.ParseIdentifier(arr, ref idx, type); }
public void ParseIdentifier_Test() { int idx = 0; TypeWrapper type = new TypeWrapper(); type.IsConstructed = true; byte[] identifier = { 0xFF, 0x01 }; TLVDec.ParseIdentifier(identifier, ref idx, type); Assert.AreEqual<uint>(1, type.Identifier); Assert.AreEqual(2, idx); }
public void ParseIdentifier_Universal_Test() { int idx = 0; TypeWrapper type = new TypeWrapper(); type.IsConstructed = true; byte[] identifier = { 0x20, 0x11 }; // 0010 TLVDec.ParseIdentifier(identifier, ref idx, type); Assert.AreEqual(1, idx); }
public void ParseIdentifier_Overflow_Test() { int idx = 1; TypeWrapper type = new TypeWrapper(); type.IsConstructed = true; byte[] identifier = { 0x7F, 0xFF, 0xFF, 0x80, 0x80, 0x80 }; TLVDec.ParseIdentifier(identifier, ref idx, type); // No Asserts -> exception }
public void ParseIdentifier_Small_Test() { int idx = 1; TypeWrapper type = new TypeWrapper(); type.IsConstructed = false; byte[] identifier = { 0x7F, 0x01 }; // T[7:6] = 01, [5]=1, [4:0]=11111 TLVDec.ParseIdentifier(identifier, ref idx, type); Assert.AreEqual<uint>(0x1, type.Identifier); Assert.AreEqual(2, idx); }
public void ParseIdentifier_Long3_Test() { int idx = 0; TypeWrapper type = new TypeWrapper(); type.IsConstructed = true; byte[] input = { 0x9F, 0x81, 0x80, 0x01 }; TLVDec.ParseIdentifier(input, ref idx, type); // [6:0] = 1 // [6:0] = 0 // [6:0] = 1 // --> 0100 0000 0000 0001 Assert.AreEqual<uint>(0x4001, type.Identifier); Assert.AreEqual(4, idx); }
public void ParseIdentifier_Long2_Test() { int idx = 0; TypeWrapper type = new TypeWrapper(); type.IsConstructed = true; byte[] input = { 0x9F, 0x90, // 1001 0000 0x01 // 0000 0001 }; TLVDec.ParseIdentifier(input, ref idx, type); // 0010000 // 0000001 // --> 1000 0000 0001 Assert.AreEqual<uint>(0x801, type.Identifier); Assert.AreEqual(3, idx); }
private static bool IsPrimitive(TypeWrapper t) { return !t.IsConstructed; }
protected object Parse(byte[] arr, ref int idx, TLVConv conv, object obj) { TypeWrapper type = new TypeWrapper(); if ((arr[idx] & TLV_PRIM_CONSTR_TYPE_MAKS) == TLV_PRIM_CONSTR_TYPE_MAKS) { // When constructed, the first bit does not contain any info beside domain/application type.IsConstructed = true; // Only incr. when bits [4:0] set //if ((arr[idx] & 0x1F) == 0x1F) ++idx; } ParseIdentifier(arr, ref idx, type); if (!IsPrimitive(type) && conv == null) { conv = TransMap[type.Identifier]; obj = ((TLVCompositeConv)conv).CreateInstance.Invoke(emptyCtorArgs); } uint length = GetLength(arr, ref idx); if (IsPrimitive(type)) { var value = ParsePrimitive(arr, ref idx, length, type.Identifier); // For 'normal' if (conv != null) conv.PropInfo.SetValue(obj, value); // For primitive in a list (is added in iteration) else obj = value; return obj; } if (IsList(conv)) { Console.WriteLine("isList"); ParseList(arr, ref idx, length, (TLVListConv)conv, obj); } else { // Create object ParseConstructed(arr, ref idx, length, conv as TLVCompositeConv, obj); //TLVCompositeConv conv = TransMap[type.Identifier]; } return obj; }
/// <summary> /// Parses an identifier of a constructed value (which means that idx is always > 0) /// </summary> /// <param name="arr">The input array</param> /// <param name="idx">Current position in arr</param> /// <param name="type">Current type-information</param> protected static void ParseIdentifier(byte[] arr, ref int idx, TypeWrapper type) { uint identifier = GetIntFrom_Holey_byteArray(arr, ref idx, TLV_CONSTRUCTED_IDENTIFIER_FIRST_MAKS); // If is primitive, clear bits [7:5] because they contain other info than type if (!type.IsConstructed) identifier &= 0x1F; type.Identifier = identifier; }