File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,9 @@ namespace quicr::messages {
14
14
quicr::Bytes& operator <<(quicr::Bytes& buffer, std::uint8_t value);
15
15
quicr::BytesSpan operator >>(quicr::BytesSpan buffer, uint8_t & value);
16
16
17
+ Bytes& operator <<(Bytes& buffer, std::uint16_t value);
18
+ BytesSpan operator >>(BytesSpan buffer, std::uint16_t & value);
19
+
17
20
quicr::Bytes& operator <<(quicr::Bytes& buffer, const quicr::UintVar& value);
18
21
19
22
using GroupId = uint64_t ;
Original file line number Diff line number Diff line change @@ -29,6 +29,14 @@ namespace quicr::messages {
29
29
return buffer;
30
30
}
31
31
32
+ Bytes& operator <<(Bytes& buffer, std::uint16_t value)
33
+ {
34
+ const std::uint16_t swapped = SwapBytes (value);
35
+ buffer.push_back (static_cast <uint8_t >(swapped >> 8 & 0xFF ));
36
+ buffer.push_back (static_cast <uint8_t >(swapped & 0xFF ));
37
+ return buffer;
38
+ }
39
+
32
40
Bytes& operator <<(Bytes& buffer, std::uint64_t value)
33
41
{
34
42
UintVar varint = value;
@@ -51,6 +59,18 @@ namespace quicr::messages {
51
59
return buffer.subspan (sizeof (value));
52
60
}
53
61
62
+ BytesSpan operator >>(BytesSpan buffer, uint16_t & value)
63
+ {
64
+ if (buffer.size () < sizeof (value)) {
65
+ throw std::invalid_argument (" Provider buffer too small" );
66
+ }
67
+ const std::uint16_t high = buffer[0 ];
68
+ const std::uint16_t low = buffer[1 ];
69
+ value = high << 8 | low;
70
+ value = SwapBytes (value);
71
+ return buffer.subspan (sizeof (std::uint16_t ));
72
+ }
73
+
54
74
BytesSpan operator >>(BytesSpan buffer, uint64_t & value)
55
75
{
56
76
UintVar value_uv (buffer);
Original file line number Diff line number Diff line change @@ -978,4 +978,14 @@ TEST_CASE("Key Value Pair encode/decode")
978
978
CHECK_EQ (out.value , value);
979
979
}
980
980
}
981
+ }
982
+
983
+ TEST_CASE (" UInt16 Encode/decode" )
984
+ {
985
+ std::uint16_t value = 65535 ;
986
+ Bytes buffer;
987
+ buffer << value;
988
+ std::uint16_t reconstructed_value = 0 ;
989
+ buffer >> reconstructed_value;
990
+ CHECK_EQ (reconstructed_value, value);
981
991
}
You can’t perform that action at this time.
0 commit comments