protected virtual void ProcessPdu(Stream stream, out byte[] rawData) { int upToPduLength = (int)PDU_LENGTH_POSITION + sizeof(ushort); int pduLength = 0; long startingPosition = stream.Position; byte[] buffer = new byte[upToPduLength]; // Read in part of the stream up to the pdu length stream.Read(buffer, 0, upToPduLength); try { pduLength = PduProcessor.pduLength(buffer, this.endian); // Allocate space for the whole PDU rawData = new byte[pduLength]; // Reset back to beginning stream.Position = startingPosition; // Read in the whole PDU stream.Read(rawData, 0, pduLength); } catch { // Wow something bad just happened, could be bad/misalgined PDU rawData = null; } }
/// <summary> /// Process a received PDU. Note that a datastream can contain multiple PDUs. Therefore a /// List is used to hold one or more after decoding. /// </summary> /// <remarks>Added by PES to support passing back just the byte array.</remarks> /// <param name="buf">byte array of PDU(s)</param> /// <returns>Collection of all PDU(s) in raw byte format</returns> protected virtual List <byte[]> ProcessRawPdu(byte[] buffer) { List <byte[]> pduCollection = new List <byte[]>(); if (buffer.Length < 1) { return(pduCollection); } int length = buffer.Length; byte pduType; byte pduVersion; int countBytes = 0; uint pduLength = 0; //used to interate over all PDU(s) within the byte array while (countBytes < length) { try { pduLength = PduProcessor.pduLength(buffer, this.endian); // Must be at end of datastream if (pduLength == 0) { break; } pduType = buffer[PDU_TYPE_POSITION + countBytes]; pduVersion = buffer[PDU_VERSION_POSITION + countBytes]; byte[] pduBufferStorage = new byte[pduLength]; // Could potentially be a problem since pduLength is an unsigned int, // changed due to windows mobile does not accept a long for 4th parameter Array.Copy(buffer, countBytes, pduBufferStorage, 0, (int)pduLength); pduCollection.Add(pduBufferStorage); countBytes += (int)pduLength; } catch { // Wow something bad just happened, could be bad/misalgined PDU break; } } return(pduCollection); }
// Protected Methods (5) protected virtual object ProcessPdu(Stream stream) { int upToPduLength = (int)PDU_LENGTH_POSITION + sizeof(ushort); int pduLength = 0; byte pduType; byte pdu_version; object pdu = null; long startingPosition = stream.Position; byte[] buffer = new byte[upToPduLength]; // Read in part of the stream up to the pdu length stream.Read(buffer, 0, upToPduLength); try { pduLength = PduProcessor.pduLength(buffer, this.endian); // Allocate space for the whole PDU byte[] pduBufferStorage = new byte[pduLength]; // Reset back to beginning stream.Position = startingPosition; // Read in the whole PDU stream.Read(pduBufferStorage, 0, pduLength); pduType = pduBufferStorage[PDU_TYPE_POSITION]; pdu_version = pduBufferStorage[PDU_VERSION_POSITION]; pdu = this.SwitchOnType(pdu_version, pduType, pduBufferStorage); } catch { // Wow something bad just happened, could be bad/misalgined PDU pdu = null; } return(pdu); }