Example #1
0
        /// <summary>
        /// Returns the contents of the message as a string
        /// </summary>
        /// <param name="prefix">
        /// The prefix to apply to each line in the message
        /// </param>
        /// <returns>
        /// Pretty printed string
        /// </returns>
        public override string ToString(string prefix)
        {
            var sb = new StringBuilder();

            sb.Append(prefix + IsoConvert.FromIntToMsgType(this.MessageType) + ":" + Environment.NewLine);
            sb.Append(base.ToString(prefix));
            return(sb.ToString());
        }
        /// <summary>
        /// Unpacks the message from a byte array
        /// </summary>
        /// <param name="msg">
        /// message data to unpack
        /// </param>
        /// <param name="startingOffset">
        /// the offset in the array to start
        /// </param>
        /// <returns>
        /// the offset in the array representing the start of the next message
        /// </returns>
        public override int Unpack(byte[] msg, int startingOffset)
        {
            // get mtid
            var mtidLength = this.Template.MsgTypeFormatter.GetPackedLength(4);
            var buffer     = new byte[mtidLength];
            var offset     = startingOffset;

            Array.Copy(msg, offset, buffer, 0, mtidLength);
            this.MessageType = IsoConvert.FromMsgTypeDataToInt(buffer);
            offset          += mtidLength;
            return(base.Unpack(msg, offset));
        }
Example #3
0
        /// <summary>
        /// Gets the message as a byte array ready to send over the network
        /// </summary>
        /// <returns>
        /// byte[] representing the message
        /// </returns>
        public override byte[] ToMsg()
        {
            var length = this.PackedLength;
            var data   = new byte[length];

            var msgTypeString = IsoConvert.FromIntToMsgType(this.MessageType);

            // MsgType
            var newMsgType = Template.MsgTypeFormatter.GetBytes(msgTypeString);
            var msgTypeLen = newMsgType.Length;

            // Array.Copy(IsoConvert.FromIntToMsgTypeData(MessageType), 0, data, 0, 4);
            Array.Copy(newMsgType, 0, data, 0, newMsgType.Length);
            var baseMsg = base.ToMsg();

            Array.Copy(baseMsg, 0, data, msgTypeLen, baseMsg.Length);
            return(data);
        }