/// <summary> /// Expands the byte array into a CommonPacket /// </summary> /// <param name="dataArray">Array with the Common Packet</param> /// <param name="offset">Place in the array the Common Packet begins</param> /// <param name="newOffset">Place where the Common Packet ends</param> public void Expand(byte[] dataArray, int offset, out int newOffset) { //First get the count... ushort count = BitConverter.ToUInt16(dataArray, offset); offset += 2; if (count < 2) { throw new ArgumentOutOfRangeException("Invalid number of items, must be at least 2, value was " + count.ToString()); } AddressItem = new CommonPacketItem(); AddressItem.Expand(dataArray, offset, out offset); //Offset += 2; DataItem = new CommonPacketItem(); DataItem.Expand(dataArray, offset, out offset); if (count > 2) { for (int i = 2; i < count; i++) { offset += 1; CommonPacketItem cpi = new CommonPacketItem(); cpi.Expand(dataArray, offset, out offset); } } newOffset = offset; }
/// <summary> /// Returns an Unconnected Data Item /// </summary> /// <param name="message">Message to encapsulate</param> /// <returns>Unconnected Data Item for the Common Packet Format</returns> public static CommonPacketItem GetUnconnectedDataItem(byte[] message) { CommonPacketItem cpi = new CommonPacketItem(); cpi.TypeId = (ushort)CommonPacketTypeId.UnconnectedMessage; cpi.Length = (ushort)(message == null ? 0 : message.Length); cpi.Data = message; return(cpi); }
/// <summary> /// Returns a Connected Address Item /// </summary> /// <param name="connectionId">Connection Id</param> /// <returns>Address Item for the Common Packet Format</returns> public static CommonPacketItem GetConnectedAddressItem(uint connectionId) { CommonPacketItem cpi = new CommonPacketItem(); cpi.TypeId = (ushort)CommonPacketTypeId.ConnectionBased; cpi.Length = 4; cpi.Data = BitConverter.GetBytes(connectionId); return(cpi); }
/// <summary> /// Returns a Connected Data Item /// </summary> /// <param name="message">Message to encapsulate</param> /// <param name="sequenceNumber">Sequence Number</param> /// <returns>Connected Data Item for the Common Packet Format</returns> public static CommonPacketItem GetConnectedDataItem(byte[] message, ushort sequenceNumber) { CommonPacketItem cpi = new CommonPacketItem(); cpi.TypeId = (ushort)CommonPacketTypeId.ConnectedTransportPacket; cpi.Length = (ushort)(message == null ? 0 : message.Length); byte[] fullMessage = new byte[2 + message.Length]; //byte[] fullMessage = new byte[6 + Message.Length]; Buffer.BlockCopy(BitConverter.GetBytes(sequenceNumber), 0, fullMessage, 0, 2); Buffer.BlockCopy(message, 0, fullMessage, 2, message.Length); cpi.Data = fullMessage; return(cpi); }
/// <summary> /// Returns a Sequenced Address Item /// </summary> /// <param name="connectionId">Connection Id</param> /// <param name="sequenceNumber">Sequence Number</param> /// <returns>Sequenced Address Item for the Common Packet Format</returns> public static CommonPacketItem GetSequencedAddressItem(uint connectionId, uint sequenceNumber) { CommonPacketItem cpi = new CommonPacketItem(); cpi.TypeId = (ushort)CommonPacketTypeId.SequencedAddressItem; cpi.Length = 8; byte[] temp = new byte[8]; Buffer.BlockCopy(BitConverter.GetBytes(connectionId), 0, temp, 0, 4); Buffer.BlockCopy(BitConverter.GetBytes(sequenceNumber), 0, temp, 4, 4); cpi.Data = temp; return(cpi); }
public EncapsReply SendRRData(CommonPacketItem AddressItem, CommonPacketItem DataItem, CommonPacketItem[] AdditionalItems = null) { if (OnPreOperation != null) { OnPreOperation(); } if ((CommonPacketTypeId)AddressItem.TypeId == CommonPacketTypeId.ConnectionBased) { //The connection ID may have changed, so we have to reset it AddressItem.Data = BitConverter.GetBytes(ConnectionParameters.O2T_CID); } EncapsRRData rrData = new EncapsRRData(); rrData.CPF = new CommonPacket(); rrData.Timeout = (ushort)MillisecondTimeout; rrData.CPF.AddressItem = AddressItem; rrData.CPF.DataItem = DataItem; if (AdditionalItems != null) { for (int i = 0; i < AdditionalItems.Length; i++) { rrData.CPF.AddItem(AdditionalItems[i]); } } EncapsPacket request = EncapsPacketFactory.CreateSendRRData(SessionHandle, 0, SenderContext, rrData.Pack()); byte[] rawRequest = request.Pack(); byte[] rawReply = SendData_WaitReply(rawRequest); if (OnPostOperation != null) { OnPostOperation(); } if (rawReply == null) { return(null); } EncapsReply reply = new EncapsReply(); int temp = 0; reply.Expand(rawReply, 0, out temp); return(reply); }
internal void Expand(byte[] sourceArray) { ItemCount = BitConverter.ToUInt16(sourceArray, 0); if (ItemCount == 0) { return; } Items = new CommonPacketItem[ItemCount]; int offset = 1; for (int i = 0; i < ItemCount; i++) { offset += 1; CommonPacketItem cpi = new CommonPacketItem(); cpi.Expand(sourceArray, offset, out offset); Items[i] = cpi; } }
/// <summary> /// Adds an item to the optional items /// </summary> /// <param name="cpi"></param> public void AddItem(CommonPacketItem cpi) { _items.Add(cpi); }
/// <summary> /// Creates a new CommonPacketItem using a Null Address Item and an Unconnected Data Item with a NULL message /// </summary> public CommonPacket() { AddressItem = CommonPacketItem.GetNullAddressItem(); DataItem = CommonPacketItem.GetUnconnectedDataItem(null); }