Exemplo n.º 1
0
        /// <summary>
        ///  Encode Network Message Header
        /// </summary>
        /// <param name="encoder"></param>
        private void EncodeNetworkMessageHeader(BinaryEncoder encoder)
        {
            // byte[0..3] UADPVersion value 1 (for now)
            // byte[4..7] UADPFlags
            encoder.WriteByte("VersionFlags", (byte)(UADPVersion | (byte)UADPFlags));

            if ((UADPFlags & UADPFlagsEncodingMask.ExtendedFlags1) != 0)
            {
                encoder.WriteByte("ExtendedFlags1", (byte)ExtendedFlags1);
            }

            if ((ExtendedFlags1 & ExtendedFlags1EncodingMask.ExtendedFlags2) != 0)
            {
                encoder.WriteByte("ExtendedFlags2", (byte)ExtendedFlags2);
            }

            if ((NetworkMessageContentMask & UadpNetworkMessageContentMask.PublisherId) != 0)
            {
                PublisherIdTypeEncodingMask publisherIdType = (PublisherIdTypeEncodingMask)((byte)ExtendedFlags1 & kPublishedIdTypeUsedBits);
                switch (publisherIdType)
                {
                case PublisherIdTypeEncodingMask.Byte:
                    encoder.WriteByte("PublisherId", Convert.ToByte(PublisherId));
                    break;

                case PublisherIdTypeEncodingMask.UInt16:
                    encoder.WriteUInt16("PublisherId", Convert.ToUInt16(PublisherId));
                    break;

                case PublisherIdTypeEncodingMask.UInt32:
                    encoder.WriteUInt32("PublisherId", Convert.ToUInt32(PublisherId));
                    break;

                case PublisherIdTypeEncodingMask.UInt64:
                    encoder.WriteUInt64("PublisherId", Convert.ToUInt64(PublisherId));
                    break;

                case PublisherIdTypeEncodingMask.String:
                    encoder.WriteString("PublisherId", Convert.ToString(PublisherId));
                    break;

                default:
                    // Reserved - no type provided
                    break;
                }
            }

            if ((NetworkMessageContentMask & UadpNetworkMessageContentMask.DataSetClassId) != 0)
            {
                encoder.WriteGuid("DataSetClassId", DataSetClassId);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Encode Network Message Header
        /// </summary>
        /// <param name="decoder"></param>
        private void DecodeNetworkMessageHeader(BinaryDecoder decoder)
        {
            // byte[0..3] UADPVersion value 1 (for now)
            // byte[4..7] UADPFlags
            byte versionFlags = decoder.ReadByte("VersionFlags");

            UADPVersion = (byte)(versionFlags & kUADPVersionBitMask);
            // Decode UADPFlags
            UADPFlags = (UADPFlagsEncodingMask)(versionFlags & 0xF0);

            // Decode the ExtendedFlags1
            if ((UADPFlags & UADPFlagsEncodingMask.ExtendedFlags1) != 0)
            {
                ExtendedFlags1 = (ExtendedFlags1EncodingMask)decoder.ReadByte("ExtendedFlags1");
            }

            // Decode the ExtendedFlags2
            if ((ExtendedFlags1 & ExtendedFlags1EncodingMask.ExtendedFlags2) != 0)
            {
                ExtendedFlags2 = (ExtendedFlags2EncodingMask)decoder.ReadByte("ExtendedFlags2");
            }
            // calculate UADPNetworkMessageType
            if ((ExtendedFlags2 & ExtendedFlags2EncodingMask.NetworkMessageWithDiscoveryRequest) != 0)
            {
                m_uadpNetworkMessageType = UADPNetworkMessageType.DiscoveryRequest;
            }
            else if ((ExtendedFlags2 & ExtendedFlags2EncodingMask.NetworkMessageWithDiscoveryResponse) != 0)
            {
                m_uadpNetworkMessageType = UADPNetworkMessageType.DiscoveryResponse;
            }
            else
            {
                m_uadpNetworkMessageType = UADPNetworkMessageType.DataSetMessage;
            }

            // Decode PublisherId
            if ((UADPFlags & UADPFlagsEncodingMask.PublisherId) != 0)
            {
                PublisherIdTypeEncodingMask publishedIdTypeType = (PublisherIdTypeEncodingMask)((byte)ExtendedFlags1 & kPublishedIdTypeUsedBits);

                switch (publishedIdTypeType)
                {
                case PublisherIdTypeEncodingMask.UInt16:
                    m_publisherId = decoder.ReadUInt16("PublisherId");
                    break;

                case PublisherIdTypeEncodingMask.UInt32:
                    m_publisherId = decoder.ReadUInt32("PublisherId");
                    break;

                case PublisherIdTypeEncodingMask.UInt64:
                    m_publisherId = decoder.ReadUInt64("PublisherId");
                    break;

                case PublisherIdTypeEncodingMask.String:
                    m_publisherId = decoder.ReadString("PublisherId");
                    break;

                case PublisherIdTypeEncodingMask.Byte:
                default:
                    // 000 The PublisherId is of DataType Byte
                    // This is the default value if ExtendedFlags1 is omitted
                    m_publisherId = decoder.ReadByte("PublisherId");
                    break;
                }
            }

            // Decode DataSetClassId
            if ((ExtendedFlags1 & ExtendedFlags1EncodingMask.DataSetClassId) != 0)
            {
                DataSetClassId = decoder.ReadGuid("DataSetClassId");
            }
        }