11#include " openmoq/publisher/transport/moqt_control_messages.h"
22
33#include < cstdint>
4+ #include < cstddef>
5+ #include < optional>
46#include < iostream>
57#include < span>
68#include < string>
@@ -20,6 +22,7 @@ using openmoq::publisher::transport::decode_server_setup_message;
2022using openmoq::publisher::transport::decode_varint;
2123using openmoq::publisher::transport::encode_request_ok_message;
2224using openmoq::publisher::transport::encode_setup_message;
25+ using openmoq::publisher::transport::encode_subgroup_object;
2326
2427bool expect (bool condition, const std::string& message) {
2528 if (!condition) {
@@ -152,5 +155,37 @@ int main() {
152155 ok &= expect (message.request_id == 7 , " expected draft-16 request_ok request_id to remain parsed" );
153156 }
154157
158+ {
159+ const std::vector<std::uint8_t > payload = {0xaa , 0xbb , 0xcc };
160+ const std::vector<std::uint8_t > bytes =
161+ encode_subgroup_object (DraftVersion::kDraft18 , std::nullopt , 0 , payload);
162+ std::size_t offset = 0 ;
163+ std::uint64_t object_id_delta = 99 ;
164+ std::uint64_t payload_length = 99 ;
165+ ok &= expect (decode_varint (bytes, offset, object_id_delta) && object_id_delta == 0 ,
166+ " expected draft-18 first subgroup object id delta" );
167+ ok &= expect (decode_varint (bytes, offset, payload_length) && payload_length == payload.size (),
168+ " expected draft-18 payload length immediately after object id delta" );
169+ ok &= expect (offset + payload_length == bytes.size (), " expected draft-18 payload object to omit status" );
170+ ok &= expect (std::vector<std::uint8_t >(bytes.begin () + static_cast <std::ptrdiff_t >(offset), bytes.end ()) == payload,
171+ " expected draft-18 payload bytes after length" );
172+ }
173+
174+ {
175+ const std::vector<std::uint8_t > bytes =
176+ encode_subgroup_object (DraftVersion::kDraft18 , std::nullopt , 0 , {});
177+ std::size_t offset = 0 ;
178+ std::uint64_t object_id_delta = 99 ;
179+ std::uint64_t payload_length = 99 ;
180+ std::uint64_t object_status = 99 ;
181+ ok &= expect (decode_varint (bytes, offset, object_id_delta) && object_id_delta == 0 ,
182+ " expected draft-18 empty object id delta" );
183+ ok &= expect (decode_varint (bytes, offset, payload_length) && payload_length == 0 ,
184+ " expected draft-18 empty object payload length" );
185+ ok &= expect (decode_varint (bytes, offset, object_status) && object_status == 0 ,
186+ " expected draft-18 empty object status after zero length" );
187+ ok &= expect (offset == bytes.size (), " expected draft-18 empty object to contain no payload" );
188+ }
189+
155190 return ok ? 0 : 1 ;
156191}
0 commit comments