public static DecodeResponseMessage ( byte byteArr ) : |
||
byteArr | byte | The payload. |
return |
public static RESPONSE_MESSAGE DecodeResponseMessage(byte[] byteArr)
{
RESPONSE_MESSAGE responseMessage;
TRANSPORT_HEADER header;
RESPONSE_CODE responseCode;
if (byteArr == null)
{
throw new ArgumentNullException("byteArr");
}
int index = 0;
byte[] informationData = GetBytes(byteArr, ref index, byteArr.Length - index);
int tempIndex = 0;
header.Size = GetUInt32(informationData, ref tempIndex, false);
if ((informationData[tempIndex] ^ 0x00) == 0)
{
responseCode = RESPONSE_CODE.OK;
}
else if ((informationData[tempIndex] ^ 0x01) == 0)
{
responseCode = RESPONSE_CODE.INTERESTED;
}
else
{
responseCode = (RESPONSE_CODE)informationData[tempIndex];
}
responseMessage.TransportHeader = header;
responseMessage.ResponseCode = responseCode;
return responseMessage;
}
/// <summary> /// Send the byte array of PCHC message using https transport . /// </summary> /// <param name="httpRequestPayload">The http request payload.</param> /// <returns>The pchc response message.</returns> private RESPONSE_MESSAGE SendByte(byte[] httpRequestPayload) { // Set the timeout of http. int timeout = 20000; byte[] payloadBuffer = null; HttpWebResponse httpWebResponse; this.httpClientTransport.Send(HttpVersion.Version10, null, httpRequestPayload, HttpMethod.POST, timeout); try { httpWebResponse = this.httpClientTransport.Receive(ref payloadBuffer); } catch (WebException e) { if (e.Message.Contains(HttpStatusCode.Unauthorized.ToString())) { throw new HttpStatusCode401Exception(); } else if (e.Message.ToLower().Contains("timed out".ToLower())) { throw new NoRESPONSEMESSAGEException(); } else { // Un expected exception is received. throw; } } this.httpResponseMethod = httpWebResponse.Method; this.httpResponseUri = httpWebResponse.ResponseUri; if (payloadBuffer == null) { throw new NoRESPONSEMESSAGEException(); } try { this.responseMessage = DecodeMessage.DecodeResponseMessage(payloadBuffer); } catch (ArgumentOutOfRangeException e) { throw new NoRESPONSEMESSAGEException(e.Message); } return(this.responseMessage); }