Enhanced C#
Loyc library documentation
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Public fields | Properties | Public Member Functions | Static Public Member Functions | List of all members
SyncJson.SchemaWriter Struct Reference

An implementation of ISyncManager that produces a JSON Schema (draft 2020-12) describing the JSON that SyncJson.Writer would produce with the same synchronizer and Options — including the effects of options such as Options.NameConverter, Options.NewtonsoftCompatibility and Options.ByteArrayMode, and the "$id"/"$ref" markers used when ObjectMode.Deduplicate is used. More...


Source file:
Inheritance diagram for SyncJson.SchemaWriter:

Remarks

An implementation of ISyncManager that produces a JSON Schema (draft 2020-12) describing the JSON that SyncJson.Writer would produce with the same synchronizer and Options — including the effects of options such as Options.NameConverter, Options.NewtonsoftCompatibility and Options.ByteArrayMode, and the "$id"/"$ref" markers used when ObjectMode.Deduplicate is used.

Mode is SyncMode.Schema, so there is no actual data: your synchronizer function receives a default/null value and should call the same methods it would call when loading. Sync methods return default values, and each sub-object type is traversed only as often as needed to learn (and double-check) its schema.

The types of sub-objects are identified by the childKey passed to BeginSubObject, which is normally typeof(T) (helper methods such as SyncManagerExt.Sync{SM, T}(SM, FieldId, T, SyncObjectFunc{SM, T}, ObjectMode) arrange this automatically). Each type becomes a named definition in the "$defs" section of the schema, referenced via "$ref"; this is also what allows recursive (cyclic) types to be described. The definition's name is the .NET type name, unless the synchronizer calls SyncTypeTag, in which case the tag becomes the name. If the same type is synchronized in two conflicting ways, EndSubObject throws InvalidOperationException.

Since a schema saver has no data, it cannot see synchronizer behavior that depends on data, e.g. (1) fields that are synchronized conditionally are recorded only if the synchronizer's code path with default values reaches them, and (2) for polymorphic types, only the branch for the default type tag is recorded.

Public fields

SyncMode Mode => SyncMode.Schema
 
bool IsReading => true
 
bool IsWriting => false
 
bool SupportsReordering => true
 
bool SupportsDeduplication => true
 
bool NeedsIntegerIds => false
 
bool IsPlainText => true
 
ISyncOptions Options => _s._opt
 
bool IsInsideList => _s.IsInsideList
 
bool ReachedEndOfList => _s.ReachedEndOfList
 
int MinimumListLength => _s.MinimumListLength
 
int Depth => _s.Depth
 
bool SupportsNextField => false
 
FieldId NextField => FieldId.Missing
 
bool Begun
 
bool int Length
 

Properties

object CurrentObject [set]
 

Public Member Functions

SyncType GetFieldType (FieldId name, SyncType expectedType=SyncType.Unknown)
 
bool int object Object BeginSubObject (FieldId name, object?childKey, ObjectMode mode, int listLength=-1)
 
void EndSubObject ()
 
string SyncTypeTag (string?tag)
 
ReadOnlyMemory< byte > Finish ()
 Renders the recorded schema as a JSON Schema (draft 2020-12) document in UTF-8 format. More...
 
override string ToString ()
 Renders the recorded schema as a JSON Schema (draft 2020-12) string. More...
 
bool Sync (FieldId name, bool savable)
 
sbyte Sync (FieldId name, sbyte savable)
 
byte Sync (FieldId name, byte savable)
 
short Sync (FieldId name, short savable)
 
ushort Sync (FieldId name, ushort savable)
 
int Sync (FieldId name, int savable)
 
uint Sync (FieldId name, uint savable)
 
long Sync (FieldId name, long savable)
 
ulong Sync (FieldId name, ulong savable)
 
float Sync (FieldId name, float savable)
 
double Sync (FieldId name, double savable)
 
decimal Sync (FieldId name, decimal savable)
 
BigInteger Sync (FieldId name, BigInteger savable)
 
char Sync (FieldId name, char savable)
 
int Sync (FieldId name, int savable, int bits, bool signed=true)
 
long Sync (FieldId name, long savable, int bits, bool signed=true)
 
BigInteger Sync (FieldId name, BigInteger savable, int bits, bool signed=true)
 
string Sync (FieldId name, string?savable, ObjectMode mode=ObjectMode.Normal)
 
bool Sync (FieldId name, bool?savable)
 
sbyte Sync (FieldId name, sbyte?savable)
 
byte Sync (FieldId name, byte?savable)
 
short Sync (FieldId name, short?savable)
 
ushort Sync (FieldId name, ushort?savable)
 
int Sync (FieldId name, int?savable)
 
uint Sync (FieldId name, uint?savable)
 
long Sync (FieldId name, long?savable)
 
ulong Sync (FieldId name, ulong?savable)
 
float Sync (FieldId name, float?savable)
 
double Sync (FieldId name, double?savable)
 
decimal Sync (FieldId name, decimal?savable)
 
BigInteger Sync (FieldId name, BigInteger?savable)
 
char Sync (FieldId name, char?savable)
 
List SyncListBoolImpl< Scanner, List, ListBuilder > (FieldId name, Scanner scanner, List?saving, ListBuilder builder, ObjectMode mode, int tupleLength=-1)
 
List SyncListCharImpl< Scanner, List, ListBuilder > (FieldId name, Scanner scanner, List?saving, ListBuilder builder, ObjectMode mode, int tupleLength=-1)
 
List SyncListByteImpl< Scanner, List, ListBuilder > (FieldId name, Scanner scanner, List?saving, ListBuilder builder, ObjectMode mode, int tupleLength=-1)
 

Static Public Member Functions

static SchemaNode IntNode (BigInteger?min, BigInteger?max, bool nullable=false)
 
static SchemaNode Node (JsonSchemaType type, bool nullable=false)
 
static SchemaNode CharNode (bool nullable=false)
 
static SchemaNode BitfieldNode (int bits, bool signed)
 

Member Function Documentation

ReadOnlyMemory<byte> SyncJson.SchemaWriter.Finish ( )
inline

Renders the recorded schema as a JSON Schema (draft 2020-12) document in UTF-8 format.

override string SyncJson.SchemaWriter.ToString ( )

Renders the recorded schema as a JSON Schema (draft 2020-12) string.