CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
Data Model and Schema

Data Structures

struct  SerResolved
 

Typedefs

typedef enum SerNodeKindEnum SerNodeKind
 
typedef struct SerResolved SerResolved
 
typedef bool(* SerTypeResolver) (SerResolved *out, strref name, void *user)
 

Enumerations

enum  SerNodeKindEnum {
  SER_Invalid = 0 , SER_EOF , SER_Null , SER_Bool ,
  SER_Int , SER_Uint , SER_Real , SER_Str ,
  SER_Bytes , SER_ArrayBegin , SER_ArrayEnd , SER_MapBegin ,
  SER_MapKey , SER_MapEnd , SER_TypeTag , SER_RefDef ,
  SER_RefUse
}
 

Functions

bool serStructSetResolver (SerResolved *out, strref name, void *user)
 
bool serClassSetResolver (SerResolved *out, strref name, void *user)
 
bool serObjClassResolver (SerResolved *out, strref name, void *user)
 

Detailed Description

Typedef Documentation

◆ SerNodeKind

A node in the abstract data model.

Every cx value decomposes into a sequence of these, and is reassembled from the same sequence. The vocabulary is deliberately close to CBOR's: rich enough to be lossless in a binary format, small enough that the JSON projection is a short table.

A backend is free to ignore nodes it has no use for – a schema-locked binary stream ignores SER_TypeTag – and to reject ones it cannot represent, which it declares by not advertising the matching capability.

◆ SerResolved

typedef struct SerResolved SerResolved

The result of resolving a wire type name.

A resolver returns more than an stype because for a nominal type the stype alone is useless for constructing an instance – every class resolves to _sti_object – so the reader also needs the StructInfo or ObjClassInfo that describes how to allocate one.

◆ SerTypeResolver

typedef bool(* SerTypeResolver) (SerResolved *out, strref name, void *user)

Resolves a wire type name to something the reader can construct.

Parameters
outReceives the resolved type on success
nameWire type name, as it appeared in a type tag
userOpaque value supplied when the resolver was registered
Returns
true if this resolver recognized the name

Definition at line 71 of file sertype.h.

Enumeration Type Documentation

◆ SerNodeKindEnum

A node in the abstract data model.

Every cx value decomposes into a sequence of these, and is reassembled from the same sequence. The vocabulary is deliberately close to CBOR's: rich enough to be lossless in a binary format, small enough that the JSON projection is a short table.

A backend is free to ignore nodes it has no use for – a schema-locked binary stream ignores SER_TypeTag – and to reject ones it cannot represent, which it declares by not advertising the matching capability.

Enumerator
SER_Invalid 

not a node; returned by peek when the reader is in an error state

SER_EOF 

reader is positioned past the end of the document

SER_Null 

no value

SER_Bool 

bool

SER_Int 

int64 plus the declared stype

SER_Uint 

uint64 plus the declared stype

SER_Real 

float64 plus the declared stype

SER_Str 

UTF-8 string.

SER_Bytes 

opaque byte run

SER_ArrayBegin 

start of an ordered sequence

SER_MapBegin 

start of a keyed collection

SER_MapKey 

a key; a string, or a typed value where supported

SER_TypeTag 

a type annotation preceding a value

SER_RefDef 

defines an id for the value that follows

SER_RefUse 

stands in for a value already written under an id

Definition at line 31 of file sertype.h.

Function Documentation

◆ serClassSetResolver()

bool serClassSetResolver ( SerResolved out,
strref  name,
void *  user 
)

Resolves a class name through a ClassSet.

The class counterpart of serStructSetResolver, over the set cxautogen emits for a classset declaration. A slot declared object[SomeSet] consults its own set without any registration; this is for the other case, where a document's top-level value, or a slot declared as bare object, has to resolve against the same vocabulary.

Parameters
outReceives the resolved class
nameWire type name
userThe ClassSet to search
Returns
true if the set contains a class with that wire name

◆ serObjClassResolver()

bool serObjClassResolver ( SerResolved out,
strref  name,
void *  user 
)

Resolves a class name through a NULL-terminated array of ObjClassInfo*.

The same thing as serClassSetResolver for a list a consumer assembles itself rather than declaring in a .cxh: a class list is a handful of &X_clsinfo it already has the symbols for. Classes without a wire name never match: not having one is exactly what "this class does not serialize" means.

Parameters
outReceives the resolved class
nameWire type name
userNULL-terminated array of ObjClassInfo pointers to search
Returns
true if one of the classes carries that wire name

Example:

static ObjClassInfo* myclasses[] = { &Document_clsinfo, &Folder_clsinfo, NULL };
bool serObjClassResolver(SerResolved *out, strref name, void *user)
void serReaderAddResolver(SerReader *r, SerTypeResolver fn, void *user)

◆ serStructSetResolver()

bool serStructSetResolver ( SerResolved out,
strref  name,
void *  user 
)

Resolves a struct name through a StructSet.

Register with serReaderAddResolver(r, serStructSetResolver, &MySet_structset) to let a reader construct any struct in the set from its wire name. cxautogen emits one StructSet per structset declaration, sorted for binary search.

A member declared structp[MySet] does not need this: the set travels with the slot, and the traverser resolves through it directly. Register it for the cases a declaration cannot cover – a dynamic value at the top level of a document, or a bare structp slot.

Parameters
outReceives the resolved struct type
nameWire type name
userThe StructSet to search
Returns
true if the set contains a struct with that name