Twitch SDK (Internal)
jsonserialization.h
Go to the documentation of this file.
1 /********************************************************************************************
2  * Twitch Broadcasting SDK
3  *
4  * This software is supplied under the terms of a license agreement with Twitch Interactive, Inc. and
5  * may not be copied or used except in accordance with the terms of that agreement
6  * Copyright (c) 2012-2016 Twitch Interactive, Inc.
7  *********************************************************************************************/
8 
9 #pragma once
10 
17 
18 namespace ttv
19 {
20  namespace json
21  {
32  template <typename ObjectType>
33  bool ToJson(const ObjectType& object, ttv::json::Value& value);
34 
41  template <typename ObjectType>
42  bool ToJsonString(const ObjectType& object, std::string& jsonString);
43 
50  template <typename ObjectType>
51  bool ToObject(const ttv::json::Value& value, ObjectType& object);
52 
59  template <typename ObjectType>
60  bool ToObject(const std::string& jsonString, ObjectType& object);
61 
68  template <typename ObjectType>
69  bool ToObject(const char* jsonString, ObjectType& object);
70 
95  struct IntegerSchema;
96  struct FloatingPointSchema;
97  struct StringSchema;
98  struct BooleanSchema;
99  struct DateSchema;
100  struct ColorSchema;
101 
102  template <typename ElementSchema, typename ElementType>
103  struct ArraySchema;
104 
126  template <typename EnumDescription>
127  struct EnumSchema;
128 
134  template <typename EnumType>
135  class EnumMapping;
136 
142  template <typename EnumType>
143  auto make_enum_mapping(const char* string, EnumType value);
144 
164  template <typename ObjectDescription>
165  struct ObjectSchema;
166 
171  struct RequiredField;
172  struct OptionalField;
173 
178  template <typename ValueType, typename RequiredType, typename SchemaType, size_t KeyPathSize>
179  class JsonField;
180 
190  template <typename SchemaType, typename RequiredType, typename ObjectType>
191  auto make_field(const char* key, ObjectType& field);
192 
193  template <typename SchemaType, typename RequiredType, typename ObjectType, size_t ArraySize>
194  auto make_field(const std::array<const char*, ArraySize>& keyPath, ObjectType& field);
195 
202  template <typename RequiredType, typename ObjectType>
203  auto make_field(const char* key, ObjectType& field);
204 
205  template <typename RequiredType, typename ObjectType, size_t ArraySize>
206  auto make_field(const std::array<const char*, ArraySize>& keyPath, ObjectType& field);
207 
213  template <typename ObjectType>
214  auto make_field(const char* key, ObjectType& field);
215 
216  template <typename ObjectType, size_t ArraySize>
217  auto make_field(const std::array<const char*, ArraySize>& keyPath, ObjectType& field);
218 
234  template <typename ObjectType, typename Enable = void>
236 
240  template <typename ObjectType>
242 
246  template <typename ...Args>
247  std::array<const char*, sizeof...(Args)> MakeKeyPath(Args... args);
248  }
249 }
250 
251 
252 template <typename ObjectType>
253 bool ttv::json::ToJson(const ObjectType& object, ttv::json::Value& value)
254 {
255  return DefaultSchema<std::decay_t<ObjectType>>::Emit(object, value);
256 }
257 
258 
259 template <typename ObjectType>
260 bool ttv::json::ToJsonString(const ObjectType& object, std::string& jsonString)
261 {
262  ttv::json::Value value;
263  if (ToJson(object, value))
264  {
265  ttv::json::FastWriter writer;
266  jsonString = writer.write(value);
267  return true;
268  }
269  else
270  {
271  return false;
272  }
273 }
274 
275 
276 template <typename ObjectType>
277 bool ttv::json::ToObject(const ttv::json::Value& value, ObjectType& object)
278 {
279  return DefaultSchema<std::decay_t<ObjectType>>::Parse(value, object);
280 }
281 
282 
283 template <typename ObjectType>
284 bool ttv::json::ToObject(const std::string& jsonString, ObjectType& object)
285 {
286  ttv::json::Value value;
287  ttv::json::Reader reader;
288  if (reader.parse(jsonString, value))
289  {
290  return ToObject(value, object);
291  }
292  else
293  {
294  return false;
295  }
296 }
297 
298 
299 template <typename ObjectType>
300 bool ttv::json::ToObject(const char* jsonString, ObjectType& object)
301 {
302  return ToObject(std::string{jsonString}, object);
303 }
304 
305 
307 {
308  template <typename IntegralType>
309  static bool Parse(const ttv::json::Value& value, IntegralType& output)
310  {
311  if (value.isNull())
312  {
313  return false;
314  }
315  else if (value.isString())
316  {
317  return ParseNum(value.asString(), output);
318  }
319  else if (value.isNumeric())
320  {
321  output = static_cast<IntegralType>(value.asUInt());
322  return true;
323  }
324  else
325  {
326  return false;
327  }
328  }
329 
330 
331  template <typename IntegralType>
332  static bool Emit(IntegralType input, ttv::json::Value& value)
333  {
334  value = static_cast<ttv::json::Value::UInt>(input);
335  return true;
336  }
337 };
338 
339 
341 {
342  template <typename FloatingPointType>
343  static bool Parse(const ttv::json::Value& value, FloatingPointType& output)
344  {
345  if (value.isNull())
346  {
347  return false;
348  }
349  else if (value.isNumeric())
350  {
351  output = static_cast<FloatingPointType>(value.asDouble());
352  return true;
353  }
354  else
355  {
356  return false;
357  }
358  }
359 
360 
361  template <typename FloatingPointType>
362  static bool Emit(FloatingPointType input, ttv::json::Value& value)
363  {
364  value = static_cast<double>(input);
365  return true;
366  }
367 };
368 
369 
371 {
372  static bool Parse(const ttv::json::Value& value, std::string& output)
373  {
374  if (value.isNull() || !value.isString())
375  {
376  return false;
377  }
378  else
379  {
380  output = value.asString();
381  return true;
382  }
383  }
384 
385 
386  static bool Emit(const std::string& input, ttv::json::Value& value)
387  {
388  value = input;
389  return true;
390  }
391 };
392 
393 
395 {
396  static bool Parse(const ttv::json::Value& value, bool& output)
397  {
398  if (value.isNull() || !value.isBool())
399  {
400  return false;
401  }
402  else
403  {
404  output = value.asBool();
405  return true;
406  }
407  }
408 
409 
410  static bool Emit(const bool& input, ttv::json::Value& value)
411  {
412  value = input;
413  return true;
414  }
415 };
416 
417 
419 {
420  static bool Parse(const ttv::json::Value& value, ttv::Timestamp& output)
421  {
422  if (value.isNull())
423  {
424  return false;
425  }
426  else if (value.isNumeric())
427  {
428  output = static_cast<Timestamp>(value.asUInt());
429  return true;
430  }
431  else if (value.isString())
432  {
433  return ttv::RFC3339TimeToUnixTimestamp(value.asString(), output);
434  }
435  else
436  {
437  return false;
438  }
439  }
440 
441 
442  static bool Emit(ttv::Timestamp input, ttv::json::Value& value)
443  {
444  value = ttv::UnixTimestampToRFC3339String(input);
445  return true;
446  }
447 };
448 
449 
451 {
452  static bool Parse(const ttv::json::Value& value, ttv::Color& output)
453  {
454  output = 0xFF000000;
455 
456  if (value.isNull())
457  {
458  return false;
459  }
460  else if (value.isString())
461  {
462  return ParseColor(value.asString(), output);
463  }
464  else
465  {
466  return false;
467  }
468  }
469 
470  // Emit(ttv::Color, ttv::json::Value&) intentionally unimplemented
471 };
472 
473 
474 template <typename ElementSchema, typename ElementType>
476 {
477  template <typename ContainerType>
478  static bool Parse(const ttv::json::Value& value, ContainerType& output)
479  {
480  if (value.isNull() || !value.isArray())
481  {
482  return false;
483  }
484 
485  for (const auto& element : value)
486  {
487  output.emplace_back();
488  if (!ElementSchema::Parse(element, output.back()))
489  {
490  output.clear();
491  return false;
492  }
493  }
494 
495  return true;
496  }
497 
498 
499  template <typename ContainerType>
500  static bool Emit(const ContainerType& input, ttv::json::Value& value)
501  {
502  for (const auto& element : input)
503  {
504  ttv::json::Value elementValue;
505  if (ElementSchema::Emit(element, value))
506  {
507  value.append(elementValue);
508  }
509  else
510  {
511  value = ttv::json::nullValue;
512  return false;
513  }
514  }
515  return true;
516  }
517 };
518 
519 
520 template <typename EnumDescription>
522 {
523  template <typename EnumType>
524  static bool Parse(const ttv::json::Value& value, EnumType& output)
525  {
526  if (value.isNull() || !value.isString())
527  {
528  return false;
529  }
530  else
531  {
532  return FindEnumMatch(EnumDescription::EnumMap(), value, output);
533  }
534  }
535 
536  template <typename EnumType>
537  static bool Emit(EnumType input, ttv::json::Value& value)
538  {
539  return FindStringMatch(EnumDescription::EnumMap(), input, value);
540  }
541 
542 private:
543  template <typename MapTuple, typename EnumType>
544  static bool FindEnumMatch(const MapTuple& tuple, const ttv::json::Value& value, EnumType& output)
545  {
546  return FindEnumMatchFromIndex<0>(tuple, value, output);
547  }
548 
549 
550  template <int index, typename MapTuple, typename EnumType>
551  static std::enable_if_t<(index < std::tuple_size<MapTuple>::value), bool> FindEnumMatchFromIndex(const MapTuple& tuple, const ttv::json::Value& value, EnumType& output)
552  {
553  auto mapping = std::get<index>(tuple);
554  if (mapping.Match(value))
555  {
556  output = mapping.GetValue();
557  return true;
558  }
559  else
560  {
561  return FindEnumMatchFromIndex<index + 1>(tuple, value, output);
562  }
563  }
564 
565 
566  template <int index, typename MapTuple, typename EnumType>
567  static std::enable_if_t<(index >= std::tuple_size<MapTuple>::value), bool> FindEnumMatchFromIndex(const MapTuple& /*tuple*/, const ttv::json::Value& /*value*/, EnumType& output)
568  {
569  return ApplyDefault<EnumDescription>(output, 0);
570  }
571 
572 
573  template <typename Description, typename EnumType, typename = decltype(Description::GetFallbackValue())>
574  static bool ApplyDefault(EnumType& output, int /*n*/)
575  {
576  // This overload will be selected if the description has defined the GetFallbackValue() static method.
577  output = Description::GetFallbackValue();
578  return true;
579  }
580 
581 
582  template <typename Description, typename EnumType>
583  static bool ApplyDefault(EnumType& /*output*/, long /*n*/)
584  {
585  // This overload will be selected if the description has not defined the GetFallbackValue() static method.
586  // The second argument type is of type long, so that when a numeric literal is passed in, it will prefer
587  // to bind to the above method (with an int parameter), if it is available, instead of this one.
588  return false;
589  }
590 
591 
592  template <typename MapTuple, typename EnumType>
593  static bool FindStringMatch(const MapTuple& tuple, EnumType input, ttv::json::Value& value)
594  {
595  return FindStringMatchFromIndex<0>(tuple, input, value);
596  }
597 
598  template <int index, typename MapTuple, typename EnumType>
599  static std::enable_if_t<(index < std::tuple_size<MapTuple>::value), bool> FindStringMatchFromIndex(const MapTuple& tuple, EnumType input, ttv::json::Value& value)
600  {
601  auto mapping = std::get<index>(tuple);
602  if (mapping.GetValue() == input)
603  {
604  value = mapping.GetString();
605  return true;
606  }
607  else
608  {
609  return FindStringMatchFromIndex<index + 1>(tuple, input, value);
610  }
611  }
612 
613  template <int index, typename MapTuple, typename EnumType>
614  static std::enable_if_t<(index >= std::tuple_size<MapTuple>::value), bool> FindStringMatchFromIndex(const MapTuple& /*tuple*/, EnumType /*input*/, ttv::json::Value& /*value*/)
615  {
616  return false;
617  }
618 };
619 
620 
621 template <typename EnumType>
623 {
624 public:
625  constexpr EnumMapping(const char* string, EnumType value)
626  : mString(string)
627  , mValue(value)
628  {
629  }
630 
631 
632  template <typename InputType>
633  constexpr bool Match(const InputType& type) const
634  {
635  return type == mString;
636  }
637 
638 
639  constexpr EnumType GetValue() const
640  {
641  return mValue;
642  }
643 
644 
645  constexpr const char* GetString() const
646  {
647  return mString;
648  }
649 
650 private:
651  const char* mString;
652  EnumType mValue;
653 };
654 
655 
656 template <typename EnumType>
657 auto ttv::json::make_enum_mapping(const char* string, EnumType value)
658 {
659  return EnumMapping<EnumType>{string, value};
660 }
661 
662 
663 template <typename ObjectDescription>
665 {
666  template <typename OutputType>
667  static bool Parse(const ttv::json::Value& value, OutputType& output)
668  {
669  if (value.isNull() || !value.isObject())
670  {
671  return false;
672  }
673 
674  if (ParseValues(value, ObjectDescription::BindFields(output)))
675  {
676  return true;
677  }
678  else
679  {
680  output = {};
681  return false;
682  }
683  }
684 
685 
686  template <typename InputType>
687  static bool Emit(const InputType& input, ttv::json::Value& value)
688  {
689  if (EmitValues(value, ObjectDescription::BindFields(input)))
690  {
691  return true;
692  }
693  else
694  {
695  value = ttv::json::nullValue;
696  return false;
697  }
698  }
699 
700 
701 private:
702  template <typename FieldsTuple>
703  static bool ParseValues(const ttv::json::Value& value, FieldsTuple&& tuple)
704  {
705  return ParseValuesAtIndex<0>(value, std::forward<FieldsTuple>(tuple));
706  }
707 
708 
709  template <int index, typename FieldsTuple>
710  static std::enable_if_t<(index < std::tuple_size<FieldsTuple>::value), bool> ParseValuesAtIndex(const ttv::json::Value& value, FieldsTuple&& tuple)
711  {
712  auto field = std::get<index>(tuple);
713  if (!field.Parse(value) && decltype(field)::IsRequired)
714  {
715  return false;
716  }
717  else
718  {
719  return ParseValuesAtIndex<index + 1>(value, std::forward<FieldsTuple>(tuple));
720  }
721  }
722 
723 
724  template <int index, typename FieldsTuple>
725  static std::enable_if_t<(index >= std::tuple_size<FieldsTuple>::value), bool> ParseValuesAtIndex(const ttv::json::Value& /*value*/, FieldsTuple&& /*tuple*/)
726  {
727  return true;
728  }
729 
730 
731  template <typename FieldsTuple>
732  static bool EmitValues(ttv::json::Value& value, FieldsTuple&& tuple)
733  {
734  return EmitValuesAtIndex<0>(value, std::forward<FieldsTuple&&>(tuple));
735  }
736 
737 
738  template <int index, typename FieldsTuple>
739  static std::enable_if_t<(index < std::tuple_size<FieldsTuple>::value), bool> EmitValuesAtIndex(ttv::json::Value& value, FieldsTuple&& tuple)
740  {
741  auto field = std::get<index>(tuple);
742  if (!field.Emit(value) && decltype(field)::IsRequired)
743  {
744  return false;
745  }
746  else
747  {
748  return EmitValuesAtIndex<index + 1>(value, std::forward<FieldsTuple>(tuple));
749  }
750  }
751 
752 
753  template <int index, typename FieldsTuple>
754  static std::enable_if_t<(index >= std::tuple_size<FieldsTuple>::value), bool> EmitValuesAtIndex(ttv::json::Value& /*value*/, FieldsTuple&& /*tuple*/)
755  {
756  return true;
757  }
758 };
759 
760 
762 {
763  static constexpr bool IsRequired = true;
764 };
765 
767 {
768  static constexpr bool IsRequired = false;
769 };
770 
771 
772 template <typename ValueType, typename RequiredType, typename SchemaType>
773 class ttv::json::JsonField<ValueType, RequiredType, SchemaType, 1>
774 {
775 public:
776  static constexpr bool IsRequired = RequiredType::IsRequired;
777 
778  JsonField(const char* key, ValueType& object)
779  : mKey(key)
780  , mValue(object)
781  {
782  }
783 
784 
785  bool Parse(const ttv::json::Value& parent)
786  {
787  return SchemaType::Parse(parent[mKey], mValue);
788  }
789 
790 
791  bool Emit(ttv::json::Value& parent)
792  {
793  return SchemaType::Emit(mValue, parent[mKey]);
794  }
795 
796 
797 private:
798  const char* mKey;
800 };
801 
802 
803 template <typename ValueType, typename RequiredType, typename SchemaType, size_t ArraySize>
805 {
806  static_assert(ArraySize != 0, "Key path for JSON field must have at least one key.");
807 
808 public:
809  static constexpr bool IsRequired = RequiredType::IsRequired;
810 
811  JsonField(const std::array<const char*, ArraySize>& keyPath, ValueType& object)
812  : mKeyPath(keyPath)
813  , mValue(object)
814  {
815  }
816 
817 
818  bool Parse(const ttv::json::Value& parent)
819  {
820  return ParseHelper<0>(parent);
821  }
822 
823 
824  bool Emit(ttv::json::Value& parent)
825  {
826  return EmitHelper<0>(parent);
827  }
828 
829 
830 private:
831  template <int index>
832  std::enable_if_t<(index < ArraySize - 1), bool> ParseHelper(const ttv::json::Value& parent)
833  {
834  const auto& jIntermediate = parent[mKeyPath[index]];
835 
836  if(jIntermediate.isNull() || !jIntermediate.isObject())
837  {
838  return false;
839  }
840 
841  return ParseHelper<index + 1>(jIntermediate);
842  }
843 
844 
845  template <int index>
846  std::enable_if_t<(index == ArraySize - 1), bool> ParseHelper(const ttv::json::Value& parent)
847  {
848  return SchemaType::Parse(parent[mKeyPath[index]], mValue);
849  }
850 
851 
852  template <int index>
853  std::enable_if_t<(index < ArraySize - 1), bool> EmitHelper(ttv::json::Value& parent)
854  {
855  auto& jIntermediate = parent[mKeyPath[index]];
856 
857  return EmitHelper<index + 1>(jIntermediate);
858  }
859 
860 
861  template <int index>
862  std::enable_if_t<(index == ArraySize - 1), bool> EmitHelper(ttv::json::Value& parent)
863  {
864  return SchemaType::Emit(mValue, parent[mKeyPath[index]]);
865  }
866 
867 
868  std::array<const char *, ArraySize> mKeyPath;
870 };
871 
872 
873 template <typename SchemaType, typename RequiredType, typename ObjectType>
874 auto ttv::json::make_field(const char* key, ObjectType& field)
875 {
877 }
878 
879 
880 template <typename SchemaType, typename RequiredType, typename ObjectType, size_t ArraySize>
881 auto ttv::json::make_field(const std::array<const char*, ArraySize>& keyPath, ObjectType& field)
882 {
884 }
885 
886 
887 template <typename RequiredType, typename ObjectType>
888 auto ttv::json::make_field(const char* key, ObjectType& field)
889 {
890  return make_field<DefaultSchema<std::decay_t<ObjectType>>, RequiredType, ObjectType>(key, field);
891 }
892 
893 
894 template <typename RequiredType, typename ObjectType, size_t ArraySize>
895 auto ttv::json::make_field(const std::array<const char*, ArraySize>& keyPath, ObjectType& field)
896 {
897  return make_field<DefaultSchema<std::decay_t<ObjectType>>, RequiredType, ObjectType, ArraySize>(keyPath, field);
898 }
899 
900 
901 template <typename ObjectType>
902 auto ttv::json::make_field(const char* key, ObjectType& field)
903 {
904  return make_field<DefaultSchema<std::decay_t<ObjectType>>, OptionalField, ObjectType>(key, field);
905 }
906 
907 
908 template <typename ObjectType, size_t ArraySize>
909 auto ttv::json::make_field(const std::array<const char*, ArraySize>& keyPath, ObjectType& field)
910 {
911  return make_field<DefaultSchema<std::decay_t<ObjectType>>, OptionalField, ObjectType, ArraySize>(keyPath, field);
912 }
913 
914 
915 template <typename ObjectType, typename Enable>
917 {
918  static_assert(sizeof(ObjectType) < 0, "Default schema not found for object.");
919 };
920 
921 
922 template <typename IntegralType>
923 struct ttv::json::DefaultSchemaProvider<IntegralType, std::enable_if_t<std::is_integral<IntegralType>::value>>
924 {
926 };
927 
928 
929 template <typename FloatingPointType>
930 struct ttv::json::DefaultSchemaProvider<FloatingPointType, std::enable_if_t<std::is_floating_point<FloatingPointType>::value>>
931 {
933 };
934 
935 
936 template <>
938 {
940 };
941 
942 
943 template <>
945 {
947 };
948 
949 
950 template <typename ElementType>
951 struct ttv::json::DefaultSchemaProvider<std::vector<ElementType>>
952 {
954 };
955 
956 
957 template <typename ...Args>
958 std::array<const char*, sizeof...(Args)> ttv::json::MakeKeyPath(Args... args)
959 {
960  return std::array<const char*, sizeof...(Args)>{{args...}};
961 }
bool ParseNum(const std::string &str, int &out)
static bool Parse(const ttv::json::Value &value, bool &output)
Definition: jsonserialization.h:396
std::array< const char *, ArraySize > mKeyPath
Definition: jsonserialization.h:868
bool RFC3339TimeToUnixTimestamp(const std::string &str, Timestamp &result)
static bool Parse(const ttv::json::Value &value, ttv::Color &output)
Definition: jsonserialization.h:452
static bool Parse(const ttv::json::Value &value, ContainerType &output)
Definition: jsonserialization.h:478
bool asBool() const
Definition: jsonserialization.h:340
bool Parse(const ttv::json::Value &parent)
Definition: jsonserialization.h:785
static bool Emit(IntegralType input, ttv::json::Value &value)
Definition: jsonserialization.h:332
std::enable_if_t<(index< ArraySize - 1), bool > EmitHelper(ttv::json::Value &parent)
Definition: jsonserialization.h:853
Definition: jsonserialization.h:761
std::array< const char *, sizeof...(Args)> MakeKeyPath(Args... args)
Definition: jsonserialization.h:958
JsonField(const char *key, ValueType &object)
Definition: jsonserialization.h:778
static bool Emit(EnumType input, ttv::json::Value &value)
Definition: jsonserialization.h:537
static bool Parse(const ttv::json::Value &value, std::string &output)
Definition: jsonserialization.h:372
static std::enable_if_t<(index< std::tuple_size< MapTuple >::value), bool > FindStringMatchFromIndex(const MapTuple &tuple, EnumType input, ttv::json::Value &value)
Definition: jsonserialization.h:599
static bool Parse(const ttv::json::Value &value, IntegralType &output)
Definition: jsonserialization.h:309
Definition: jsonserialization.h:127
static bool EmitValues(ttv::json::Value &value, FieldsTuple &&tuple)
Definition: jsonserialization.h:732
Definition: jsonserialization.h:418
Definition: jsonserialization.h:135
auto make_enum_mapping(const char *string, EnumType value)
Definition: jsonserialization.h:657
static std::enable_if_t<(index >=std::tuple_size< FieldsTuple >::value), bool > EmitValuesAtIndex(ttv::json::Value &, FieldsTuple &&)
Definition: jsonserialization.h:754
EnumType mValue
Definition: jsonserialization.h:652
static bool ApplyDefault(EnumType &output, int)
Definition: jsonserialization.h:574
auto make_field(const char *key, ObjectType &field)
Definition: jsonserialization.h:874
std::string asString() const
static bool Emit(const bool &input, ttv::json::Value &value)
Definition: jsonserialization.h:410
std::enable_if_t<(index< ArraySize - 1), bool > ParseHelper(const ttv::json::Value &parent)
Definition: jsonserialization.h:832
ValueType & mValue
Definition: jsonserialization.h:799
Definition: cpp11transition.h:22
uint32_t Timestamp
Definition: coretypes.h:27
static bool FindEnumMatch(const MapTuple &tuple, const ttv::json::Value &value, EnumType &output)
Definition: jsonserialization.h:544
bool ToObject(const ttv::json::Value &value, ObjectType &object)
Definition: jsonserialization.h:277
bool isObject() const
bool Parse(const ttv::json::Value &parent)
Definition: jsonserialization.h:818
static bool Emit(const InputType &input, ttv::json::Value &value)
Definition: jsonserialization.h:687
bool parse(const std::string &document, Value &root, bool collectComments=true)
Read a Value from a JSON document.
static std::enable_if_t<(index >=std::tuple_size< FieldsTuple >::value), bool > ParseValuesAtIndex(const ttv::json::Value &, FieldsTuple &&)
Definition: jsonserialization.h:725
constexpr const char * GetString() const
Definition: jsonserialization.h:645
typename DefaultSchemaProvider< ObjectType >::Type DefaultSchema
Definition: jsonserialization.h:241
Definition: jsonserialization.h:235
Definition: jsonserialization.h:370
JSON (JavaScript Object Notation).
Definition: adsapi.h:16
Definition: jsonserialization.h:766
bool isString() const
static std::enable_if_t<(index< std::tuple_size< FieldsTuple >::value), bool > EmitValuesAtIndex(ttv::json::Value &value, FieldsTuple &&tuple)
Definition: jsonserialization.h:739
json::UInt64 UInt
Definition: value.h:125
static bool Parse(const ttv::json::Value &value, FloatingPointType &output)
Definition: jsonserialization.h:343
Definition: jsonserialization.h:165
bool Emit(ttv::json::Value &parent)
Definition: jsonserialization.h:824
Represents a JSON value.
Definition: value.h:114
Unserialize a JSON document into a Value.
Definition: reader.h:18
static bool Emit(const std::string &input, ttv::json::Value &value)
Definition: jsonserialization.h:386
constexpr EnumType GetValue() const
Definition: jsonserialization.h:639
ValueType & mValue
Definition: jsonserialization.h:869
static bool Parse(const ttv::json::Value &value, EnumType &output)
Definition: jsonserialization.h:524
bool ToJsonString(const ObjectType &object, std::string &jsonString)
Definition: jsonserialization.h:260
static bool ParseValues(const ttv::json::Value &value, FieldsTuple &&tuple)
Definition: jsonserialization.h:703
Definition: jsonserialization.h:306
static std::enable_if_t<(index< std::tuple_size< MapTuple >::value), bool > FindEnumMatchFromIndex(const MapTuple &tuple, const ttv::json::Value &value, EnumType &output)
Definition: jsonserialization.h:551
constexpr bool Match(const InputType &type) const
Definition: jsonserialization.h:633
static std::enable_if_t<(index >=std::tuple_size< MapTuple >::value), bool > FindStringMatchFromIndex(const MapTuple &, EnumType, ttv::json::Value &)
Definition: jsonserialization.h:614
std::enable_if_t<(index==ArraySize - 1), bool > EmitHelper(ttv::json::Value &parent)
Definition: jsonserialization.h:862
Value & append(const Value &value)
Append value to array at the end.
static std::enable_if_t<(index >=std::tuple_size< MapTuple >::value), bool > FindEnumMatchFromIndex(const MapTuple &, const ttv::json::Value &, EnumType &output)
Definition: jsonserialization.h:567
std::string UnixTimestampToRFC3339String(Timestamp timestamp)
bool isBool() const
&#39;null&#39; value
Definition: value.h:28
ValueType
Type of the value held by a Value object.
Definition: value.h:26
std::enable_if_t<(index==ArraySize - 1), bool > ParseHelper(const ttv::json::Value &parent)
Definition: jsonserialization.h:846
static bool Emit(ttv::Timestamp input, ttv::json::Value &value)
Definition: jsonserialization.h:442
static std::enable_if_t<(index< std::tuple_size< FieldsTuple >::value), bool > ParseValuesAtIndex(const ttv::json::Value &value, FieldsTuple &&tuple)
Definition: jsonserialization.h:710
const char * mKey
Definition: jsonserialization.h:798
bool isNull() const
Definition: jsonserialization.h:103
constexpr EnumMapping(const char *string, EnumType value)
Definition: jsonserialization.h:625
Definition: jsonserialization.h:179
bool ToJson(const ObjectType &object, ttv::json::Value &value)
Definition: jsonserialization.h:253
double asDouble() const
bool isArray() const
UInt asUInt() const
static bool ApplyDefault(EnumType &, long)
Definition: jsonserialization.h:583
bool ParseColor(const std::string &str, Color &result)
static bool FindStringMatch(const MapTuple &tuple, EnumType input, ttv::json::Value &value)
Definition: jsonserialization.h:593
uint32_t Color
Definition: coretypes.h:28
bool isNumeric() const
static bool Emit(FloatingPointType input, ttv::json::Value &value)
Definition: jsonserialization.h:362
virtual std::string write(const Value &root)
Definition: jsonserialization.h:450
bool Emit(ttv::json::Value &parent)
Definition: jsonserialization.h:791
static bool Emit(const ContainerType &input, ttv::json::Value &value)
Definition: jsonserialization.h:500
Outputs a Value in JSON format without formatting (not human friendly).
Definition: writer.h:31
Definition: jsonserialization.h:394
static bool Parse(const ttv::json::Value &value, OutputType &output)
Definition: jsonserialization.h:667
const char * mString
Definition: jsonserialization.h:651
static bool Parse(const ttv::json::Value &value, ttv::Timestamp &output)
Definition: jsonserialization.h:420
JsonField(const std::array< const char *, ArraySize > &keyPath, ValueType &object)
Definition: jsonserialization.h:811