Beispiel #1
0
        public void Decode(BinaryStream stream)
        {
            byte flags = stream.ReadByte();

            Reliability = (MessageReliability)(flags >> 5);
            HasSplit    = (flags & 0x10) != 0;

            var contentLength = stream.ReadInt16() >> 3;

            if (ReliabilityHelper.IsReliable(Reliability))
            {
                MessageIndex = stream.ReadInt24();
            }

            if (ReliabilityHelper.IsSequenced(Reliability))
            {
                SequenceIndex = stream.ReadInt24();
                OrderIndex    = stream.ReadInt24();
                OrderChannel  = stream.ReadByte();
            }
            else if (ReliabilityHelper.IsOrdered(Reliability))
            {
                OrderIndex   = stream.ReadInt24();
                OrderChannel = stream.ReadByte();
            }

            if (HasSplit)
            {
                SplitCount = stream.ReadInt32();
                SplitId    = stream.ReadUInt16();
                SplitIndex = stream.ReadInt32();
            }

            Content = stream.ReadBytes(contentLength);
        }
Beispiel #2
0
        public void Encode(BinaryStream stream)
        {
            stream.WriteByte((byte)(((byte)Reliability << 5) | (HasSplit ? 0x10 : 0x00)));

            if (Content.Length > CONTENT_MAX_SIZE)
            {
                throw new OverflowException("Content.Length > CONTENT_MAX_SIZE");
            }
            stream.WriteInt16((short)(Content.Length << 3));

            if (ReliabilityHelper.IsReliable(Reliability))
            {
                stream.WriteInt24(MessageIndex);
            }

            if (ReliabilityHelper.IsSequenced(Reliability))
            {
                stream.WriteInt24(SequenceIndex);
                stream.WriteInt24(OrderIndex);
                stream.WriteByte(OrderChannel);
            }
            else if (ReliabilityHelper.IsOrdered(Reliability))
            {
                stream.WriteInt24(OrderIndex);
                stream.WriteByte(OrderChannel);
            }

            if (HasSplit)
            {
                stream.WriteInt32(SplitCount);
                stream.WriteUInt16(SplitId);
                stream.WriteInt32(SplitIndex);
            }

            stream.WriteBytes(Content);
        }