1///|
2/// Message covers all jsonrpc2 message types.
3/// They share no common functionality, but are a closed set of concrete types
4/// that are allowed to implement this interface. The message types are Request
5/// and Response.
6pub enum Message {
7 // Request is a jsonrpc2 request message.
8 (Request) -> Message
Request(struct Request {
id: ID?
method_: String
params: Json
}
A Request is a message sent to a peer to request behavior.
If it has an ID then it is a call and therefore requests a response,
otherwise it is a notification which receives no response.
Request)
9 // Response is a jsonrpc2 response message.
10 (Response) -> Message
Response(struct Response {
id: ID
result: Result[Json, WireError]
}
Response is a Message used as a reply to a call Request.
It will have the same ID as the call it is a response to.
Response)
11 // BatchRequest is an array of requests.
12 (Array[Request]) -> Message
BatchRequest(type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
Array[struct Request {
id: ID?
method_: String
params: Json
}
A Request is a message sent to a peer to request behavior.
If it has an ID then it is a call and therefore requests a response,
otherwise it is a notification which receives no response.
Request])
13 // BatchResponse is an array of responses.
14 (Array[Response]) -> Message
BatchResponse(type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
Array[struct Response {
id: ID
result: Result[Json, WireError]
}
Response is a Message used as a reply to a call Request.
It will have the same ID as the call it is a response to.
Response])
15} derive((Message, &Logger) -> Unit
Trait for types that can be converted to String
Show, (Message, Message) -> Bool
Trait for types whose elements can test for equality
Eq)
16
17///|
18pub impl trait ToJson {
to_json(Self) -> Json
}
Trait for types that can be converted to Json
ToJson for enum Message {
Request(Request)
Response(Response)
BatchRequest(Array[Request])
BatchResponse(Array[Response])
}
Message covers all jsonrpc2 message types.
They share no common functionality, but are a closed set of concrete types
that are allowed to implement this interface. The message types are Request
and Response.
Message with (self : Message) -> Json
to_json(Message
self) {
19 match Message
self {
20 (Request) -> Message
Request(Request
req) => Request
req.(self : Request) -> Json
to_json()
21 (Response) -> Message
Response(Response
res) => Response
res.(self : Response) -> Json
to_json()
22 (Array[Request]) -> Message
BatchRequest(Array[Request]
arr_req) => Array[Request]
arr_req.(self : Array[Request]) -> Json
to_json()
23 (Array[Response]) -> Message
BatchResponse(Array[Response]
arr_res) => Array[Response]
arr_res.(self : Array[Response]) -> Json
to_json()
24 }
25}
26
27///|
28pub impl trait @json.FromJson {
from_json(Json, @json.JsonPath) -> Self!@json.JsonDecodeError
}
Trait for types that can be converted from Json
@json.FromJson for enum Message {
Request(Request)
Response(Response)
BatchRequest(Array[Request])
BatchResponse(Array[Response])
}
Message covers all jsonrpc2 message types.
They share no common functionality, but are a closed set of concrete types
that are allowed to implement this interface. The message types are Request
and Response.
Message with (json : Json, path : @json.JsonPath) -> Message!@json.JsonDecodeError
from_json(Json
json, @json.JsonPath
path) {
29 let Result[Request, @json.JsonDecodeError]
req : enum Result[A, B] {
Err(B)
Ok(A)
}
Result[struct Request {
id: ID?
method_: String
params: Json
}
A Request is a message sent to a peer to request behavior.
If it has an ID then it is a call and therefore requests a response,
otherwise it is a notification which receives no response.
Request, type! @json.JsonDecodeError (@json.JsonPath, String)
@json.JsonDecodeError] = (json : Json, path~ : @json.JsonPath = ..) -> Request!@json.JsonDecodeError
@json.from_json?(Json
json)
30 if Result[Request, @json.JsonDecodeError]
req is (Request) -> Result[Request, @json.JsonDecodeError]
Ok(Request
req) {
31 return (Request) -> Message
Request(Request
req)
32 }
33 let Result[Response, @json.JsonDecodeError]
res : enum Result[A, B] {
Err(B)
Ok(A)
}
Result[struct Response {
id: ID
result: Result[Json, WireError]
}
Response is a Message used as a reply to a call Request.
It will have the same ID as the call it is a response to.
Response, type! @json.JsonDecodeError (@json.JsonPath, String)
@json.JsonDecodeError] = (json : Json, path~ : @json.JsonPath = ..) -> Response!@json.JsonDecodeError
@json.from_json?(Json
json)
34 if Result[Response, @json.JsonDecodeError]
res is (Response) -> Result[Response, @json.JsonDecodeError]
Ok(Response
res) {
35 return (Response) -> Message
Response(Response
res)
36 }
37 let Result[Array[Request], @json.JsonDecodeError]
arr_req : enum Result[A, B] {
Err(B)
Ok(A)
}
Result[type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
Array[struct Request {
id: ID?
method_: String
params: Json
}
A Request is a message sent to a peer to request behavior.
If it has an ID then it is a call and therefore requests a response,
otherwise it is a notification which receives no response.
Request], type! @json.JsonDecodeError (@json.JsonPath, String)
@json.JsonDecodeError] = (json : Json, path~ : @json.JsonPath = ..) -> Array[Request]!@json.JsonDecodeError
@json.from_json?(
38 Json
json,
39 )
40 if Result[Array[Request], @json.JsonDecodeError]
arr_req is (Array[Request]) -> Result[Array[Request], @json.JsonDecodeError]
Ok(Array[Request]
arr_req) {
41 return (Array[Request]) -> Message
BatchRequest(Array[Request]
arr_req)
42 }
43 let Result[Array[Response], @json.JsonDecodeError]
arr_res : enum Result[A, B] {
Err(B)
Ok(A)
}
Result[type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
Array[struct Response {
id: ID
result: Result[Json, WireError]
}
Response is a Message used as a reply to a call Request.
It will have the same ID as the call it is a response to.
Response], type! @json.JsonDecodeError (@json.JsonPath, String)
@json.JsonDecodeError] = (json : Json, path~ : @json.JsonPath = ..) -> Array[Response]!@json.JsonDecodeError
@json.from_json?(
44 Json
json,
45 )
46 if Result[Array[Response], @json.JsonDecodeError]
arr_res is (Array[Response]) -> Result[Array[Response], @json.JsonDecodeError]
Ok(Array[Response]
arr_res) {
47 return (Array[Response]) -> Message
BatchResponse(Array[Response]
arr_res)
48 }
49 raise @json.((@json.JsonPath, String)) -> @json.JsonDecodeError
JsonDecodeError((@json.JsonPath
path, "expected request(s) or response(s)"))
50}
51
52///|
53/// new_notification constructs a new notification message for the supplied
54/// method and parameters.
55pub fn (method_ : String, params : Json) -> Message
new_notification constructs a new notification message for the supplied
method and parameters.
new_notification(String
method_ : String
String, Json
params : enum Json {
Null
True
False
Number(Double)
String(String)
Array(Array[Json])
Object(Map[String, Json])
}
Json) -> enum Message {
Request(Request)
Response(Response)
BatchRequest(Array[Request])
BatchResponse(Array[Response])
}
Message covers all jsonrpc2 message types.
They share no common functionality, but are a closed set of concrete types
that are allowed to implement this interface. The message types are Request
and Response.
Message {
56 (Request) -> Message
Request({ ID?
id: ID?
None, String
method_, Json
params })
57}
58
59///|
60/// new_call constructs a new call message for the supplied ID, method and
61/// parameters.
62pub fn (id : ID, method_ : String, params : Json) -> Message
new_call constructs a new call message for the supplied ID, method and
parameters.
new_call(ID
id : enum ID {
Number(Int64)
String(String)
}
ID is used to identify the request and tie it to the response.
ID, String
method_ : String
String, Json
params : enum Json {
Null
True
False
Number(Double)
String(String)
Array(Array[Json])
Object(Map[String, Json])
}
Json) -> enum Message {
Request(Request)
Response(Response)
BatchRequest(Array[Request])
BatchResponse(Array[Response])
}
Message covers all jsonrpc2 message types.
They share no common functionality, but are a closed set of concrete types
that are allowed to implement this interface. The message types are Request
and Response.
Message {
63 (Request) -> Message
Request({ ID?
id: (ID) -> ID?
Some(ID
id), String
method_, Json
params })
64}
65
66///|
67/// new_response constructs a new Response message.
68pub fn (id : ID, result : Result[Json, WireError]) -> Message
new_response constructs a new Response message.
new_response(ID
id : enum ID {
Number(Int64)
String(String)
}
ID is used to identify the request and tie it to the response.
ID, Result[Json, WireError]
result : enum Result[A, B] {
Err(B)
Ok(A)
}
Result[enum Json {
Null
True
False
Number(Double)
String(String)
Array(Array[Json])
Object(Map[String, Json])
}
Json, struct WireError {
code: Int
message: String
data: Json?
}
WireError is a jsonrpc2 error message.
WireError]) -> enum Message {
Request(Request)
Response(Response)
BatchRequest(Array[Request])
BatchResponse(Array[Response])
}
Message covers all jsonrpc2 message types.
They share no common functionality, but are a closed set of concrete types
that are allowed to implement this interface. The message types are Request
and Response.
Message {
69 (Response) -> Message
Response({ ID
id, Result[Json, WireError]
result })
70}
71
72///|
73/// new_batch_request constructs a new batch request message for the supplied
74/// requests.
75pub fn (messages : Array[Message]) -> Message
new_batch_request constructs a new batch request message for the supplied
requests.
new_batch_request(Array[Message]
messages : type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
Array[enum Message {
Request(Request)
Response(Response)
BatchRequest(Array[Request])
BatchResponse(Array[Response])
}
Message covers all jsonrpc2 message types.
They share no common functionality, but are a closed set of concrete types
that are allowed to implement this interface. The message types are Request
and Response.
Message]) -> enum Message {
Request(Request)
Response(Response)
BatchRequest(Array[Request])
BatchResponse(Array[Response])
}
Message covers all jsonrpc2 message types.
They share no common functionality, but are a closed set of concrete types
that are allowed to implement this interface. The message types are Request
and Response.
Message {
76 let Array[Request]
requests = Array[Message]
messages.(self : Array[Message], f : (Message) -> Request?) -> Array[Request]
Returns a new array containing the elements of the original array that satisfy the given predicate.
Arguments
self - The array to filter.
f - The predicate function.
Returns
filter_map((self : Message) -> Request?
as_request)
77 (Array[Request]) -> Message
BatchRequest(Array[Request]
requests)
78}
79
80///|
81/// new_batch_response constructs a new batch response message for the supplied
82/// responses.
83pub fn (messages : Array[Message]) -> Message
new_batch_response constructs a new batch response message for the supplied
responses.
new_batch_response(Array[Message]
messages : type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
Array[enum Message {
Request(Request)
Response(Response)
BatchRequest(Array[Request])
BatchResponse(Array[Response])
}
Message covers all jsonrpc2 message types.
They share no common functionality, but are a closed set of concrete types
that are allowed to implement this interface. The message types are Request
and Response.
Message]) -> enum Message {
Request(Request)
Response(Response)
BatchRequest(Array[Request])
BatchResponse(Array[Response])
}
Message covers all jsonrpc2 message types.
They share no common functionality, but are a closed set of concrete types
that are allowed to implement this interface. The message types are Request
and Response.
Message {
84 let Array[Response]
responses = Array[Message]
messages.(self : Array[Message], f : (Message) -> Response?) -> Array[Response]
Returns a new array containing the elements of the original array that satisfy the given predicate.
Arguments
self - The array to filter.
f - The predicate function.
Returns
filter_map((self : Message) -> Response?
as_response)
85 (Array[Response]) -> Message
BatchResponse(Array[Response]
responses)
86}
87
88///|
89pub fn (self : Message) -> Request?
as_call(Message
self : enum Message {
Request(Request)
Response(Response)
BatchRequest(Array[Request])
BatchResponse(Array[Response])
}
Message covers all jsonrpc2 message types.
They share no common functionality, but are a closed set of concrete types
that are allowed to implement this interface. The message types are Request
and Response.
Message) -> struct Request {
id: ID?
method_: String
params: Json
}
A Request is a message sent to a peer to request behavior.
If it has an ID then it is a call and therefore requests a response,
otherwise it is a notification which receives no response.
Request? {
90 guard Message
self is (Request) -> Message
Request(Request
req) else { return Request?
None }
91 guard Request
req.ID?
id is ID?
Some(_) else { return Request?
None }
92 (Request) -> Request?
Some(Request
req)
93}
94
95///|
96pub fn (self : Message) -> Request?
as_notification(Message
self : enum Message {
Request(Request)
Response(Response)
BatchRequest(Array[Request])
BatchResponse(Array[Response])
}
Message covers all jsonrpc2 message types.
They share no common functionality, but are a closed set of concrete types
that are allowed to implement this interface. The message types are Request
and Response.
Message) -> struct Request {
id: ID?
method_: String
params: Json
}
A Request is a message sent to a peer to request behavior.
If it has an ID then it is a call and therefore requests a response,
otherwise it is a notification which receives no response.
Request? {
97 guard Message
self is (Request) -> Message
Request(Request
req) else { return Request?
None }
98 guard Request
req.ID?
id is ID?
None else { return Request?
None }
99 (Request) -> Request?
Some(Request
req)
100}
101
102///|
103pub fn (self : Message) -> Request?
as_request(Message
self : enum Message {
Request(Request)
Response(Response)
BatchRequest(Array[Request])
BatchResponse(Array[Response])
}
Message covers all jsonrpc2 message types.
They share no common functionality, but are a closed set of concrete types
that are allowed to implement this interface. The message types are Request
and Response.
Message) -> struct Request {
id: ID?
method_: String
params: Json
}
A Request is a message sent to a peer to request behavior.
If it has an ID then it is a call and therefore requests a response,
otherwise it is a notification which receives no response.
Request? {
104 if Message
self is (Request) -> Message
Request(Request
req) {
105 (Request) -> Request?
Some(Request
req)
106 } else {
107 Request?
None
108 }
109}
110
111///|
112pub fn (self : Message) -> Response?
as_response(Message
self : enum Message {
Request(Request)
Response(Response)
BatchRequest(Array[Request])
BatchResponse(Array[Response])
}
Message covers all jsonrpc2 message types.
They share no common functionality, but are a closed set of concrete types
that are allowed to implement this interface. The message types are Request
and Response.
Message) -> struct Response {
id: ID
result: Result[Json, WireError]
}
Response is a Message used as a reply to a call Request.
It will have the same ID as the call it is a response to.
Response? {
113 if Message
self is (Response) -> Message
Response(Response
res) {
114 (Response) -> Response?
Some(Response
res)
115 } else {
116 Response?
None
117 }
118}
119
120///|
121/// as_batch_request returns the message as a batch request if it is one.
122pub fn (self : Message) -> Array[Request]?
as_batch_request returns the message as a batch request if it is one.
as_batch_request(Message
self : enum Message {
Request(Request)
Response(Response)
BatchRequest(Array[Request])
BatchResponse(Array[Response])
}
Message covers all jsonrpc2 message types.
They share no common functionality, but are a closed set of concrete types
that are allowed to implement this interface. The message types are Request
and Response.
Message) -> type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
Array[struct Request {
id: ID?
method_: String
params: Json
}
A Request is a message sent to a peer to request behavior.
If it has an ID then it is a call and therefore requests a response,
otherwise it is a notification which receives no response.
Request]? {
123 if Message
self is (Array[Request]) -> Message
BatchRequest(Array[Request]
arr_req) {
124 (Array[Request]) -> Array[Request]?
Some(Array[Request]
arr_req)
125 } else {
126 Array[Request]?
None
127 }
128}
129
130///|
131/// as_batch_response returns the message as a batch response if it is one.
132pub fn (self : Message) -> Array[Response]?
as_batch_response returns the message as a batch response if it is one.
as_batch_response(Message
self : enum Message {
Request(Request)
Response(Response)
BatchRequest(Array[Request])
BatchResponse(Array[Response])
}
Message covers all jsonrpc2 message types.
They share no common functionality, but are a closed set of concrete types
that are allowed to implement this interface. The message types are Request
and Response.
Message) -> type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
Array[struct Response {
id: ID
result: Result[Json, WireError]
}
Response is a Message used as a reply to a call Request.
It will have the same ID as the call it is a response to.
Response]? {
133 if Message
self is (Array[Response]) -> Message
BatchResponse(Array[Response]
arr_res) {
134 (Array[Response]) -> Array[Response]?
Some(Array[Response]
arr_res)
135 } else {
136 Array[Response]?
None
137 }
138}
139