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

An optimized implementation of ISyncManager for writing JSON objects. SupportsReordering and SupportsDeduplication are both true. More...


Source file:
Inheritance diagram for SyncJson.Writer:

Remarks

An optimized implementation of ISyncManager for writing JSON objects. SupportsReordering and SupportsDeduplication are both true.

This is a struct rather than a class for performance reasons. Don't try to use a default(Writer); it'll throw NullReferenceException.

Public fields

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

Properties

object CurrentObject [set]
 

Public Member Functions

bool int object Object BeginSubObject (FieldId name, object?childKey, ObjectMode mode, int listLength=-1)
 
void EndSubObject ()
 
SyncType GetFieldType (FieldId name, SyncType expectedType=SyncType.Unknown)
 
string SyncTypeTag (string?tag)
 
bool Sync (FieldId name, bool 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)
 
IBufferWriter< byte > Flush ()
 Ensures that all written output has been registered with the IBufferWriter{byte} object with which this writer was initialized, and then returns it. If you called NewWriter without arguments, this function returns a ArrayBufferWriter{T} (see example below). More...
 
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)
 
bool BeginStringList (ref FieldId name, object?saving, ObjectMode mode)
 
void EndStringList (ObjectMode mode)
 

Member Function Documentation

IBufferWriter<byte> SyncJson.Writer.Flush ( )

Ensures that all written output has been registered with the IBufferWriter{byte} object with which this writer was initialized, and then returns it. If you called NewWriter without arguments, this function returns a ArrayBufferWriter{T} (see example below).

It is only necessary to call this method if the root value is a primitive (e.g. number or string), or if you want to see the output before the root object or list is finished, because flushing happens automatically when ISyncManager.EndSubObject finishes the root object or list.

Here's an example that uses this method to write a primitive:

<![CDATA[
    var writer = SyncJson.NewWriter();
    writer.Sync(null, 1234.5);
    var output = (ArrayBufferWriter<byte>) writer.Flush();
    // Output: 1234.5
    Console.WriteLine("Output: " + Encoding.UTF8.GetString(output.WrittenSpan));
]]>