public override void Encode(IByteBuffer buffer) { var buf = Unpooled.Buffer(); try { if (SessionPresent) { buf.WriteByte(1); // 7 reserved 0-bits and SP = 1 } else { buf.WriteByte(0); // 7 reserved 0-bits and SP = 0 } buf.WriteByte((byte)ConnectReturnCode); FixedHeader.RemaingLength = buf.ReadableBytes; FixedHeader.WriteFixedHeader(buffer); buffer.WriteBytes(buf); } finally { buf?.SafeRelease(); } }
/// <summary> /// EncodePacketIdVariableHeader /// </summary> /// <param name="buffer"></param> public override void Encode(IByteBuffer buffer) { var buf = Unpooled.Buffer(); try { WritePacketId(buf); FixedHeader.RemaingLength = buf.ReadableBytes; FixedHeader.WriteFixedHeader(buffer); buffer.WriteBytes(buf); buf = null; } finally { buf?.Release(); } }
public override void Encode(IByteBuffer buffer) { var buf = Unpooled.Buffer(); try { // variable header buf.WriteString(ProtocolName); //byte 1 - 8 buf.WriteByte(ProtocolLevel); //byte 9 // connect flags; //byte 10 var flags = UsernameFlag.ToByte() << 7; flags |= PasswordFlag.ToByte() << 6; flags |= WillRetain.ToByte() << 5; flags |= ((byte)WillQos) << 3; flags |= WillFlag.ToByte() << 2; flags |= CleanSession.ToByte() << 1; buf.WriteByte((byte)flags); // keep alive buf.WriteShort(KeepAlive); //byte 11 - 12 // payload buf.WriteString(ClientId); if (WillFlag) { buf.WriteString(WillTopic); buf.WriteBytes(WillMessage); } if (UsernameFlag && PasswordFlag) { buf.WriteString(UserName); buf.WriteString(Password); } FixedHeader.RemaingLength = buf.ReadableBytes; FixedHeader.WriteFixedHeader(buffer); buffer.WriteBytes(buf); } finally { buf?.SafeRelease(); } }
public override void Encode(IByteBuffer buffer) { var buf = Unpooled.Buffer(); try { buf.WriteString(TopicName); WritePacketId(buf); buf.WriteBytes(Payload, 0, Payload.Length); FixedHeader.RemaingLength = buf.ReadableBytes; FixedHeader.WriteFixedHeader(buffer); buffer.WriteBytes(buf); } finally { buf?.Release(); } }
public override void Encode(IByteBuffer buffer) { var buf = Unpooled.Buffer(); try { buf.WriteShort(PacketId); foreach (var item in _topics) { buf.WriteString(item); } FixedHeader.RemaingLength = buf.ReadableBytes; FixedHeader.WriteFixedHeader(buffer); buffer.WriteBytes(buf); } finally { buf?.Release(); } }