Пример #1
0
        /// <summary>
        /// Make a deep clone of the Message
        /// </summary>
        /// <param name="tMsg">Mesage to be cloned</param>
        /// <param name="DoClonePLB">If set to True, the PLB parameter will be block-copied, too</param>
        /// <returns></returns>
        public static TSM Clone(TSM tMsg, bool DoClonePLB)
        {
            TSM tRes = new TSM(tMsg.SID)    //Save not to set ORG or SID for fast cloning
            {
                TXT  = tMsg.TXT,
                TIM  = tMsg.TIM,
                FLG  = tMsg.FLG,
                ORG  = tMsg.ORG,//ORG-OK
                QDX  = tMsg.QDX,
                LVL  = tMsg.LVL,
                ENG  = tMsg.ENG,
                FID  = tMsg.FID,
                SEID = tMsg.SEID,
                CST  = tMsg.CST,
                UID  = tMsg.UID,
                PLS  = tMsg.PLS,
                OWN  = tMsg.OWN
            };

            if (DoClonePLB && tMsg.PLB != null && tMsg.PLB.Length > 0)
            {
                tRes.PLB = new byte[tMsg.PLB.Length];
                TheCommonUtils.cdeBlockCopy(tMsg.PLB, 0, tRes.PLB, 0, tMsg.PLB.Length);
            }
            return(tRes);
        }
Пример #2
0
        /// <summary>
        /// Serializes the TSM to a binary object format only known to the C-Engine
        /// This is not used for the HTTP channel but reserverd for future use on other TCP/UPD channels
        /// </summary>
        /// <param name="pOffset"></param>
        /// <returns></returns>
        internal byte[] ToPacketBytes(int pOffset)
        {
            long  timeBytes       = TIM.ToFileTime();
            short timeOffsetBytes = (short)TIM.Offset.TotalMinutes;

            string[] Data = new string[9];
            Data[0] = TXT;         // Text
            Data[1] = PLS;         // PayLoad String
            Data[2] = ORG;         //  Origin
            Data[3] = ENG;         //eEngineName
            Data[4] = FID;         // Federation ID
            Data[5] = SID;         // Scope ID
            Data[6] = SEID;        // Session ID
            Data[7] = UID;         //UserID
            Data[8] = CST;
            Data[9] = OWN;
            //public byte[] PLB;              // PayLoad Binary

            int dataByteCounter = 0;

            byte[] dataBytes = null;
            using (MemoryStream dataByteWriter = new MemoryStream())
            {
                byte[] dataStringBytes = null;
                foreach (string dataString in Data)
                {
                    if (string.IsNullOrEmpty(dataString))
                    {
                        dataByteWriter.Write(zeroInt, 0, 4);
                        dataByteCounter += 4;
                    }
                    else
                    {
                        dataStringBytes = Encoding.UTF8.GetBytes(dataString);
                        dataByteWriter.WriteByte((byte)((dataStringBytes.Length >> 0) & 0xff));
                        dataByteWriter.WriteByte((byte)((dataStringBytes.Length >> 8) & 0xff));
                        dataByteWriter.WriteByte((byte)((dataStringBytes.Length >> 16) & 0xff));
                        dataByteWriter.WriteByte((byte)((dataStringBytes.Length >> 24) & 0xff));
                        dataByteWriter.Write(dataStringBytes, 0, dataStringBytes.Length);
                        dataByteCounter += 4;
                        dataByteCounter += dataStringBytes.Length;
                    }
                }
                dataBytes = dataByteWriter.GetBuffer();
            }

            int PLBLength = 0;

            if (PLB != null && PLB.Length > 0)
            {
                PLBLength = PLB.Length;
            }
            int totalBytes = 21 + PLBLength + dataByteCounter + pOffset;

            byte[] packetBuffer = null;
            using (MemoryStream stream = new MemoryStream())
            {
                stream.WriteByte((byte)((totalBytes >> 0) & 0xff));
                stream.WriteByte((byte)((totalBytes >> 8) & 0xff));
                stream.WriteByte((byte)((totalBytes >> 16) & 0xff));
                stream.WriteByte((byte)((totalBytes >> 24) & 0xff));

                stream.WriteByte((byte)((timeBytes >> 0) & 0xff));
                stream.WriteByte((byte)((timeBytes >> 8) & 0xff));
                stream.WriteByte((byte)((timeBytes >> 16) & 0xff));
                stream.WriteByte((byte)((timeBytes >> 24) & 0xff));
                stream.WriteByte((byte)((timeBytes >> 32) & 0xff));
                stream.WriteByte((byte)((timeBytes >> 40) & 0xff));
                stream.WriteByte((byte)((timeBytes >> 48) & 0xff));
                stream.WriteByte((byte)((timeBytes >> 56) & 0xff));

                stream.WriteByte((byte)((timeOffsetBytes >> 0) & 0xff));
                stream.WriteByte((byte)((timeOffsetBytes >> 8) & 0xff));


                stream.WriteByte((byte)LVL);
                stream.WriteByte((byte)(FLG >> 8));
                stream.WriteByte((byte)(FLG & 255));
                stream.WriteByte((byte)QDX);
                stream.WriteByte((byte)Data.Length);
                stream.WriteByte((byte)((PLBLength >> 0) & 0xff));
                stream.WriteByte((byte)((PLBLength >> 8) & 0xff));
                stream.WriteByte((byte)((PLBLength >> 16) & 0xff));
                stream.WriteByte((byte)((PLBLength >> 24) & 0xff));
                stream.Write(dataBytes, 0, dataByteCounter);
                if (PLBLength > 0)
                {
                    stream.Write(PLB, 0, PLBLength);
                }

                packetBuffer = new byte[totalBytes];

                TheCommonUtils.cdeBlockCopy(stream.GetBuffer(), 0, packetBuffer, pOffset, packetBuffer.Length - pOffset);

                if (totalBytes != packetBuffer.Length)
                {
                    throw new InvalidOperationException("Sending Invalid Packet Length");
                }
            }

            return(packetBuffer);
        }