Example #1
0
        public static PacketPayload.CursorWritingContext StartWriting(MemoryCursor cursor,
                                                                      PacketVersion version,
                                                                      PacketConnectionId destinationConnectionId,
                                                                      PacketConnectionId sourceConnectionId,
                                                                      PacketNumber packetNumber,
                                                                      PacketToken token)
        {
            var startOffset = cursor.AsOffset();
            var firstByte   = new PacketFirstByte()
                              .SetInitial()
                              .SetMaxPacketNumberLength();

            firstByte.Write(cursor);
            version.WriteBytes(cursor);
            destinationConnectionId.WriteBytes(cursor);
            sourceConnectionId.WriteBytes(cursor);
            token.WriteBytes(cursor);

            var context           = PacketPayload.StartPacketWriting(cursor, startOffset);
            var packetNumberBytes = firstByte.SlicePacketNumberBytes(cursor);

            packetNumber.Fill(packetNumberBytes.Span);

            return(context);
        }
Example #2
0
        public static PacketPayload.CursorWritingContext StartWriting(MemoryCursor cursor,
                                                                      PacketVersion version,
                                                                      PacketConnectionId destinationConnectionId,
                                                                      PacketConnectionId sourceConnectionId,
                                                                      PacketNumber largestAcknowledgedPacketNumber,
                                                                      PacketNumber packetNumber)
        {
            var startOffset = cursor.AsOffset();
            var firstByte   = new PacketFirstByte()
                              .SetHandshake()
                              .SetMaxPacketNumberLength();

            firstByte.Write(cursor);
            version.WriteBytes(cursor);
            destinationConnectionId.WriteBytes(cursor);
            sourceConnectionId.WriteBytes(cursor);

            var context           = PacketPayload.StartPacketWriting(cursor, startOffset);
            var packetNumberBytes = firstByte.SlicePacketNumberBytes(cursor);

            packetNumber
            .EncodeByLargestAcknowledged(largestAcknowledgedPacketNumber)
            .Fill(packetNumberBytes.Span);

            return(context);
        }