private ServiceElement BuildElement(IntPtr pElemData) { var elemData = (Structs.sdp_data_struct__Bytes)Marshal.PtrToStructure( pElemData, typeof(Structs.sdp_data_struct__Bytes)); var debug = (Structs.sdp_data_struct__Debug)Marshal.PtrToStructure( pElemData, typeof(Structs.sdp_data_struct__Debug)); // ElementTypeDescriptor etd; SizeIndex sizeIndex; Map(elemData.dtd, out etd, out sizeIndex); //Console.WriteLine("BE: dtd: {0}, unitSize: {1}", // elemData.dtd, elemData.unitSize); // if (etd == ElementTypeDescriptor.ElementSequence || etd == ElementTypeDescriptor.ElementAlternative) { IntPtr pCur = elemData.ReadIntPtr(); var list = DoSequence(pCur); #if DEBUG ElementTypeDescriptor cover; if (etd == ElementTypeDescriptor.ElementAlternative) { cover = etd; //COVERAGE } else { cover = etd; //COVERAGE } #endif return(new ServiceElement( etd == ElementTypeDescriptor.ElementSequence ? ElementType.ElementSequence : ElementType.ElementAlternative, list)); } else { byte[] buf; byte[] data; if (etd == ElementTypeDescriptor.TextString || etd == ElementTypeDescriptor.Url) { buf = new byte[elemData.unitSize]; IntPtr pStr = elemData.ReadIntPtr(); Marshal.Copy(pStr, buf, 0, buf.Length - 1); //---- } else if (etd == ElementTypeDescriptor.Uuid) { var elemDataUuid = (Structs.sdp_data_struct__uuid_t)Marshal.PtrToStructure( pElemData, typeof(Structs.sdp_data_struct__uuid_t)); Debug.Assert(elemDataUuid.dtd == elemDataUuid.val.type, "uuid type"); int len = FromSizeIndex(sizeIndex); buf = new byte[len]; data = elemDataUuid.val.value; Array.Copy(data, buf, buf.Length); //---- } else { int len = FromSizeIndex(sizeIndex); buf = new byte[len]; data = elemData.val; Array.Copy(data, buf, buf.Length); } int readLen = buf.Length; bool networkOrderFalse = false; var elem = _parser.ParseContent(networkOrderFalse, networkOrderFalse, buf, 0, buf.Length, ref readLen, etd, sizeIndex, buf.Length, 0); return(elem); } }
private ServiceElement BuildElement(IntPtr pElemData) { var elemData = (Structs.SDP_Data_Element)Marshal.PtrToStructure( pElemData, typeof(Structs.SDP_Data_Element)); var sizeofElemData = Marshal.SizeOf(typeof(Structs.SDP_Data_Element)); // ElementTypeDescriptor etd; SizeIndex sizeIndex; Map(elemData.SDP_Data_Element_Type, out etd, out sizeIndex); // const int OffsetOf_FakeAtUnionPosition = 8; #if !NETCF var dbgOffset = Marshal.OffsetOf(typeof(Structs.SDP_Data_Element), "FakeAtUnionPosition"); Debug.Assert(new IntPtr(OffsetOf_FakeAtUnionPosition) == dbgOffset, "OffsetOf_FakeAtUnionPosition but: " + dbgOffset); #endif IntPtr pDataInStruct = Pointers.Add(pElemData, OffsetOf_FakeAtUnionPosition); IntPtr pArrElements = Marshal.ReadIntPtr(pDataInStruct); if (etd == ElementTypeDescriptor.ElementSequence || etd == ElementTypeDescriptor.ElementAlternative) { var list = new List <ServiceElement>(); var pCur = pArrElements; for (int i = 0; i < elemData.SDP_Data_Element_Length; ++i) { var e = BuildElement(pCur); list.Add(e); // Next pCur = Pointers.Add(pCur, sizeofElemData); }//for #if DEBUG ElementTypeDescriptor cover; if (etd == ElementTypeDescriptor.ElementAlternative) { cover = etd; //COVERAGE } else { cover = etd; //COVERAGE } #endif return(new ServiceElement( etd == ElementTypeDescriptor.ElementSequence ? ElementType.ElementSequence : ElementType.ElementAlternative, list)); } else { byte[] buf = new byte[elemData.SDP_Data_Element_Length]; IntPtr pData; if (etd == ElementTypeDescriptor.TextString || etd == ElementTypeDescriptor.Url) { pData = pArrElements; } else { pData = pDataInStruct; } Marshal.Copy(pData, buf, 0, buf.Length); int readLen = buf.Length; var elem = _parser.ParseContent(false, true, buf, 0, buf.Length, ref readLen, etd, sizeIndex, buf.Length, 0); return(elem); } }