Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
JSONRPC.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Framework_WebService_JSONRPC_h_
5#define _Stroika_Framework_WebService_JSONRPC_h_ 1
6
7#include "Stroika/Frameworks/StroikaPreComp.h"
8
10#include "Stroika/Foundation/Containers/Mapping.h"
11#include "Stroika/Foundation/Containers/Sequence.h"
12#include "Stroika/Foundation/DataExchange/ObjectVariantMapper.h"
14
15/*
16 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
17 */
18
19namespace Stroika::Frameworks::WebService::JSONRPC {
20
21 using namespace Stroika::Foundation;
22
27
28 /**
29 * See https://www.jsonrpc.org/specification
30 */
31
32 /**
33 */
34 struct Request {
35 /**
36 */
37 String jsonrpc{"2.0"sv};
38
39 /**
40 */
41 String method;
42
43 /**
44 * This can be missing, or a Mapping (named params) or an array of params (Sequence)
45 */
46 optional<variant<Mapping<String, VariantValue>, Sequence<VariantValue>>> params;
47
48 /**
49 // Note if provided, this must be an integer, or string (can be float but discouraged)
50 */
51 optional<VariantValue> id;
52
53 /**
54 */
56 };
57
58 namespace ErrorCodes {
59 constexpr int kParseError = -32700;
60 constexpr int kInvalidRequest = -32600;
61 constexpr int kMethodNotFound = -32601;
62 constexpr int kInvalidParameters = -32602;
63 constexpr int kInternalJSONRPCError = -32603;
64 }
65
66 /**
67 */
68 struct Error {
69 /**
70 * can be ErrorCodes, or other
71 */
72 int code{};
73
74 /**
75 */
76 String message;
77
78 /**
79 */
80 optional<VariantValue> data;
81
82 /**
83 */
84 nonvirtual String ToString () const;
85
86 /**
87 */
89 };
90
91 /**
92 * MAYBE redo result/error so variant object so can be one thing or other?
93 */
94 struct Response {
95 String jsonrpc{"2.0"sv};
96
97 /**
98 * If provided, can be any json value. result or error required, but not both
99 */
100 optional<VariantValue> result;
101
102 /**
103 * If provided, can be any json value. result or error required, but not both
104 */
105 optional<Error> error;
106
107 /*
108 * Must be same as value from request
109 */
110 VariantValue id;
111
112 /**
113 */
115 };
116
117}
118
119/*
120 ********************************************************************************
121 ***************************** Implementation Details ***************************
122 ********************************************************************************
123 */
124#include "JSONRPC.inl"
125
126#endif /*_Stroika_Framework_WebService_JSONRPC_h_*/
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
A generalization of a vector: a container whose elements are keyed by the natural numbers.
Definition Sequence.h:187
ObjectVariantMapper can be used to map C++ types to and from variant-union types, which can be transp...
Simple variant-value (case variant union) object, with (variant) basic types analogous to a value in ...
optional< variant< Mapping< String, VariantValue >, Sequence< VariantValue > > > params
Definition JSONRPC.h:46