public List <BaseResponse> ProcessReceivedDataRsp() { List <BaseResponse> packets = new List <BaseResponse>(); byte[] buf = ReceivedData.GetBuffer(); //Parse packets int rSize, pos = 0; BaseResponse packet; do { packet = BaseResponse.Deserialize(buf, ReceivedDataLength, pos, out rSize); if (rSize > 0 && packet != null) { packets.Add(packet); pos += rSize; } } while (rSize > 0 && packet != null); //Shrink stream if (pos > 0 && ReceivedDataLength > 0) { ReceivedDataLength -= pos; Buffer.BlockCopy(buf, pos, buf, 0, ReceivedDataLength); ReceivedData.SetLength(ReceivedDataLength); } return(packets); }
private void ProcessReceivedData(MemoryStream stream) { List <BaseResponse> packets = new List <BaseResponse>(); byte[] buf = stream.GetBuffer(); //Parse packets int rSize, pos = 0; int dataSize = (int)stream.Length; BaseResponse packet; do { packet = BaseResponse.Deserialize(buf, dataSize, pos, out rSize); if (rSize > 0 && packet != null) { packets.Add(packet); pos += rSize; } } while (rSize > 0 && packet != null); //Shrink stream if (pos > 0) { Buffer.BlockCopy(buf, pos, buf, 0, dataSize - pos); stream.SetLength(dataSize - pos); } //Fire DataReceived event if (DataReceived != null && packets.Count > 0) { DataReceived(packets); } }