45 lines
1.0 KiB
C#
45 lines
1.0 KiB
C#
|
|
#if TOOLS
|
||
|
|
|
||
|
|
namespace Rokojori.Tools
|
||
|
|
{
|
||
|
|
using Rokojori;
|
||
|
|
|
||
|
|
public static class JsonRpc
|
||
|
|
{
|
||
|
|
public static JSONObject BuildResult( JSONData id, JSONData result )
|
||
|
|
{
|
||
|
|
var obj = new JSONObject();
|
||
|
|
obj.Set( "jsonrpc", "2.0" );
|
||
|
|
obj.Set( "id", id ?? new JSONValue() );
|
||
|
|
obj.Set( "result", result );
|
||
|
|
return obj;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static JSONObject BuildError( JSONData id, int code, string message )
|
||
|
|
{
|
||
|
|
var error = new JSONObject();
|
||
|
|
error.Set( "code", (double) code );
|
||
|
|
error.Set( "message", message );
|
||
|
|
|
||
|
|
var obj = new JSONObject();
|
||
|
|
obj.Set( "jsonrpc", "2.0" );
|
||
|
|
obj.Set( "id", id ?? new JSONValue() );
|
||
|
|
obj.Set( "error", error );
|
||
|
|
return obj;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static string GetMethod( JSONObject envelope )
|
||
|
|
{
|
||
|
|
var data = envelope.Get( "method" );
|
||
|
|
return data != null && data.isString ? data.stringValue : null;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static bool IsNotification( JSONObject envelope )
|
||
|
|
{
|
||
|
|
return ! envelope.HasKey( "id" );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#endif
|