Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define frames for session handshake #14

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Loading