Objectively
Ultra-lightweight object oriented framework for GNU C.
Loading...
Searching...
No Matches
JSONContext.h
Go to the documentation of this file.
1/*
2 * Objectively: Ultra-lightweight object oriented framework for GNU C.
3 * Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#pragma once
25
26#include <Objectively/Data.h>
28#include <Objectively/Error.h>
30#include <Objectively/Array.h>
31#include <Objectively/Object.h>
32
38typedef struct JSONContextInterface JSONContextInterface;
39
40// ---------------------------------------------------------------------------
41// JSONWriteOptions
42// ---------------------------------------------------------------------------
43
47typedef enum {
48
53
58
60
61// ---------------------------------------------------------------------------
62// JSONContext
63// ---------------------------------------------------------------------------
64
73
78
83 JSONContextInterface *interface;
84
90};
91
95struct JSONContextInterface {
96
100 ObjectInterface objectInterface;
101
111 Data *(*dataFromObject)(JSONContext *self, const ident obj, int options);
112
122 Data *(*dataFromStruct)(JSONContext *self, const JSONProperties *properties, const ident instance);
123
134 Data *(*dataFromStructs)(JSONContext *self, const JSONProperties *properties, const ident instances, size_t count);
135
145 Dictionary *(*dictionaryFromStruct)(JSONContext *self, const JSONProperties *properties, const ident instance);
146
154 JSONContext *(*init)(JSONContext *self);
155
165 ident (*objectFromData)(JSONContext *self, const Data *data, int options);
166
177 bool (*structFromData)(JSONContext *self, const JSONProperties *properties, const Data *data, ident instance);
178
189 bool (*structFromDictionary)(JSONContext *self, const JSONProperties *properties, const Dictionary *dictionary, ident instance);
190
202 size_t (*structsFromArray)(JSONContext *self, const JSONProperties *properties, const Array *array, ident instances, size_t count);
203
215 size_t (*structsFromData)(JSONContext *self, const JSONProperties *properties, const Data *data, ident instances, size_t count);
216};
217
static Array * array(void)
Definition Array.c:234
Arrays.
#define obj
static Data * data(void)
Definition Data.c:286
Data buffers.
static Dictionary * dictionary(void)
Definition Dictionary.c:242
Key-value stores.
Encapsulation for error conditions.
OBJECTIVELY_EXPORT Class * _JSONContext(void)
JSONWriteOptions
Options for JSON serialization.
Definition JSONContext.h:47
@ JSON_WRITE_PRETTY
Enables pretty (indented) formatting of JSON output.
Definition JSONContext.h:52
@ JSON_WRITE_SORTED
Enables lexicographic sorting of JSON object keys.
Definition JSONContext.h:57
Standard JSONSerializer and JSONDeserializer functions for C struct fields.
Object is the root Class of The Objectively Class hierarchy.
static int options(RESTClient *self, const char *url, Data **data)
Definition RESTClient.c:217
void * ident
The identity type, similar to Objective-C id.
Definition Types.h:49
#define OBJECTIVELY_EXPORT
Definition Types.h:36
Arrays.
Definition Array.h:56
The runtime representation of a Class.
Definition Class.h:95
Data buffers.
Definition Data.h:50
Key-value stores.
Definition Dictionary.h:60
A context for JSON serialization and deserialization.
Definition JSONContext.h:72
Object object
The superclass.
Definition JSONContext.h:77
Array * errors
Errors accumulated during the operation.
Definition JSONContext.h:89
JSONContextInterface * interface
The interface.
Definition JSONContext.h:83
Describes the JSON binding for all fields of a C struct.
Object is the root Class of The Objectively Class hierarchy.
Definition Object.h:46