コード例 #1
0
        // Decoder
        private void ReadFrame(BinaryReader reader)
        {
            // Size
            _ = reader.ReadUInt16();

            // Protocol, addressable, tagged, origin
            ushort flags = reader.ReadUInt16();

            ushort protocol    = (ushort)(flags & 0xfff);
            bool   addressable = ((flags >> 12) & 1) != 0;
            /* bool tagged = ((flags >> 13) & 1) != 0; */
            byte origin = (byte)((flags >> 14) & 3);

            LifxMessage.AssertEquals("invalid_protocol", LifxMessage.Protocol, protocol);
            LifxMessage.AssertEquals("invalid_addressable_flag", LifxMessage.Addressable, addressable);
            LifxMessage.AssertEquals("invalid_origin", LifxMessage.Origin, origin);

            // Source
            uint source = reader.ReadUInt32();

            if (this.SourceId != 0)
            {
                LifxMessage.AssertEquals("invalid_source", (uint)this.SourceId, source);
            }

            this.SourceId = (int)source;
        }
コード例 #2
0
        private void ReadProtocolHeader(BinaryReader reader)
        {
            // Reserved
            _ = reader.ReadUInt64();

            // Type
            ushort type = reader.ReadUInt16();

            if (this.Type != LifxMessageType.Unknown)
            {
                LifxMessage.AssertEquals("invalid_type", (ushort)this.Type, type);
            }

            this.Type = (LifxMessageType)type;

            // Reserved
            _ = reader.ReadUInt16();
        }