40#pragma mark - Standard serializers
53 const char *s = value;
72 const char *
const *s = value;
239 for (
size_t i = 0; i <
array->capacity; i++) {
240 const ident instance = (uint8_t *) value + i *
array->properties->size;
249#pragma mark - Standard deserializers
261 const size_t size =
property->size;
263 if (!dest || !size) {
267 memset(dest, 0, size);
273 strncpy(dest,
cast(
String, value)->chars, size - 1);
274 dest[size - 1] =
'\0';
314 int32_t *dest = field;
339 uint32_t *dest = field;
350 *dest = (uint32_t)
cast(
Number, value)->value;
364 int64_t *dest = field;
389 uint64_t *dest = field;
400 *dest = (uint64_t)
cast(
Number, value)->value;
439 double *dest = field;
492 memset(field, 0, child->
size);
514 uint8_t *instance = (uint8_t *) field - property->
offset;
519 memset(field, 0,
array->properties->size *
array->capacity);
535#pragma mark - Object serializers / deserializers
549 return *s ?
retain(*s) : NULL;
586 return *url ?
retain((*url)->urlString) : NULL;
608 return *dest != NULL;
653 return *dest != NULL;
668 return *arr ?
retain(*arr) : NULL;
681 Array **dest = field;
750 return *dict ?
retain(*dict) : NULL;
static Array * initWithCapacity(Array *self, size_t capacity)
static void addObjectsFromArray(Array *self, const Array *array)
static void addObject(Array *self, const ident obj)
static Array * array(void)
static Array * init(Array *self)
static Boole * True(void)
static Boole * False(void)
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,...
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.
Microsecond-precision immutable dates.
Class * _Dictionary(void)
static Array * allObjects(const Dictionary *self)
static void addEntriesFromDictionary(Dictionary *self, const Dictionary *dictionary)
static Dictionary * dictionaryFromStruct(JSONContext *self, const JSONProperties *properties, const ident instance)
Serializes a C struct instance to a Dictionary.
static size_t structsFromArray(JSONContext *self, const JSONProperties *properties, const Array *array, ident instances, size_t count)
Deserializes a JSON Array into an array of C structs.
static bool structFromDictionary(JSONContext *self, const JSONProperties *properties, const Dictionary *dictionary, ident instance)
Deserializes a Dictionary into a C struct.
JSONContext class for JSON serialization and deserialization.
bool JSONDeserializeDouble(const JSONProperties *properties, const JSONProperty *property, const Object *value, ident field, JSONContext *context)
Deserializes a JSON number into a double field.
bool JSONDeserializeDate(const JSONProperties *properties, const JSONProperty *property, const Object *value, ident field, JSONContext *context)
Deserializes a JSON string into a Date * field (ISO 8601 by default).
bool JSONDeserializeCString(const JSONProperties *properties, const JSONProperty *property, const Object *value, ident field, JSONContext *context)
Deserializes a JSON string into a heap-allocated char * field.
bool JSONDeserializeInt32(const JSONProperties *properties, const JSONProperty *property, const Object *value, ident field, JSONContext *context)
Deserializes a JSON number into an int32_t field.
ident JSONSerializeUint32(const JSONProperties *properties, const JSONProperty *property, ident value, ident data, JSONContext *context)
Serializes a uint32_t field to a JSON number.
bool JSONDeserializeFloat(const JSONProperties *properties, const JSONProperty *property, const Object *value, ident field, JSONContext *context)
Deserializes a JSON number into a float field.
bool JSONDeserializeObjectArray(const JSONProperties *properties, const JSONProperty *property, const Object *value, ident field, JSONContext *context)
Deserializes a JSON array into an Array * field.
ident JSONSerializeStruct(const JSONProperties *properties, const JSONProperty *property, ident value, ident data, JSONContext *context)
Serializes a nested struct field to a JSON object.
ident JSONSerializeArray(const JSONProperties *properties, const JSONProperty *property, ident value, ident data, JSONContext *context)
Serializes an inline array field to a JSON array.
bool JSONDeserializeBoole(const JSONProperties *properties, const JSONProperty *property, const Object *value, ident field, JSONContext *context)
Deserializes a JSON boolean into a bool field.
bool JSONDeserializeCharacters(const JSONProperties *properties, const JSONProperty *property, const Object *value, ident field, JSONContext *context)
Deserializes a JSON string into a fixed-size char[] field.
bool JSONDeserializeArray(const JSONProperties *properties, const JSONProperty *property, const Object *value, ident field, JSONContext *context)
Deserializes a JSON array into an inline array field.
ident JSONSerializeInt64(const JSONProperties *properties, const JSONProperty *property, ident value, ident data, JSONContext *context)
Serializes an int64_t field to a JSON number.
ident JSONSerializeCString(const JSONProperties *properties, const JSONProperty *property, ident value, ident data, JSONContext *context)
Serializes a char * heap string field to a JSON string.
ident JSONSerializeURL(const JSONProperties *properties, const JSONProperty *property, ident value, ident data, JSONContext *context)
Serializes a URL * field to a JSON string (the URL's string form).
bool JSONDeserializeUint32(const JSONProperties *properties, const JSONProperty *property, const Object *value, ident field, JSONContext *context)
Deserializes a JSON number into a uint32_t field.
bool JSONDeserializeString(const JSONProperties *properties, const JSONProperty *property, const Object *value, ident field, JSONContext *context)
Deserializes a JSON string into a String * field.
ident JSONSerializeDictionary(const JSONProperties *properties, const JSONProperty *property, ident value, ident data, JSONContext *context)
Serializes a Dictionary * field to a JSON object.
ident JSONSerializeCharacters(const JSONProperties *properties, const JSONProperty *property, ident value, ident data, JSONContext *context)
Serializes a fixed-size char[] field to a JSON string.
ident JSONSerializeInt32(const JSONProperties *properties, const JSONProperty *property, ident value, ident data, JSONContext *context)
Serializes an int32_t field to a JSON number.
ident JSONSerializeObjectArray(const JSONProperties *properties, const JSONProperty *property, ident value, ident data, JSONContext *context)
Serializes an Array * field to a JSON array.
ident JSONSerializeSet(const JSONProperties *properties, const JSONProperty *property, ident value, ident data, JSONContext *context)
Serializes a Set * field to a JSON array.
bool JSONDeserializeDictionary(const JSONProperties *properties, const JSONProperty *property, const Object *value, ident field, JSONContext *context)
Deserializes a JSON object into a Dictionary * field.
bool JSONDeserializeStruct(const JSONProperties *properties, const JSONProperty *property, const Object *value, ident field, JSONContext *context)
Deserializes a JSON object into a nested struct field.
bool JSONDeserializeURL(const JSONProperties *properties, const JSONProperty *property, const Object *value, ident field, JSONContext *context)
Deserializes a JSON string into a URL * field via initWithString.
ident JSONSerializeBoole(const JSONProperties *properties, const JSONProperty *property, ident value, ident data, JSONContext *context)
Serializes a bool field to a JSON boolean.
bool JSONDeserializeInt64(const JSONProperties *properties, const JSONProperty *property, const Object *value, ident field, JSONContext *context)
Deserializes a JSON number into an int64_t field.
ident JSONSerializeUint64(const JSONProperties *properties, const JSONProperty *property, ident value, ident data, JSONContext *context)
Serializes a uint64_t field to a JSON number.
bool JSONDeserializeSet(const JSONProperties *properties, const JSONProperty *property, const Object *value, ident field, JSONContext *context)
Deserializes a JSON array into a Set * field.
ident JSONSerializeString(const JSONProperties *properties, const JSONProperty *property, ident value, ident data, JSONContext *context)
Serializes a String * field to a JSON string.
ident JSONSerializeFloat(const JSONProperties *properties, const JSONProperty *property, ident value, ident data, JSONContext *context)
Serializes a float field to a JSON number.
ident JSONSerializeDouble(const JSONProperties *properties, const JSONProperty *property, ident value, ident data, JSONContext *context)
Serializes a double field to a JSON number.
ident JSONSerializeDate(const JSONProperties *properties, const JSONProperty *property, ident value, ident data, JSONContext *context)
Serializes a Date * field to a JSON string (ISO 8601 by default).
bool JSONDeserializeUint64(const JSONProperties *properties, const JSONProperty *property, const Object *value, ident field, JSONContext *context)
Deserializes a JSON number into a uint64_t field.
#define JSONArrayProperties_NoCount
Sentinel for JSONArrayProperties::count indicating no sibling count field.
static Number * numberWithValue(double value)
A wrapper for placing numeric primitives into collections, etc.
static bool isKindOfClass(const Object *self, const Class *clazz)
static String * initWithString(String *self, const String *string)
static String * string(void)
static String * stringWithCharacters(const char *chars)
void * ident
The identity type, similar to Objective-C id.
Uniform Resource Locators (RFC 3986).
size_t count
The count of elements.
A wrapper for placing boolean primitives into collections, etc.
Microsecond-precision immutable dates.
Describes the JSON binding for an inline array field of a C struct.
A context for JSON serialization and deserialization.
Describes the JSON binding for all fields of a C struct.
const JSONProperty * properties
The NULL-terminated JSONProperty array.
size_t size
The struct size, i.e. sizeof(Struct).
Describes the JSON binding strategy for a single field of a C struct.
ptrdiff_t offset
The byte offset of the field within the struct.
ident data
Opaque user data passed to the serializer and deserializer.
A wrapper for placing numeric primitives into collections, etc.
Object is the root Class of The Objectively Class hierarchy.
Uniform Resource Locators (RFC 3986).