-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
40 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
namespace ActiveMQ.Artemis.Core.Client.Framing; | ||
|
||
internal static class Codec | ||
{ | ||
public static void Encode(ByteBuffer buffer, Packet packet, long channelId) | ||
{ | ||
buffer.WriteInt(0); // The length gets filled in at the end | ||
|
||
var type = packet switch | ||
{ | ||
CreateSessionMessageV2 => CreateSessionMessageV2.Type, | ||
_ => throw new ArgumentOutOfRangeException(nameof(packet), packet, $"{packet.GetType()} is not supported for encoding") | ||
}; | ||
buffer.WriteByte(type); | ||
buffer.WriteLong(channelId); | ||
|
||
packet.Encode(buffer); | ||
|
||
buffer.WriteSize(); | ||
} | ||
|
||
public static (Packet packet, long channelId) Decode(ByteBuffer buffer) | ||
{ | ||
var type = buffer.ReadByte(); | ||
var channelId = buffer.ReadLong(); | ||
|
||
Packet packet = type switch | ||
{ | ||
CreateSessionResponseMessage.Type => new CreateSessionResponseMessage(), | ||
_ => throw new ArgumentOutOfRangeException($"Type {type} is not supported for decoding") | ||
}; | ||
|
||
packet.Decode(buffer); | ||
|
||
return (packet, channelId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters