1818namespace sourcemeta ::jsonbinpack {
1919
2020// / @ingroup runtime
21- template <typename CharT, typename Traits>
22- class Encoder : private BasicEncoder <CharT, Traits> {
21+ class Encoder : private BasicEncoder {
2322public:
24- Encoder (std::basic_ostream<CharT, Traits> &output)
25- : BasicEncoder<CharT, Traits>{output} {}
23+ Encoder (std::basic_ostream<sourcemeta::jsontoolkit::JSON::Char,
24+ sourcemeta::jsontoolkit::JSON::CharTraits> &output)
25+ : BasicEncoder{output} {}
2626
2727 auto encode (const sourcemeta::jsontoolkit::JSON &document,
2828 const Plan &encoding) -> void {
@@ -203,18 +203,20 @@ class Encoder : private BasicEncoder<CharT, Traits> {
203203 auto UTF8_STRING_NO_LENGTH (const sourcemeta::jsontoolkit::JSON &document,
204204 const UTF8_STRING_NO_LENGTH &options) -> void {
205205 assert (document.is_string ());
206- const std::basic_string<CharT> value{document.to_string ()};
206+ const std::basic_string<sourcemeta::jsontoolkit::JSON::Char> value{
207+ document.to_string ()};
207208 this ->put_string_utf8 (value, options.size );
208209 }
209210
210211 auto FLOOR_VARINT_PREFIX_UTF8_STRING_SHARED (
211212 const sourcemeta::jsontoolkit::JSON &document,
212213 const FLOOR_VARINT_PREFIX_UTF8_STRING_SHARED &options) -> void {
213214 assert (document.is_string ());
214- const std::basic_string<CharT> value{document.to_string ()};
215+ const std::basic_string<sourcemeta::jsontoolkit::JSON::Char> value{
216+ document.to_string ()};
215217 const auto size{value.size ()};
216218 assert (document.size () == size);
217- const bool is_shared{this ->context ().has (value, ContextType ::Standalone)};
219+ const bool is_shared{this ->context ().has (value, Context::Type ::Standalone)};
218220
219221 // (1) Write 0x00 if shared, else do nothing
220222 if (is_shared) {
@@ -226,10 +228,12 @@ class Encoder : private BasicEncoder<CharT, Traits> {
226228
227229 // (3) Write relative offset if shared, else write plain string
228230 if (is_shared) {
229- this ->put_varint (this ->position () -
230- this ->context ().offset (value, ContextType::Standalone));
231+ this ->put_varint (
232+ this ->position () -
233+ this ->context ().offset (value, Context::Type::Standalone));
231234 } else {
232- this ->context ().record (value, this ->position (), ContextType::Standalone);
235+ this ->context ().record (value, this ->position (),
236+ Context::Type::Standalone);
233237 this ->put_string_utf8 (value, size);
234238 }
235239 }
@@ -238,11 +242,12 @@ class Encoder : private BasicEncoder<CharT, Traits> {
238242 const sourcemeta::jsontoolkit::JSON &document,
239243 const ROOF_VARINT_PREFIX_UTF8_STRING_SHARED &options) -> void {
240244 assert (document.is_string ());
241- const std::basic_string<CharT> value{document.to_string ()};
245+ const std::basic_string<sourcemeta::jsontoolkit::JSON::Char> value{
246+ document.to_string ()};
242247 const auto size{value.size ()};
243248 assert (document.size () == size);
244249 assert (size <= options.maximum );
245- const bool is_shared{this ->context ().has (value, ContextType ::Standalone)};
250+ const bool is_shared{this ->context ().has (value, Context::Type ::Standalone)};
246251
247252 // (1) Write 0x00 if shared, else do nothing
248253 if (is_shared) {
@@ -254,10 +259,12 @@ class Encoder : private BasicEncoder<CharT, Traits> {
254259
255260 // (3) Write relative offset if shared, else write plain string
256261 if (is_shared) {
257- this ->put_varint (this ->position () -
258- this ->context ().offset (value, ContextType::Standalone));
262+ this ->put_varint (
263+ this ->position () -
264+ this ->context ().offset (value, Context::Type::Standalone));
259265 } else {
260- this ->context ().record (value, this ->position (), ContextType::Standalone);
266+ this ->context ().record (value, this ->position (),
267+ Context::Type::Standalone);
261268 this ->put_string_utf8 (value, size);
262269 }
263270 }
@@ -266,13 +273,14 @@ class Encoder : private BasicEncoder<CharT, Traits> {
266273 const sourcemeta::jsontoolkit::JSON &document,
267274 const BOUNDED_8BIT_PREFIX_UTF8_STRING_SHARED &options) -> void {
268275 assert (document.is_string ());
269- const std::basic_string<CharT> value{document.to_string ()};
276+ const std::basic_string<sourcemeta::jsontoolkit::JSON::Char> value{
277+ document.to_string ()};
270278 const auto size{value.size ()};
271279 assert (document.size () == size);
272280 assert (options.minimum <= options.maximum );
273281 assert (is_byte (options.maximum - options.minimum + 1 ));
274282 assert (is_within (size, options.minimum , options.maximum ));
275- const bool is_shared{this ->context ().has (value, ContextType ::Standalone)};
283+ const bool is_shared{this ->context ().has (value, Context::Type ::Standalone)};
276284
277285 // (1) Write 0x00 if shared, else do nothing
278286 if (is_shared) {
@@ -284,10 +292,12 @@ class Encoder : private BasicEncoder<CharT, Traits> {
284292
285293 // (3) Write relative offset if shared, else write plain string
286294 if (is_shared) {
287- this ->put_varint (this ->position () -
288- this ->context ().offset (value, ContextType::Standalone));
295+ this ->put_varint (
296+ this ->position () -
297+ this ->context ().offset (value, Context::Type::Standalone));
289298 } else {
290- this ->context ().record (value, this ->position (), ContextType::Standalone);
299+ this ->context ().record (value, this ->position (),
300+ Context::Type::Standalone);
291301 this ->put_string_utf8 (value, size);
292302 }
293303 }
@@ -320,25 +330,27 @@ class Encoder : private BasicEncoder<CharT, Traits> {
320330 const sourcemeta::jsontoolkit::JSON &document,
321331 const PREFIX_VARINT_LENGTH_STRING_SHARED &) -> void {
322332 assert (document.is_string ());
323- const std::basic_string<CharT> value{document.to_string ()};
333+ const std::basic_string<sourcemeta::jsontoolkit::JSON::Char> value{
334+ document.to_string ()};
324335
325- if (this ->context ().has (value, ContextType ::PrefixLengthVarintPlusOne)) {
336+ if (this ->context ().has (value, Context::Type ::PrefixLengthVarintPlusOne)) {
326337 const auto new_offset{this ->position ()};
327338 this ->put_byte (0 );
328339 this ->put_varint (this ->position () -
329340 this ->context ().offset (
330- value, ContextType ::PrefixLengthVarintPlusOne));
341+ value, Context::Type ::PrefixLengthVarintPlusOne));
331342 // Bump the context cache for locality purposes
332343 this ->context ().record (value, new_offset,
333- ContextType ::PrefixLengthVarintPlusOne);
344+ Context::Type ::PrefixLengthVarintPlusOne);
334345 } else {
335346 const auto size{value.size ()};
336347 assert (document.size () == size);
337348 this ->context ().record (value, this ->position (),
338- ContextType ::PrefixLengthVarintPlusOne);
349+ Context::Type ::PrefixLengthVarintPlusOne);
339350 this ->put_varint (size + 1 );
340351 // Also record a standalone variant of it
341- this ->context ().record (value, this ->position (), ContextType::Standalone);
352+ this ->context ().record (value, this ->position (),
353+ Context::Type::Standalone);
342354 this ->put_string_utf8 (value, size);
343355 }
344356 }
@@ -460,20 +472,22 @@ class Encoder : private BasicEncoder<CharT, Traits> {
460472 this ->put_varint (absolute);
461473 }
462474 } else if (document.is_string ()) {
463- const std::basic_string<CharT> value{document.to_string ()};
475+ const std::basic_string<sourcemeta::jsontoolkit::JSON::Char> value{
476+ document.to_string ()};
464477 const auto size{document.byte_size ()};
465- const bool is_shared{this ->context ().has (value, ContextType::Standalone)};
478+ const bool is_shared{
479+ this ->context ().has (value, Context::Type::Standalone)};
466480 if (size < uint_max<5 >) {
467481 const std::uint8_t type{is_shared ? TYPE_SHARED_STRING : TYPE_STRING};
468482 this ->put_byte (
469483 static_cast <std::uint8_t >(type | ((size + 1 ) << type_size)));
470484 if (is_shared) {
471485 this ->put_varint (
472486 this ->position () -
473- this ->context ().offset (value, ContextType ::Standalone));
487+ this ->context ().offset (value, Context::Type ::Standalone));
474488 } else {
475489 this ->context ().record (value, this ->position (),
476- ContextType ::Standalone);
490+ Context::Type ::Standalone);
477491 this ->put_string_utf8 (value, size);
478492 }
479493 } else if (size >= uint_max<5 > && size < uint_max<5 > * 2 && !is_shared) {
@@ -539,9 +553,6 @@ class Encoder : private BasicEncoder<CharT, Traits> {
539553 }
540554
541555#endif
542-
543- private:
544- using ContextType = typename Context<CharT>::Type;
545556};
546557
547558} // namespace sourcemeta::jsonbinpack
0 commit comments