-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathencoder_object.cc
More file actions
32 lines (25 loc) · 1018 Bytes
/
Copy pathencoder_object.cc
File metadata and controls
32 lines (25 loc) · 1018 Bytes
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
#include <sourcemeta/jsonbinpack/runtime_encoder.h>
#include <cassert> // assert
namespace sourcemeta::jsonbinpack {
auto Encoder::FIXED_TYPED_ARBITRARY_OBJECT(
const sourcemeta::core::JSON &document,
const struct FIXED_TYPED_ARBITRARY_OBJECT &options) -> void {
assert(document.is_object());
assert(document.size() == options.size);
for (const auto &entry : document.as_object()) {
this->write(sourcemeta::core::JSON{entry.first}, *(options.key_encoding));
this->write(entry.second, *(options.encoding));
}
}
auto Encoder::VARINT_TYPED_ARBITRARY_OBJECT(
const sourcemeta::core::JSON &document,
const struct VARINT_TYPED_ARBITRARY_OBJECT &options) -> void {
assert(document.is_object());
const auto size{document.size()};
this->put_varint(size);
for (const auto &entry : document.as_object()) {
this->write(sourcemeta::core::JSON{entry.first}, *(options.key_encoding));
this->write(entry.second, *(options.encoding));
}
}
} // namespace sourcemeta::jsonbinpack