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

fix: add unsigned short support in table deserialisation #1270

Merged
merged 3 commits into from
Oct 18, 2022
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
3 changes: 3 additions & 0 deletions projects/RabbitMQ.Client/client/impl/WireFormatting.Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ static object ReadFieldValueSlow(ReadOnlySpan<byte> span, out int bytesRead)
case 's':
bytesRead = 3;
return NetworkOrderDeserializer.ReadInt16(slice);
case 'u':
bytesRead = 3;
return NetworkOrderDeserializer.ReadUInt16(slice);
case 'T':
bytesRead = 1 + ReadTimestamp(slice, out var timestamp);
return timestamp;
Expand Down
6 changes: 6 additions & 0 deletions projects/RabbitMQ.Client/client/impl/WireFormatting.Write.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ static int WriteFieldValueSlow(ref byte destination, ref byte fieldValue, object
case BinaryTableValue val:
destination = (byte)'x';
return 1 + WriteLongstr(ref fieldValue, val.Bytes);
case ushort val:
destination = (byte)'u';
NetworkOrderSerializer.WriteUInt16(ref fieldValue, val);
return 3;
default:
return ThrowInvalidTableValue(value);
}
Expand Down Expand Up @@ -235,6 +239,8 @@ public static int GetFieldValueByteCount(object value)
return 2;
case short _:
return 3;
case ushort _:
return 3;
case uint _:
return 5;
case decimal _:
Expand Down
2 changes: 2 additions & 0 deletions projects/Unit/TestFieldTableFormatting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public void TestQpidJmsTypes()
["f"] = (float)123, // 2+5
["l"] = (long)123, // 2+9
["s"] = (short)123, // 2+2
["u"] = (ushort)123,
["t"] = true // 2+2
};
byte[] xbytes = { 0xaa, 0x55 };
Expand All @@ -159,6 +160,7 @@ public void TestQpidJmsTypes()
Assert.Equal(typeof(float), nt["f"].GetType()); Assert.Equal((float)123, nt["f"]);
Assert.Equal(typeof(long), nt["l"].GetType()); Assert.Equal((long)123, nt["l"]);
Assert.Equal(typeof(short), nt["s"].GetType()); Assert.Equal((short)123, nt["s"]);
Assert.Equal(typeof(ushort), nt["u"].GetType()); Assert.Equal((ushort)123, nt["u"]);
Assert.Equal(true, nt["t"]);
Assert.Equal(xbytes, ((BinaryTableValue)nt["x"]).Bytes);
Assert.Null(nt["V"]);
Expand Down
2 changes: 2 additions & 0 deletions projects/Unit/TestFieldTableFormattingGeneric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public void TestQpidJmsTypes()
["f"] = (float)123,
["l"] = (long)123,
["s"] = (short)123,
["u"] = (ushort)123,
["t"] = true
};
byte[] xbytes = new byte[] { 0xaa, 0x55 };
Expand All @@ -147,6 +148,7 @@ public void TestQpidJmsTypes()
Assert.Equal(typeof(float), nt["f"].GetType()); Assert.Equal((float)123, nt["f"]);
Assert.Equal(typeof(long), nt["l"].GetType()); Assert.Equal((long)123, nt["l"]);
Assert.Equal(typeof(short), nt["s"].GetType()); Assert.Equal((short)123, nt["s"]);
Assert.Equal(typeof(ushort), nt["u"].GetType()); Assert.Equal((ushort)123, nt["u"]);
Assert.Equal(true, nt["t"]);
Assert.Equal(xbytes, ((BinaryTableValue)nt["x"]).Bytes);
Assert.Null(nt["V"]);
Expand Down