37#define _Class _JSONSerialization
39#pragma mark - JSONSerialization
121 for (
size_t i = 0; i < writer->
depth; i++) {
144 for (
size_t i = 0; i < keys->
count; i++) {
154 if (i < keys->count - 1) {
183 if (i < array->count - 1) {
258 return (
int) *(++(reader->
b));
262 return (
int) *(reader->
b = reader->
data->
bytes);
281 if (b == -1 || strchr(stop, b)) {
296 for (
size_t i = 1; i < strlen(bytes); i++) {
298 assert(b == bytes[i]);
309 uint8_t *bytes = reader->
b;
314 const size_t length = reader->
b - bytes - 1;
325 uint8_t *bytes = reader->
b;
328 double d = strtod((
char *) bytes, (
char **) &end);
343 Boole *
boolean = NULL;
345 switch (*reader->
b) {
458 const int b =
readByteUntil(reader,
"{[\"tfn0123456789.-]}");
461 }
else if (b ==
'[') {
463 }
else if (b ==
'\"') {
465 }
else if (b ==
't' || b ==
'f') {
467 }
else if (b ==
'n') {
469 }
else if (b ==
'.' || b ==
'-' || isdigit(b)) {
471 }
else if (b ==
']' || b ==
'}') {
496#pragma mark - Class lifecycle
517 .name =
"JSONSerialization",
521 .interfaceSize =
sizeof(JSONSerializationInterface),
A wrapper for placing boolean primitives into collections, etc.
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
Class * _initialize(const ClassDef *def)
Initializes the given Class.
ident retain(ident obj)
Atomically increment the given Object's reference count.
#define alloc(type)
Allocate and initialize and instance of type.
#define cast(type, obj)
Safely cast obj to type.
static ident readElement(JSONReader *reader)
Reads an element from reader. An element is any valid JSON type.
static void writeLabel(JSONWriter *writer, const String *label)
Writes the label (field name) label to writer.
static int readByte(JSONReader *reader)
static void writeNull(JSONWriter *writer, const Null *null)
Writes null to writer.
static _Bool * readBoole(JSONReader *reader)
Reads a Boole from reader.
static void writeString(JSONWriter *writer, const String *string)
Writes string to writer.
static void writePretty(JSONWriter *writer)
Writes pretty formatting, if applicable, to writer.
static void writeNumber(JSONWriter *writer, const Number *number)
Writes number to writer.
static void writeBoole(JSONWriter *writer, const Boole *boolean)
Writes boolean to writer.
static int readByteUntil(JSONReader *reader, const char *stop)
Consume bytes from reader until a byte from stop is found.
static void writeArray(JSONWriter *writer, const Array *array)
Writes array to writer.
static Dictionary * readObject(JSONReader *reader)
Reads an object from reader. An object is a valid JSON structure.
static void writeObject(JSONWriter *writer, const Dictionary *object)
Writes object to writer.
static String * readString(JSONReader *reader)
Reads a String from reader.
static Array * readArray(JSONReader *reader)
Reads an array from `reader.
static void consumeBytes(JSONReader *reader, const char *bytes)
Consumes and verifies bytes from `reader.
static void initialize(Class *clazz)
static String * readLabel(JSONReader *reader)
Reads a label from reader.
static Number * readNumber(JSONReader *reader)
Reads a Number from reader.
static Null * readNull(JSONReader *reader)
Reads Null from Reader.
static void writeElement(JSONWriter *writer, const ident obj)
Writes the specified JSON element to writer.
JSON serialization and introspection.
@ JSON_WRITE_PRETTY
Enables pretty (indented) formatting of JSON output.
@ JSON_WRITE_SORTED
Enables lexicographic sorting of JSON output.
Mutable key-value stores.
A wrapper for placing numeric primitives into collections, etc.
void * ident
The identity type, similar to Objective-C id.
#define do_once(once, block)
Executes the given block at most one time.
Class * _Array(void)
The Array archetype.
Array * sortedArray(const Array *self, Comparator comparator)
ident objectAtIndex(const Array *self, int index)
size_t count
The count of elements.
A wrapper for placing boolean primitives into collections, etc.
_Bool value
The backing _Bool.
Class * _Boole(void)
The Boole archetype.
ClassDefs are passed to _initialize via an archetype to initialize a Class.
The runtime representation of a Class.
ident interface
The interface of the Class.
Condition * init(Condition *self)
Initializes this Condition.
size_t length
The length of bytes.
uint8_t * bytes
The bytes.
Immutable key-value stores.
Class * _Dictionary(void)
The Dictionary archetype.
Array * allKeys(const Dictionary *self)
ident objectForKey(const Dictionary *self, const ident key)
A reader for parsing JSON Data.
JSON serialization and introspection.
Class * _JSONSerialization(void)
The JSONSerialization archetype.
Data * dataFromObject(const ident obj, int options)
Serializes the given Object to JSON Data.
ident objectFromData(const Data *data, int options)
Parses an Object from the specified Data.
A writer for generating JSON Data.
void addObject(MutableArray *self, const ident obj)
Adds the specified Object to this MutableArray.
MutableArray * array(void)
Returns a new MutableArray.
MutableData * data(void)
Returns a new MutableData.
void appendBytes(MutableData *self, const uint8_t *bytes, size_t length)
Appends the given bytes to this Data.
Mutable key-value stores.
void setObjectForKey(MutableDictionary *self, const ident obj, const ident key)
Sets a pair in this MutableDictionary.
MutableString * string(void)
Returns a new MutableString.
Class * _Null(void)
The Null archetype.
A wrapper for placing numeric primitives into collections, etc.
Number * numberWithValue(double value)
Returns a new Number with the given value.
double value
The backing value.
Class * _Number(void)
The Number archetype.
Object is the root Class of The Objectively Class hierarchy.
Class * _Object(void)
The Object archetype.
_Bool isKindOfClass(const Object *self, const Class *clazz)
Tests for Class hierarchy membership.
char * chars
The backing null-terminated UTF-8 encoded character array.
size_t length
The length of the String in bytes.
String * stringWithBytes(const uint8_t *bytes, size_t length, StringEncoding encoding)
Returns a new String by decoding length of bytes to UTF-8.
Class * _String(void)
The String archetype.
OBJECTIVELY_EXPORT Order StringCompare(const ident a, const ident b)
A Comparator for sorting Strings.