4#include "../Strings/SmallString.h"
5#include "../Strings/StringFormat.h"
6#include "Internal/SerializationTextReadVersioned.h"
7#include "Internal/SerializationTextReadWriteExact.h"
65 Writer stream(output, options);
66 if (not stream.onSerializationStart())
68 if (not Serialization::SerializationTextReadWriteExact<Writer, T>::serialize(0,
object, stream))
70 return stream.onSerializationEnd();
86 return Serialization::SerializationTextReadWriteExact<Reader, T>::serialize(0,
object, stream);
99 return Serialization::SerializationTextReadVersioned<Reader, T>::loadVersioned(0,
object, stream);
109 Writer(
StringFormatOutput& output, Options options) : output(output), options(options) {}
111 [[nodiscard]]
bool onSerializationStart();
112 [[nodiscard]]
bool onSerializationEnd();
114 [[nodiscard]]
bool setOptions(Options opt);
116 [[nodiscard]]
bool startObject(
uint32_t index);
117 [[nodiscard]]
bool endObject();
119 [[nodiscard]]
bool startArray(
uint32_t index);
120 [[nodiscard]]
bool endArray();
122 template <
typename Container>
123 [[nodiscard]]
bool startArray(
uint32_t index, Container& container,
uint32_t& size)
125 if (not eventuallyAddComma(index))
127 size =
static_cast<uint32_t>(container.size());
128 return output.append(
"["_a8);
131 template <
typename Container>
132 [[nodiscard]]
bool endArrayItem(Container&,
uint32_t&)
137 [[nodiscard]]
bool startObjectField(
uint32_t index, StringView text);
139 [[nodiscard]]
bool serialize(
uint32_t index,
const String& value);
140 [[nodiscard]]
bool serialize(
uint32_t index,
float value);
141 [[nodiscard]]
bool serialize(
uint32_t index,
double value);
143 template <
typename T>
144 [[nodiscard]]
bool serialize(
uint32_t index, T value)
146 if (not eventuallyAddComma(index))
148 return StringFormatterFor<T>::format(output, StringView(), value);
152 bool eventuallyAddComma(
uint32_t index);
154 SmallString<64> floatFormat;
162 Reader(StringView text) : iteratorText(text), iterator(text.getIterator<StringIteratorASCII>()) {}
164 [[nodiscard]]
bool onSerializationStart() {
return true; }
165 [[nodiscard]]
bool onSerializationEnd() {
return true; }
167 [[nodiscard]]
bool startObject(
uint32_t index);
168 [[nodiscard]]
bool endObject();
170 [[nodiscard]]
bool startArray(
uint32_t index);
171 [[nodiscard]]
bool endArray();
173 template <
typename Container>
174 [[nodiscard]]
bool startArray(
uint32_t index, Container& container,
uint32_t& size)
176 if (not tokenizeArrayStart(index))
178 return endArrayItem(container, size);
181 template <
typename Container>
182 [[nodiscard]]
bool endArrayItem(Container& container,
uint32_t& size)
185 if (not tokenizeArrayEnd(size))
188 return Reflection::ExtendedTypeInfo<Container>::resize(container, size);
192 [[nodiscard]]
bool startObjectField(
uint32_t index, StringView text);
193 [[nodiscard]]
bool getNextField(
uint32_t index, StringView& text,
bool& hasMore);
195 [[nodiscard]]
bool serialize(
uint32_t index,
bool& value);
196 [[nodiscard]]
bool serialize(
uint32_t index,
float& value);
198 [[nodiscard]]
bool serialize(
uint32_t index, String& text);
201 [[nodiscard]]
bool tokenizeArrayStart(
uint32_t index);
202 [[nodiscard]]
bool tokenizeArrayEnd(
uint32_t& size);
203 [[nodiscard]]
bool eventuallyExpectComma(
uint32_t index);
205 StringView iteratorText;
206 StringIteratorASCII iterator;
#define SC_COMPILER_EXPORT
Macro for symbol visibility in non-MSVC compilers.
Definition: Compiler.h:78
int int32_t
Platform independent (4) bytes signed int.
Definition: PrimitiveTypes.h:46
unsigned char uint8_t
Platform independent (1) byte unsigned int.
Definition: PrimitiveTypes.h:36
unsigned int uint32_t
Platform independent (4) bytes unsigned int.
Definition: PrimitiveTypes.h:38
Formatting options.
Definition: SerializationJson.h:48
uint8_t floatDigits
How many digits should be used when printing floating points.
Definition: SerializationJson.h:49
SC::SerializationJson reads or writes C++ structures to / from json using Reflection information.
Definition: SerializationJson.h:45
static bool loadVersioned(T &object, StringView text)
Parses a JSON buffer and writes C++ objects supporting reordered or missing fields.
Definition: SerializationJson.h:96
static bool write(T &object, StringFormatOutput &output, Options options=Options())
Writes a C++ object to JSON using Reflection.
Definition: SerializationJson.h:63
static bool loadExact(T &object, StringView text)
Parses a JSON produced by SerializationJson::write loading its values into a C++ object Read a JSON b...
Definition: SerializationJson.h:83
Non-owning view over a range of characters with UTF Encoding.
Definition: StringView.h:47