-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathserialize_subscribe_update_message.cpp
More file actions
88 lines (74 loc) · 3.42 KB
/
serialize_subscribe_update_message.cpp
File metadata and controls
88 lines (74 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "test_serialization_utils.hpp"
#include <cassert>
#include <iostream>
#include <serialization/chunk.hpp>
#include <serialization/deserialization_impl.hpp>
#include <serialization/messages.hpp>
#include <serialization/serialization_impl.hpp>
#include <utilities.hpp>
using namespace rvn;
using namespace rvn::serialization;
void test_serialize_subscribe_error()
{
SubscribeUpdateMessage msg;
ds::chunk c;
msg.requestId_ = 0x12345678;
GroupId group(0x87654321);
ObjectId object(0x11111111);
msg.startLocation_.group_ = group;
msg.startLocation_.object_ = object;
msg.endGroup_ = 0;
msg.subscriberPriority_ = 255;
msg.forward_ = 100;
Parameter param;
msg.parameters_.push_back(param);
serialization::detail::serialize(c, msg);
// clang-format off
/*
00000010 00011000 10010010 00110100 01010110 01111000 11000000 00000000 00000000 00000000 10000111 01100101 01000011 00100001
[msg type 0x02] [msg len 18] [requestId 0x12345678] [groupId 0x87654321]
10010001 00010001 00010001 00010001 00000000 11111111 01100100 00000001 00000011
[objectId 0x11111111] [endGroup 0] [subscriberPriority 255] [forward 100] [Number of Parameters 1] [Parameter Type 0x03]
00000001 00000000
[Parameter Length] [Timeout 0]
*/
std::string expectedSerializationString = "00000010 00011000 10010010 00110100 01010110 01111000 11000000 00000000 00000000 00000000 10000111 01100101 01000011 00100001 10010001 00010001 00010001 00010001 00000000 11111111 01100100 00000001 00000011 00000001 00000000";
// // clang-format on
auto expectedSerialization = binary_string_to_vector(expectedSerializationString);
utils::ASSERT_LOG_THROW(c.size() == expectedSerialization.size(), "Size mismatch\n",
"Expected size: ", expectedSerialization.size(),
"\n", "Actual size: ", c.size(), "\n");
for (std::size_t i = 0; i < c.size(); i++)
utils::ASSERT_LOG_THROW(c[i] == expectedSerialization[i], "Mismatch at index: ", i,
"\n", "Expected: ", int(expectedSerialization[i]),
"\n", "Actual: ", int(c[i]), "\n");
ds::ChunkSpan span(c);
ControlMessageHeader header;
serialization::detail::deserialize(header, span);
utils::ASSERT_LOG_THROW(header.messageType_ == MoQtMessageType::SUBSCRIBE_UPDATE,
"Message type mismatch\n", "Expected: ",
utils::to_underlying(MoQtMessageType::SUBSCRIBE_UPDATE), "\n",
"Actual: ", utils::to_underlying(header.messageType_), "\n");
SubscribeUpdateMessage deserializedMsg;
serialization::detail::deserialize(deserializedMsg, span);
std::cout << "Deserialization Succesfull !!" << std::endl;
utils::ASSERT_LOG_THROW(msg == deserializedMsg, "Deserialization failed\n",
"Expected: ", msg, "\n", "Actual: ", deserializedMsg, "\n");
}
void tests()
{
try
{
test_serialize_subscribe_error();
}
catch (const std::exception& e)
{
std::cerr << "test failed\n";
std::cerr << e.what() << '\n';
}
}
int main()
{
tests();
return 0;
}