/// <summary> /// Parse the response data into response body. /// </summary> /// <param name="rawData">The raw data of response</param> /// <returns>The response body of the request</returns> public static QueryRowsResponseBody Parse(byte[] rawData) { QueryRowsResponseBody responseBody = new QueryRowsResponseBody(); int index = 0; responseBody.StatusCode = BitConverter.ToUInt32(rawData, index); index += sizeof(uint); responseBody.ErrorCode = BitConverter.ToUInt32(rawData, index); index += sizeof(uint); responseBody.HasState = BitConverter.ToBoolean(rawData, index); index += sizeof(bool); if (responseBody.HasState) { responseBody.State = STAT.Parse(rawData, ref index); } responseBody.HasColumnsAndRows = BitConverter.ToBoolean(rawData, index); index += sizeof(bool); if (responseBody.HasColumnsAndRows) { responseBody.Columns = LargePropTagArray.Parse(rawData, ref index); responseBody.RowCount = BitConverter.ToUInt32(rawData, index); index += sizeof(uint); responseBody.RowData = new AddressBookPropertyRow[(uint)responseBody.RowCount]; for (int i = 0; i < responseBody.RowCount; i++) { responseBody.RowData[i] = AddressBookPropertyRow.Parse(rawData, (LargePropTagArray)responseBody.Columns, ref index); } } responseBody.AuxiliaryBufferSize = BitConverter.ToUInt32(rawData, index); index += 4; responseBody.AuxiliaryBuffer = new byte[responseBody.AuxiliaryBufferSize]; Array.Copy(rawData, index, responseBody.AuxiliaryBuffer, 0, responseBody.AuxiliaryBufferSize); return(responseBody); }
/// <summary> /// Parse the AddressBookPropertyRow structure. /// </summary> /// <param name="rawBuffer">The raw data returned from server.</param> /// <param name="propTagArray">The list of property tags.</param> /// <param name="index">The start index.</param> /// <returns>Return an instance of AddressBookPropertyRow.</returns> public static AddressBookPropertyRow Parse(byte[] rawBuffer, LargePropTagArray propTagArray, ref int index) { AddressBookPropertyRow addressBookPropertyRow = new AddressBookPropertyRow(); addressBookPropertyRow.Flag = rawBuffer[index]; index++; addressBookPropertyRow.ValueArray = new List <AddressBookPropertyValue>(); Context.Instance.PropertyBytes = rawBuffer; Context.Instance.CurIndex = index; Context.Instance.CurProperty = new Property(Microsoft.Protocols.TestSuites.Common.PropertyType.PtypUnspecified); // If the value of the Flags field is set to 0x00: The array contains either a PropertyValue structure, or a TypedPropertyValue structure. // If the value of the Flags field is set to 0x01: The array contains either a FlaggedPropertyValue structure, or a FlaggedPropertyValueWithType structure. if (addressBookPropertyRow.Flag == 0x00) { foreach (PropertyTag propertyTag in propTagArray.PropertyTags) { if (propertyTag.PropertyType == 0x0000) { // If the value of the Flags field is set to 0x00: The array contains a TypedPropertyValue structure, if the type of property is PtyUnspecified. AddressBookTypedPropertyValue typedPropertyValue = new AddressBookTypedPropertyValue(); typedPropertyValue.Parse(Context.Instance); addressBookPropertyRow.ValueArray.Add(typedPropertyValue); index = Context.Instance.CurIndex; } else { // If the value of the Flags field is set to 0x00: The array contains a PropertyValue structure, if the type of property is specified. Context.Instance.CurProperty.Type = (Microsoft.Protocols.TestSuites.Common.PropertyType)propertyTag.PropertyType; AddressBookPropertyValue propertyValue = new AddressBookPropertyValue(); propertyValue.Parse(Context.Instance); addressBookPropertyRow.ValueArray.Add(propertyValue); index = Context.Instance.CurIndex; } } } else if (addressBookPropertyRow.Flag == 0x01) { foreach (PropertyTag propertyTag in propTagArray.PropertyTags) { if (propertyTag.PropertyType == 0x0000) { // If the value of the Flags field is set to 0x01: The array contains a FlaggedPropertyValueWithType structure, if the type of property is PtyUnspecified. AddressBookFlaggedPropertyValueWithType flaggedPropertyValue = new AddressBookFlaggedPropertyValueWithType(); flaggedPropertyValue.Parse(Context.Instance); addressBookPropertyRow.ValueArray.Add(flaggedPropertyValue); index = Context.Instance.CurIndex; } else { // If the value of the Flags field is set to 0x01: The array contains a FlaggedPropertyValue structure, if the type of property is specified. Context.Instance.CurProperty.Type = (Microsoft.Protocols.TestSuites.Common.PropertyType)propertyTag.PropertyType; AddressBookFlaggedPropertyValue propertyValue = new AddressBookFlaggedPropertyValue(); propertyValue.Parse(Context.Instance); addressBookPropertyRow.ValueArray.Add(propertyValue); index = Context.Instance.CurIndex; } } } return(addressBookPropertyRow); }
/// <summary> /// Parse PropertyRowSet_r structure. /// </summary> /// <param name="columns">The columns which contain property tags.</param> /// <param name="rowCount">The row count of the PropertyRowSet_r.</param> /// <param name="rowData">The row data which contain the property values.</param> /// <returns>Instance of PropertyRowSet_r structure.</returns> public static PropertyRowSet_r ParsePropertyRowSet_r(LargePropTagArray columns, uint rowCount, AddressBookPropertyRow[] rowData) { PropertyRowSet_r propertyRowSet_r = new PropertyRowSet_r(); propertyRowSet_r.Rows = rowCount; propertyRowSet_r.PropertyRowSet = new PropertyRow_r[rowCount]; for (int i = 0; i < rowCount; i++) { propertyRowSet_r.PropertyRowSet[i].Reserved = 0; propertyRowSet_r.PropertyRowSet[i].Values = columns.PropertyTagCount; propertyRowSet_r.PropertyRowSet[i].Props = new PropertyValue_r[columns.PropertyTagCount]; for (int j = 0; j < columns.PropertyTagCount; j++) { propertyRowSet_r.PropertyRowSet[i].Props[j].PropTag = BitConverter.ToUInt32(columns.PropertyTags[j].Serialize(), 0); propertyRowSet_r.PropertyRowSet[i].Props[j].Reserved = 0; propertyRowSet_r.PropertyRowSet[i].Props[j].Value = AdapterHelper.ParsePROP_VAL_UNION(rowData[i].ValueArray.ToArray()[j], (PropertyTypeValue)columns.PropertyTags[j].PropertyType); } } return propertyRowSet_r; }
/// <summary> /// Parse the AddressBookPropertyRow structure. /// </summary> /// <param name="rawBuffer">The raw data returned from server.</param> /// <param name="propTagArray">The list of property tags.</param> /// <param name="index">The start index.</param> /// <returns>Return an instance of AddressBookPropertyRow.</returns> public static AddressBookPropertyRow Parse(byte[] rawBuffer, LargePropTagArray propTagArray, ref int index) { AddressBookPropertyRow addressBookPropertyRow = new AddressBookPropertyRow(); addressBookPropertyRow.Flag = rawBuffer[index]; index++; addressBookPropertyRow.ValueArray = new List<AddressBookPropertyValue>(); Context.Instance.PropertyBytes = rawBuffer; Context.Instance.CurIndex = index; Context.Instance.CurProperty = new Property(Microsoft.Protocols.TestSuites.Common.PropertyType.PtypUnspecified); // If the value of the Flags field is set to 0x00: The array contains either a PropertyValue structure, or a TypedPropertyValue structure. // If the value of the Flags field is set to 0x01: The array contains either a FlaggedPropertyValue structure, or a FlaggedPropertyValueWithType structure. if (addressBookPropertyRow.Flag == 0x00) { foreach (PropertyTag propertyTag in propTagArray.PropertyTags) { if (propertyTag.PropertyType == 0x0000) { // If the value of the Flags field is set to 0x00: The array contains a TypedPropertyValue structure, if the type of property is PtyUnspecified. AddressBookTypedPropertyValue typedPropertyValue = new AddressBookTypedPropertyValue(); typedPropertyValue.Parse(Context.Instance); addressBookPropertyRow.ValueArray.Add(typedPropertyValue); index = Context.Instance.CurIndex; } else { // If the value of the Flags field is set to 0x00: The array contains a PropertyValue structure, if the type of property is specified. Context.Instance.CurProperty.Type = (Microsoft.Protocols.TestSuites.Common.PropertyType)propertyTag.PropertyType; AddressBookPropertyValue propertyValue = new AddressBookPropertyValue(); propertyValue.Parse(Context.Instance); addressBookPropertyRow.ValueArray.Add(propertyValue); index = Context.Instance.CurIndex; } } } else if (addressBookPropertyRow.Flag == 0x01) { foreach (PropertyTag propertyTag in propTagArray.PropertyTags) { if (propertyTag.PropertyType == 0x0000) { // If the value of the Flags field is set to 0x01: The array contains a FlaggedPropertyValueWithType structure, if the type of property is PtyUnspecified. AddressBookFlaggedPropertyValueWithType flaggedPropertyValue = new AddressBookFlaggedPropertyValueWithType(); flaggedPropertyValue.Parse(Context.Instance); addressBookPropertyRow.ValueArray.Add(flaggedPropertyValue); index = Context.Instance.CurIndex; } else { // If the value of the Flags field is set to 0x01: The array contains a FlaggedPropertyValue structure, if the type of property is specified. Context.Instance.CurProperty.Type = (Microsoft.Protocols.TestSuites.Common.PropertyType)propertyTag.PropertyType; AddressBookFlaggedPropertyValue propertyValue = new AddressBookFlaggedPropertyValue(); propertyValue.Parse(Context.Instance); addressBookPropertyRow.ValueArray.Add(propertyValue); index = Context.Instance.CurIndex; } } } return addressBookPropertyRow; }