Skip to content

Commit

Permalink
Define frames for session handshake
Browse files Browse the repository at this point in the history
  • Loading branch information
Havret committed Mar 8, 2024
1 parent e2f77cd commit 6b2a0c6
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ArtemisNetCoreClient/ByteBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,10 @@ private string ReadAsShorts(int length)
var value = _memoryStream.ReadByte();
return value == DataConstants.NotNull ? ReadString() : null;
}

public void WriteSize()
{
_memoryStream.TryGetBuffer(out var buffer);
BinaryPrimitives.WriteInt32BigEndian(buffer, buffer.Count - sizeof(int));
}
}
51 changes: 51 additions & 0 deletions src/ArtemisNetCoreClient/Framing/CreateSessionMessageV2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
namespace ActiveMQ.Artemis.Core.Client.Framing;

internal class CreateSessionMessageV2 : Packet
{
public override byte Type => unchecked((byte) -18);
public required string Name { get; init; }
public long SessionChannelId { get; init; }
public int Version { get; init; }
public string? Username { get; init; }
public string? Password { get; init; }
public int MinLargeMessageSize { get; init; }
public bool Xa { get; init; }
public bool AutoCommitSends { get; init; }
public bool AutoCommitAcks { get; init; }
public bool PreAcknowledge { get; init; }
public int WindowSize { get; init; }
public string? DefaultAddress { get; init; }
public string? ClientId { get; init; }
public long ChannelId { get; init; }

public override void Encode(ByteBuffer buffer)
{
// header
buffer.WriteInt(0); // The length gets filled in at the end
buffer.WriteByte(Type);
buffer.WriteLong(ChannelId);

// rest
buffer.WriteString(Name);
buffer.WriteLong(SessionChannelId);
buffer.WriteInt(Version);
buffer.WriteNullableString(Username);
buffer.WriteNullableString(Password);
buffer.WriteInt(MinLargeMessageSize);
buffer.WriteBool(Xa);
buffer.WriteBool(AutoCommitSends);
buffer.WriteBool(AutoCommitAcks);
buffer.WriteInt(WindowSize);
buffer.WriteBool(PreAcknowledge);
buffer.WriteNullableString(DefaultAddress);
buffer.WriteNullableString(ClientId);

// size
buffer.WriteSize();
}

public override void Decode(ByteBuffer buffer)
{
throw new NotImplementedException();
}
}
21 changes: 21 additions & 0 deletions src/ArtemisNetCoreClient/Framing/CreateSessionResponseMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace ActiveMQ.Artemis.Core.Client.Framing;

internal class CreateSessionResponseMessage : Packet
{
public long ChannelId { get; private set; }
public int ServerVersion { get; private set; }

public override byte Type { get; } = 31;

public override void Encode(ByteBuffer buffer)
{
throw new NotImplementedException();
}

public override void Decode(ByteBuffer buffer)
{
_ = buffer.ReadByte(); // type
ChannelId = buffer.ReadLong();
ServerVersion = buffer.ReadInt();
}
}
8 changes: 8 additions & 0 deletions src/ArtemisNetCoreClient/Framing/Packet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace ActiveMQ.Artemis.Core.Client.Framing;

internal abstract class Packet
{
public abstract byte Type { get; }
public abstract void Encode(ByteBuffer buffer);
public abstract void Decode(ByteBuffer buffer);
}

0 comments on commit 6b2a0c6

Please sign in to comment.