Avro C#
Loading...
Searching...
No Matches
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.
 
 JsonEncoder (Schema sc, Stream stream, bool pretty)
 Initializes a new instance of the JsonEncoder class.
 
 JsonEncoder (Schema sc, JsonWriter writer)
 Initializes a new instance of the JsonEncoder class.
 
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.
 
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.
 
override void WriteNull ()
 Writes a null value.
 
override void WriteBoolean (bool b)
 Writes a boolean value.
Parameters
valueValue to write.

 
override void WriteInt (int n)
 Writes an int value.
Parameters
valueValue to write.

 
override void WriteLong (long n)
 Writes a long value.
Parameters
valueValue to write.

 
override void WriteFloat (float f)
 Writes a float value.
Parameters
valueValue to write.

 
override void WriteDouble (double d)
 Writes a double value.
Parameters
valueValue to write.

 
override void WriteString (string str)
 Writes an Unicode string.
Parameters
valueValue to write.

 
override void WriteBytes (byte[] bytes)
 Writes a byte string.
Parameters
valueValue to write.

 
override void WriteBytes (byte[] bytes, int start, int len)
 Writes a byte string.
Parameters
valueThe byte[] to be read (fully or partially)
offsetThe offset from the beginning of the byte[] to start writing
lengthThe length of the data to be read from the byte[].

 
override void WriteFixed (byte[] bytes)
 Writes a fixed value.
Parameters
dataThe contents to write.

 
override void WriteFixed (byte[] bytes, int start, int len)
 Writes a fixed value.
Parameters
dataContents to write.
startPosition within data where the contents start.
lenNumber of bytes to write.

 
override void WriteEnum (int e)
 Writes an enumeration.
Parameters
valueValue to write.

 
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.
 
- Public Member Functions inherited from Avro.IO.ParsingEncoder
void WriteNull ()
 Writes a null value.
 
void WriteBoolean (bool value)
 Writes a boolean value.
Parameters
valueValue to write.

 
void WriteInt (int value)
 Writes an int value.
Parameters
valueValue to write.

 
void WriteLong (long value)
 Writes a long value.
Parameters
valueValue to write.

 
void WriteFloat (float value)
 Writes a float value.
Parameters
valueValue to write.

 
void WriteDouble (double value)
 Writes a double value.
Parameters
valueValue to write.

 
void WriteBytes (byte[] value)
 Writes a byte string.
Parameters
valueValue to write.

 
void WriteBytes (byte[] value, int offset, int length)
 Writes a byte string.
Parameters
valueThe byte[] to be read (fully or partially)
offsetThe offset from the beginning of the byte[] to start writing
lengthThe length of the data to be read from the byte[].

 
void WriteString (string value)
 Writes an Unicode string.
Parameters
valueValue to write.

 
void WriteEnum (int value)
 Writes an enumeration.
Parameters
valueValue to write.

 
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();

 
void WriteArrayEnd ()
 Call this method to finish writing an array. See WriteArrayStart for usage information.
 
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();

 
void WriteMapEnd ()
 Call this method to terminate the inner-most, currently-opened map. See WriteArrayStart for more details.
 
void WriteUnionIndex (int value)
 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);

 
void WriteFixed (byte[] data)
 Writes a fixed value.
Parameters
dataThe contents to write.

 
void WriteFixed (byte[] data, int start, int len)
 Writes a fixed value.
Parameters
dataContents to write.
startPosition within data where the contents start.
lenNumber of bytes to write.

 
void Flush ()
 Flushes the encoder.
 
virtual void SetItemCount (long value)
 Call this method before writing a batch of items in an array or a map.
Parameters
valueNumber of StartItem calls to follow.

 

Properties

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

Additional Inherited Members

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

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.

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.

◆ Flush()

override void Avro.IO.JsonEncoder.Flush ( )
inline

Flushes the encoder.

Implements Avro.IO.Encoder.

◆ StartItem()

override void Avro.IO.JsonEncoder.StartItem ( )
inlinevirtual

Start a new item of an array or map. See WriteArrayStart for usage information.

Reimplemented from Avro.IO.ParsingEncoder.

◆ WriteArrayEnd()

override void Avro.IO.JsonEncoder.WriteArrayEnd ( )
inline

Call this method to finish writing an array. See WriteArrayStart for usage information.

Implements Avro.IO.Encoder.

◆ WriteArrayStart()

override void Avro.IO.JsonEncoder.WriteArrayStart ( )
inline

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();

Implements Avro.IO.Encoder.

◆ WriteBoolean()

override void Avro.IO.JsonEncoder.WriteBoolean ( bool  b)
inline

Writes a boolean value.

Parameters
valueValue to write.

Implements Avro.IO.Encoder.

◆ WriteBytes() [1/2]

override void Avro.IO.JsonEncoder.WriteBytes ( byte[]  bytes)
inline

Writes a byte string.

Parameters
valueValue to write.

Implements Avro.IO.Encoder.

◆ WriteBytes() [2/2]

override void Avro.IO.JsonEncoder.WriteBytes ( byte[]  bytes,
int  start,
int  len 
)
inline

Writes a byte string.

Parameters
valueThe byte[] to be read (fully or partially)
offsetThe offset from the beginning of the byte[] to start writing
lengthThe length of the data to be read from the byte[].

Implements Avro.IO.Encoder.

◆ WriteDouble()

override void Avro.IO.JsonEncoder.WriteDouble ( double  d)
inline

Writes a double value.

Parameters
valueValue to write.

Implements Avro.IO.Encoder.

◆ WriteEnum()

override void Avro.IO.JsonEncoder.WriteEnum ( int  e)
inline

Writes an enumeration.

Parameters
valueValue to write.

Implements Avro.IO.Encoder.

◆ WriteFixed() [1/2]

override void Avro.IO.JsonEncoder.WriteFixed ( byte[]  bytes)
inline

Writes a fixed value.

Parameters
dataThe contents to write.

Implements Avro.IO.Encoder.

◆ WriteFixed() [2/2]

override void Avro.IO.JsonEncoder.WriteFixed ( byte[]  bytes,
int  start,
int  len 
)
inline

Writes a fixed value.

Parameters
dataContents to write.
startPosition within data where the contents start.
lenNumber of bytes to write.

Implements Avro.IO.Encoder.

◆ WriteFloat()

override void Avro.IO.JsonEncoder.WriteFloat ( float  f)
inline

Writes a float value.

Parameters
valueValue to write.

Implements Avro.IO.Encoder.

◆ WriteInt()

override void Avro.IO.JsonEncoder.WriteInt ( int  n)
inline

Writes an int value.

Parameters
valueValue to write.

Implements Avro.IO.Encoder.

◆ WriteLong()

override void Avro.IO.JsonEncoder.WriteLong ( long  n)
inline

Writes a long value.

Parameters
valueValue to write.

Implements Avro.IO.Encoder.

◆ WriteMapEnd()

override void Avro.IO.JsonEncoder.WriteMapEnd ( )
inline

Call this method to terminate the inner-most, currently-opened map. See WriteArrayStart for more details.

Implements Avro.IO.Encoder.

◆ WriteMapStart()

override void Avro.IO.JsonEncoder.WriteMapStart ( )
inline

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();

Implements Avro.IO.Encoder.

◆ WriteNull()

override void Avro.IO.JsonEncoder.WriteNull ( )
inline

Writes a null value.

Implements Avro.IO.Encoder.

◆ WriteString()

override void Avro.IO.JsonEncoder.WriteString ( string  str)
inline

Writes an Unicode string.

Parameters
valueValue to write.

Implements Avro.IO.Encoder.

◆ WriteUnionIndex()

override void Avro.IO.JsonEncoder.WriteUnionIndex ( int  unionIndex)
inline

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);

Implements Avro.IO.Encoder.


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