Class JsonMessageBuilder
Builds a json representation of a message produced by a IMessageProducer
Implements
Inherited Members
Namespace: UnityEngine.Perception.GroundTruth.Consumers
Assembly: Unity.Perception.Runtime.dll
Syntax
public class JsonMessageBuilder : IMessageBuilder
Properties
currentJToken
JToken used to build json output
Declaration
protected JToken currentJToken { get; }
Property Value
Type | Description |
---|---|
JToken |
nestedArrays
Nested arrays for JSON output
Declaration
protected Dictionary<string, List<JsonMessageBuilder>> nestedArrays { get; }
Property Value
Type | Description |
---|---|
Dictionary<string, List<JsonMessageBuilder>> |
nestedValue
Nested builders for JSON output
Declaration
protected Dictionary<string, JsonMessageBuilder> nestedValue { get; }
Property Value
Type | Description |
---|---|
Dictionary<string, JsonMessageBuilder> |
Methods
AddBool(string, bool)
Adds a bool value to the json
Declaration
public virtual void AddBool(string key, bool value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
bool | value | The value to write out to json |
AddBoolArray(string, IEnumerable<bool>)
Adds a bool array to the json
Declaration
public virtual void AddBoolArray(string key, IEnumerable<bool> value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
IEnumerable<bool> | value | The value to write out to json |
AddByte(string, byte)
Adds a byte value to the json
Declaration
public virtual void AddByte(string key, byte value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
byte | value | The value to write out to json |
AddByteArray(string, IEnumerable<byte>)
Add a key/value array pair to the message.
Declaration
[Obsolete("AddByteArray has been deprecated, Use AddEncodedImage instead", true)]
public void AddByteArray(string key, IEnumerable<byte> value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key to add |
IEnumerable<byte> | value | The array of values to add |
Remarks
This method is obsolete, using AddEncodedImage(string, string, byte[]) instead
AddChar(string, char)
Adds a char value to the json
Declaration
public virtual void AddChar(string key, char value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
char | value | The value to write out to json |
AddDouble(string, double)
Adds a double value to the json
Declaration
public virtual void AddDouble(string key, double value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
double | value | The value to write out to json |
AddDoubleArray(string, IEnumerable<double>)
Adds a double array to the json
Declaration
public virtual void AddDoubleArray(string key, IEnumerable<double> value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
IEnumerable<double> | value | The value to write out to json |
AddEncodedImage(string, string, byte[])
Placeholder for support to write an encoded image to json. The default handler does not support this and throws a NotSupportedException.
Declaration
public virtual void AddEncodedImage(string key, string extension, byte[] value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
string | extension | Image extension for the image type, for example a PNG image would be "png" |
byte[] | value | The value to write out to json |
AddFloat(string, float)
Adds a float value to the json
Declaration
public virtual void AddFloat(string key, float value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
float | value | The value to write out to json |
AddFloatArray(string, IEnumerable<float>)
Adds a float array to the json
Declaration
public virtual void AddFloatArray(string key, IEnumerable<float> value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
IEnumerable<float> | value | The value to write out to json |
AddInt(string, int)
Adds an int value to the json
Declaration
public virtual void AddInt(string key, int value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
int | value | The value to write out to json |
AddIntArray(string, IEnumerable<int>)
Adds an int array to the json
Declaration
public virtual void AddIntArray(string key, IEnumerable<int> value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
IEnumerable<int> | value | The value to write out to json |
AddLong(string, long)
Adds a long int value to the json
Declaration
public virtual void AddLong(string key, long value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
long | value | The value to write out to json |
AddLongArray(string, IEnumerable<long>)
Adds a long int array to the json
Declaration
public virtual void AddLongArray(string key, IEnumerable<long> value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
IEnumerable<long> | value | The value to write out to json |
AddNestedMessage(string)
Adds a nested json element to the json object
Declaration
public virtual IMessageBuilder AddNestedMessage(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
Returns
Type | Description |
---|---|
IMessageBuilder | A handle to the nested json builder |
AddNestedMessageToVector(string)
Adds a nested json vector to the json object
Declaration
public virtual IMessageBuilder AddNestedMessageToVector(string arrayKey)
Parameters
Type | Name | Description |
---|---|---|
string | arrayKey | The key of the json object |
Returns
Type | Description |
---|---|
IMessageBuilder | A handle to the nested json builder |
AddString(string, string)
Adds a string value to the json
Declaration
public virtual void AddString(string key, string value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
string | value | The value to write out to json |
AddStringArray(string, IEnumerable<string>)
Adds an array of strings to the json
Declaration
public virtual void AddStringArray(string key, IEnumerable<string> value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
IEnumerable<string> | value | The value to write out to json |
AddTensor(string, Tensor)
Adds a tensor to the json. The default json handler does not support tensors and throws a NotSupportedException.
Declaration
public virtual void AddTensor(string key, Tensor tensor)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
Tensor | tensor | The value to write out to json |
AddUInt(string, uint)
Adds an unsigned int value to the json
Declaration
public virtual void AddUInt(string key, uint value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
uint | value | The value to write out to json |
AddUIntArray(string, IEnumerable<uint>)
Adds an unsigned int array to the json
Declaration
public virtual void AddUIntArray(string key, IEnumerable<uint> value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the json object |
IEnumerable<uint> | value | The value to write out to json |
ToJson()
Converts the message into a json Newtonsoft.Json.Linq.JToken
Declaration
public JToken ToJson()
Returns
Type | Description |
---|---|
JToken | JToken json representation of a message |