Skip to content

Commit 65dd5f9

Browse files
authored
Merge pull request #1271 from gytsen/6.x
fix: add unsigned short support in table protocol
2 parents 6b6b672 + 3a2c454 commit 65dd5f9

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

projects/RabbitMQ.Client/client/impl/WireFormatting.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ public static object ReadFieldValue(ReadOnlySpan<byte> span, out int bytesRead)
152152
case 's':
153153
bytesRead += 2;
154154
return NetworkOrderDeserializer.ReadInt16(span.Slice(1));
155+
case 'u':
156+
bytesRead += 2;
157+
return NetworkOrderDeserializer.ReadUInt16(span.Slice(1));
155158
case 't':
156159
bytesRead += 1;
157160
return span[1] != 0;
@@ -342,6 +345,10 @@ public static int WriteFieldValue(Span<byte> span, object value)
342345
span[0] = (byte)'s';
343346
NetworkOrderSerializer.WriteInt16(slice, val);
344347
return 3;
348+
case ushort val:
349+
span[0] = (byte)'u';
350+
NetworkOrderSerializer.WriteUInt16(slice, val);
351+
return 3;
345352
case bool val:
346353
span[0] = (byte)'t';
347354
span[1] = (byte)(val ? 1 : 0);
@@ -365,6 +372,7 @@ public static int GetFieldValueByteCount(object value)
365372
case bool _:
366373
return 2;
367374
case short _:
375+
case ushort _:
368376
return 3;
369377
case int _:
370378
case uint _:

projects/Unit/TestFieldTableFormatting.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public void TestQpidJmsTypes()
144144
["f"] = (float)123, // 2+5
145145
["l"] = (long)123, // 2+9
146146
["s"] = (short)123, // 2+2
147+
["u"] = (ushort)123,
147148
["t"] = true // 2+2
148149
};
149150
byte[] xbytes = { 0xaa, 0x55 };
@@ -160,6 +161,7 @@ public void TestQpidJmsTypes()
160161
Assert.AreEqual(typeof(float), nt["f"].GetType()); Assert.AreEqual((float)123, nt["f"]);
161162
Assert.AreEqual(typeof(long), nt["l"].GetType()); Assert.AreEqual((long)123, nt["l"]);
162163
Assert.AreEqual(typeof(short), nt["s"].GetType()); Assert.AreEqual((short)123, nt["s"]);
164+
Assert.AreEqual(typeof(ushort), nt["u"].GetType()); Assert.AreEqual((ushort)123, nt["u"]);
163165
Assert.AreEqual(true, nt["t"]);
164166
Assert.AreEqual(xbytes, ((BinaryTableValue)nt["x"]).Bytes);
165167
Assert.AreEqual(null, nt["V"]);

projects/Unit/TestFieldTableFormattingGeneric.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public void TestQpidJmsTypes()
131131
["f"] = (float)123,
132132
["l"] = (long)123,
133133
["s"] = (short)123,
134+
["u"] = (ushort)123,
134135
["t"] = true
135136
};
136137
byte[] xbytes = new byte[] { 0xaa, 0x55 };
@@ -147,6 +148,7 @@ public void TestQpidJmsTypes()
147148
Assert.AreEqual(typeof(float), nt["f"].GetType()); Assert.AreEqual((float)123, nt["f"]);
148149
Assert.AreEqual(typeof(long), nt["l"].GetType()); Assert.AreEqual((long)123, nt["l"]);
149150
Assert.AreEqual(typeof(short), nt["s"].GetType()); Assert.AreEqual((short)123, nt["s"]);
151+
Assert.AreEqual(typeof(ushort), nt["u"].GetType()); Assert.AreEqual((ushort)123, nt["u"]);
150152
Assert.AreEqual(true, nt["t"]);
151153
Assert.AreEqual(xbytes, ((BinaryTableValue)nt["x"]).Bytes);
152154
Assert.AreEqual(null, nt["V"]);

0 commit comments

Comments
 (0)