CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
sertype.h
Go to the documentation of this file.
1
6
7#pragma once
8
10#include <cx/string.h>
11#include <cx/struct/struct.h>
12#include <cx/stype/stype.h>
13
14CX_C_BEGIN
15
19
20typedef struct ObjClassInfo ObjClassInfo;
21
53
64
71typedef bool (*SerTypeResolver)(_Out_ SerResolved* out, _In_opt_ strref name,
72 _Inout_opt_ void* user);
73
74typedef struct SerResolverEnt {
76 void* user;
77} SerResolverEnt;
78saDeclare(SerResolverEnt);
79
80// The wire-name table for cx's own structural types, defined in sertype.c. It names types on
81// the way out and resolves them on the way back in, so the two directions cannot disagree.
82// Reached through serReaderResolve(), which consults it after the reader's own resolvers.
83_Ret_maybenull_ strref _serBuiltinName(uint32 stypeid);
84bool _serResolveBuiltin(_Out_ SerResolved* out, _In_opt_ strref name);
85
100bool serStructSetResolver(_Out_ SerResolved* out, _In_opt_ strref name, _Inout_opt_ void* user);
101
113bool serClassSetResolver(_Out_ SerResolved* out, _In_opt_ strref name, _Inout_opt_ void* user);
114
132bool serObjClassResolver(_Out_ SerResolved* out, _In_opt_ strref name, _Inout_opt_ void* user);
133
135
139
147 SER_Cap_Bytes = (1 << 1),
148 SER_Cap_TypeTags = (1 << 2),
149 SER_Cap_Refs = (1 << 3),
150 SER_Cap_ExactInt = (1 << 4),
151 SER_Cap_Skip = (1 << 5),
152 SER_Cap_Sizes = (1 << 6),
153};
154
157 // JSON
158 SER_JSON_Pretty = 0x00000001,
159 SER_JSON_Compact = 0x00000002,
160
161 // binary
162 SER_Bin_Compact = 0x00000100,
164
165 // general
166 SER_EmitDefaults = 0x01000000,
167 SER_Refs = 0x02000000,
168 SER_Strict = 0x10000000,
169
173 SER_Collect = 0x20000000,
174};
175
186
187typedef struct SerError {
188 int32 code;
189 string msg;
190 string path;
191} SerError;
192saDeclare(SerError);
193
194void serErrorDestroy(_Inout_ SerError* err);
195
201typedef struct SerPathFrame {
202 strref name;
203 int32 idx;
206
211typedef struct SerTraverseState {
212 sa_SerPathFrame path;
213 sa_SerError collected;
215
216void _serTraverseStateDestroy(_Inout_ SerTraverseState* ws);
217
222void serPathString(_Inout_ string* out, _In_ const SerTraverseState* ws);
223
225
226CX_C_END
#define saDeclare(name)
Definition sarray.h:93
SerErrorCodeEnum
Error codes reported through SerError::code.
Definition sertype.h:177
void serPathString(string *out, const SerTraverseState *ws)
SerCapabilitiesEnum
Definition sertype.h:145
SerFlagsEnum
Per-document options, passed to a backend's create function.
Definition sertype.h:156
@ SER_Err_Type
a type cannot be serialized, or is not what the schema said
Definition sertype.h:180
@ SER_Err_Backend
the backend refused or failed to emit/consume a node
Definition sertype.h:179
@ SER_Err_Unsupported
the backend lacks a capability this value needs
Definition sertype.h:183
@ SER_Err_Schema
the schema is missing or malformed where one is required
Definition sertype.h:181
@ SER_Err_Data
the data does not match what the schema expects
Definition sertype.h:182
@ SER_Err_Overflow
a value does not fit the slot it is being read into
Definition sertype.h:184
@ SER_Cap_Sizes
container counts are known before their contents
Definition sertype.h:152
@ SER_Cap_TypeTags
type annotations are preserved
Definition sertype.h:148
@ SER_Cap_ExactInt
the full int64/uint64 range round-trips exactly
Definition sertype.h:150
@ SER_Cap_Skip
the reader can skip over an unknown value
Definition sertype.h:151
@ SER_Cap_Bytes
native binary blob node
Definition sertype.h:147
@ SER_Cap_Refs
SER_RefDef / SER_RefUse are honored.
Definition sertype.h:149
@ SER_Cap_NonStringKeys
maps may be keyed by arbitrary values
Definition sertype.h:146
@ SER_JSON_Compact
single line
Definition sertype.h:159
@ SER_Bin_NoStringDedup
inline string values
Definition sertype.h:163
@ SER_EmitDefaults
write members equal to their default
Definition sertype.h:166
@ SER_Refs
enable reference dedup where supported
Definition sertype.h:167
@ SER_Strict
unknown fields and lossy cases are errors
Definition sertype.h:168
@ SER_JSON_Pretty
4-space indent
Definition sertype.h:158
@ SER_Bin_Compact
omit type tags
Definition sertype.h:162
@ SER_Collect
Definition sertype.h:173
bool(* SerTypeResolver)(SerResolved *out, strref name, void *user)
Definition sertype.h:71
enum SerNodeKindEnum SerNodeKind
bool serClassSetResolver(SerResolved *out, strref name, void *user)
bool serObjClassResolver(SerResolved *out, strref name, void *user)
bool serStructSetResolver(SerResolved *out, strref name, void *user)
SerNodeKindEnum
Definition sertype.h:31
@ SER_TypeTag
a type annotation preceding a value
Definition sertype.h:49
@ SER_EOF
reader is positioned past the end of the document
Definition sertype.h:33
@ SER_ArrayBegin
start of an ordered sequence
Definition sertype.h:43
@ SER_RefUse
stands in for a value already written under an id
Definition sertype.h:51
@ SER_Bytes
opaque byte run
Definition sertype.h:41
@ SER_Real
float64 plus the declared stype
Definition sertype.h:39
@ SER_MapKey
a key; a string, or a typed value where supported
Definition sertype.h:46
@ SER_Null
no value
Definition sertype.h:35
@ SER_Invalid
not a node; returned by peek when the reader is in an error state
Definition sertype.h:32
@ SER_Int
int64 plus the declared stype
Definition sertype.h:37
@ SER_Uint
uint64 plus the declared stype
Definition sertype.h:38
@ SER_Str
UTF-8 string.
Definition sertype.h:40
@ SER_MapBegin
start of a keyed collection
Definition sertype.h:45
@ SER_Bool
bool
Definition sertype.h:36
@ SER_RefDef
defines an id for the value that follows
Definition sertype.h:50
Dynamic arrays with type-safe generic programming.
Copy-on-write strings with automatic memory management and rope optimization.
strref name
member or map key; NULL for an array index frame
Definition sertype.h:202
int32 idx
array index, when name is NULL
Definition sertype.h:203
const StructInfo * structinfo
struct / structp, else NULL
Definition sertype.h:61
ObjClassInfo * clsinfo
object class, else NULL
Definition sertype.h:62
stype type
runtime descriptor
Definition sertype.h:60
sa_SerError collected
SER_Collect only.
Definition sertype.h:213
sa_SerPathFrame path
current location, innermost last
Definition sertype.h:212
Runtime type system and type descriptor infrastructure.