Avro C#
Public Member Functions | Properties | List of all members
Avro.IO.JsonEncoder Class Reference

An Encoder for Avro's JSON data encoding. More...

Inheritance diagram for Avro.IO.JsonEncoder:
Avro.IO.ParsingEncoder Avro.IO.Parsing.Parser.IActionHandler Avro.IO.Encoder

Public Member Functions

 JsonEncoder (Schema sc, Stream stream)
 Initializes a new instance of the JsonEncoder class. More...
 
 JsonEncoder (Schema sc, Stream stream, bool pretty)
 Initializes a new instance of the JsonEncoder class. More...
 
 JsonEncoder (Schema sc, JsonWriter writer)
 Initializes a new instance of the JsonEncoder class. More...
 
override void Flush ()
 Flushes the encoder.
 
void Configure (Stream stream)
 Reconfigures this JsonEncoder to use the output stream provided. Otherwise, this JsonEncoder will flush its current output and then reconfigure its output to use a default UTF8 JsonWriter that writes to the provided Stream. More...
 
void Configure (JsonWriter jsonWriter)
 Reconfigures this JsonEncoder to output to the JsonWriter provided. Otherwise, this JsonEncoder will flush its current output and then reconfigure its output to use the provided JsonWriter. More...
 
override void WriteNull ()
 Writes a null value.
 
override void WriteBoolean (bool b)
 Writes a boolean value.
 
override void WriteInt (int n)
 Writes an int value.
 
override void WriteLong (long n)
 Writes a long value.
 
override void WriteFloat (float f)
 Writes a float value.
 
override void WriteDouble (double d)
 Writes a double value.
 
override void WriteString (string str)
 Writes an Unicode string.
 
override void WriteBytes (byte[] bytes)
 Writes a byte string.
 
override void WriteBytes (byte[] bytes, int start, int len)
 Writes a byte string.
 
override void WriteFixed (byte[] bytes)
 Writes a fixed value.
 
override void WriteFixed (byte[] bytes, int start, int len)
 Writes a fixed value.
 
override void WriteEnum (int e)
 Writes an enumeration.
 
override void WriteArrayStart ()
 Call this method to start writing an array. When starting to serialize an array, call WriteArrayStart. Then, before writing any data for any item call SetItemCount(long) followed by a sequence of StartItem and the item itself. The number of StartItem should match the number specified in SetItemCount(long). When actually writing the data of the item, you can call any Encoder method (e.g., WriteLong(long)). When all items of the array have been written, call WriteArrayEnd. As an example, let's say you want to write an array of records, the record consisting of an Long field and a Boolean field. Your code would look something like this:
out.WriteArrayStart();
out.SetItemCount(list.Count);
foreach (var r in list)
{
out.StartItem();
out.WriteLong(r.LongField);
out.WriteBoolean(r.BoolField);
}
out.WriteArrayEnd();

 
override void WriteArrayEnd ()
 Call this method to finish writing an array. See WriteArrayStart for usage information.
 
override void WriteMapStart ()
 Call this to start a new map. See WriteArrayStart for details on usage. As an example of usage, let's say you want to write a map of records, the record consisting of an Long field and a Boolean field. Your code would look something like this:
out.WriteMapStart();
out.SetItemCount(dictionary.Count);
foreach (var entry in dictionary)
{
out.StartItem();
out.WriteString(entry.Key);
out.writeLong(entry.Value.LongField);
out.writeBoolean(entry.Value.BoolField);
}
out.WriteMapEnd();

 
override void WriteMapEnd ()
 Call this method to terminate the inner-most, currently-opened map. See WriteArrayStart for more details.
 
override void StartItem ()
 Start a new item of an array or map. See WriteArrayStart for usage information.
 
override void WriteUnionIndex (int unionIndex)
 Call this method to write the tag of a union. As an example of usage, let's say you want to write a union, whose second branch is a record consisting of an Long field and a Boolean field. Your code would look something like this:
out.WriteIndex(1);
out.WriteLong(record.LongField);
out.WriteBoolean(record.BoolField);

 
virtual Symbol DoAction (Symbol input, Symbol top)
 Perform an action based on the given input. More...
 
- Public Member Functions inherited from Avro.IO.ParsingEncoder
virtual void SetItemCount (long value)
 Call this method before writing a batch of items in an array or a map.
 

Properties

virtual bool IncludeNamespace [get, set]
 Whether to include a union label when generating JSON. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Avro.IO.ParsingEncoder
void Push ()
 Push a new collection on to the stack. More...
 
void Pop ()
 Pop a new collection on to the stack. More...
 
int Depth ()
 Returns the position into the stack. More...
 
- Protected Attributes inherited from Avro.IO.ParsingEncoder
int Pos = -1
 Position into the counts stack. More...
 

Detailed Description

An Encoder for Avro's JSON data encoding.

JsonEncoder buffers output, and data may not appear on the output until Encoder.Flush() is called.

JsonEncoder is not thread-safe.

Constructor & Destructor Documentation

◆ JsonEncoder() [1/3]

Avro.IO.JsonEncoder.JsonEncoder ( Schema  sc,
Stream  stream 
)
inline

Initializes a new instance of the JsonEncoder class.

◆ JsonEncoder() [2/3]

Avro.IO.JsonEncoder.JsonEncoder ( Schema  sc,
Stream  stream,
bool  pretty 
)
inline

Initializes a new instance of the JsonEncoder class.

◆ JsonEncoder() [3/3]

Avro.IO.JsonEncoder.JsonEncoder ( Schema  sc,
JsonWriter  writer 
)
inline

Initializes a new instance of the JsonEncoder class.

Member Function Documentation

◆ Configure() [1/2]

void Avro.IO.JsonEncoder.Configure ( JsonWriter  jsonWriter)
inline

Reconfigures this JsonEncoder to output to the JsonWriter provided. Otherwise, this JsonEncoder will flush its current output and then reconfigure its output to use the provided JsonWriter.

Parameters
jsonWriterThe JsonWriter to direct output to. Cannot be null.

◆ Configure() [2/2]

void Avro.IO.JsonEncoder.Configure ( Stream  stream)
inline

Reconfigures this JsonEncoder to use the output stream provided. Otherwise, this JsonEncoder will flush its current output and then reconfigure its output to use a default UTF8 JsonWriter that writes to the provided Stream.

Parameters
streamThe Stream to direct output to. Cannot be null.

◆ DoAction()

virtual Symbol Avro.IO.JsonEncoder.DoAction ( Symbol  input,
Symbol  top 
)
inlinevirtual

Perform an action based on the given input.

Implements Avro.IO.Parsing.Parser.IActionHandler.

Property Documentation

◆ IncludeNamespace

virtual bool Avro.IO.JsonEncoder.IncludeNamespace
getset

Whether to include a union label when generating JSON.


The documentation for this class was generated from the following file: