webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
Classes | Public Member Functions | Static Public Member Functions | Properties | List of all members
Google.Protobuf.JsonFormatter Class Reference

Reflection-based converter from messages to JSON. More...

Classes

class  Settings
 Settings controlling JSON formatting. More...
 

Public Member Functions

 JsonFormatter (Settings settings)
 Creates a new formatted with the given settings. More...
 
string Format (IMessage message)
 Formats the specified message as JSON. More...
 
void Format (IMessage message, TextWriter writer)
 Formats the specified message as JSON. More...
 

Static Public Member Functions

static string ToDiagnosticString (IMessage message)
 Converts a message to JSON for diagnostic purposes with no extra context. More...
 

Properties

static JsonFormatter Default [get]
 Returns a formatter using the default settings. More...
 

Detailed Description

Reflection-based converter from messages to JSON.

Instances of this class are thread-safe, with no mutable state.

This is a simple start to get JSON formatting working. As it's reflection-based, it's not as quick as baking calls into generated messages - but is a simpler implementation. (This code is generally not heavily optimized.)

Constructor & Destructor Documentation

◆ JsonFormatter()

Google.Protobuf.JsonFormatter.JsonFormatter ( Settings  settings)
inline

Creates a new formatted with the given settings.

Parameters
settingsThe settings.

Member Function Documentation

◆ Format() [1/2]

string Google.Protobuf.JsonFormatter.Format ( IMessage  message)
inline

Formats the specified message as JSON.

Parameters
messageThe message to format.
Returns
The formatted message.

◆ Format() [2/2]

void Google.Protobuf.JsonFormatter.Format ( IMessage  message,
TextWriter  writer 
)
inline

Formats the specified message as JSON.

Parameters
messageThe message to format.
writerThe TextWriter to write the formatted message to.
Returns
The formatted message.

◆ ToDiagnosticString()

static string Google.Protobuf.JsonFormatter.ToDiagnosticString ( IMessage  message)
inlinestatic

Converts a message to JSON for diagnostic purposes with no extra context.

This differs from calling Format(IMessage) on the default JSON formatter in its handling of Any. As no type registry is available in object.ToString calls, the normal way of resolving the type of an Any message cannot be applied. Instead, a JSON property named is included with the base64 data from the Any.Value property of the message.

The value returned by this method is only designed to be used for diagnostic purposes. It may not be parsable by JsonParser, and may not be parsable by other Protocol Buffer implementations.

Parameters
messageThe message to format for diagnostic purposes.
Returns
The diagnostic-only JSON representation of the message

Property Documentation

◆ Default

JsonFormatter Google.Protobuf.JsonFormatter.Default
staticget

Returns a formatter using the default settings.


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