1///|
2/// This file is based on: https://cs.opensource.google/go/x/exp/+/master:jsonrpc2/frame.go;bpv=0
3/// which has copyright:
4/// Copyright 2018 The Go Authors. All rights reserved.
5/// Use of this source code is governed by a BSD-style
6/// license that can be found in the LICENSE file.
7
8///|
9/// Reader abstracts the transport mechanics from the JSON RPC protocol.
10/// A Conn reads messages from the reader it was provided on construction,
11/// and assumes that each call to Read fully transfers a single message,
12/// or returns an error.
13/// A reader is not safe for concurrent use, it is expected it will be used by
14/// a single Conn in a safe manner.
15pub trait trait Reader {
read(Self) -> (Message?, Int64, @io.IOError?)
}
Reader abstracts the transport mechanics from the JSON RPC protocol.
A Conn reads messages from the reader it was provided on construction,
and assumes that each call to Read fully transfers a single message,
or returns an error.
A reader is not safe for concurrent use, it is expected it will be used by
a single Conn in a safe manner.
Reader {
16 // Read gets the next message from the stream.
17 (Self) -> (Message?, Int64, @io.IOError?)
read(type parameter Self
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?, Int64
Int64, type! @io.IOError String
An IOError can be tested with equality checks.
@io.IOError?)
18}
19
20///|
21/// Writer abstracts the transport mechanics from the JSON RPC protocol.
22/// A Conn writes messages using the writer it was provided on construction,
23/// and assumes that each call to Write fully transfers a single message,
24/// or returns an error.
25/// A writer is not safe for concurrent use, it is expected it will be used by
26/// a single Conn in a safe manner.
27pub trait trait Writer {
write(Self, Message) -> (Int64, @io.IOError?)
}
Writer abstracts the transport mechanics from the JSON RPC protocol.
A Conn writes messages using the writer it was provided on construction,
and assumes that each call to Write fully transfers a single message,
or returns an error.
A writer is not safe for concurrent use, it is expected it will be used by
a single Conn in a safe manner.
Writer {
28 // Write sends a message to the stream.
29 (Self, Message) -> (Int64, @io.IOError?)
write(type parameter Self
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) -> (Int64
Int64, type! @io.IOError String
An IOError can be tested with equality checks.
@io.IOError?)
30}
31
32///|
33/// Framer wraps low level byte readers and writers into jsonrpc2 message
34/// readers and writers.
35/// It is responsible for the framing and encoding of messages into wire form.
36pub trait trait Framer {
reader(Self, &@io.ByteReader) -> &Reader
writer(Self, &@io.Writer) -> &Writer
}
Framer wraps low level byte readers and writers into jsonrpc2 message
readers and writers.
It is responsible for the framing and encoding of messages into wire form.
Framer {
37 // Reader wraps a byte reader into a message reader.
38 (Self, &@io.ByteReader) -> &Reader
reader(type parameter Self
Self, &trait @io.ByteReader {
read_byte(Self) -> (Byte, @io.IOError?)
}
ByteReader is the interface that wraps the read_byte method.
read_byte reads and returns the next byte from the input or
any error encountered. If read_byte returns an error, no input
byte was consumed, and the returned byte value is undefined.
read_byte provides an efficient interface for byte-at-time
processing. A [Reader] that does not implement ByteReader
can be wrapped using bufio.NewReader to add this method.
@io.ByteReader) -> &trait Reader {
read(Self) -> (Message?, Int64, @io.IOError?)
}
Reader abstracts the transport mechanics from the JSON RPC protocol.
A Conn reads messages from the reader it was provided on construction,
and assumes that each call to Read fully transfers a single message,
or returns an error.
A reader is not safe for concurrent use, it is expected it will be used by
a single Conn in a safe manner.
Reader
39 // Writer wraps a writer into a message writer.
40 (Self, &@io.Writer) -> &Writer
writer(type parameter Self
Self, &trait @io.Writer {
write(Self, @io.Slice[Byte]) -> (Int, @io.IOError?)
}
Writer is the interface that wraps the basic Write method.
Write writes len(p) bytes from p to the underlying data stream.
It returns the number of bytes written from p (0 <= n <= len(p))
and any error encountered that caused the write to stop early.
Write must return a non-None error if it returns n < len(p).
Write must not modify the slice data, even temporarily.
Implementations must not retain p.
@io.Writer) -> &trait Writer {
write(Self, Message) -> (Int64, @io.IOError?)
}
Writer abstracts the transport mechanics from the JSON RPC protocol.
A Conn writes messages using the writer it was provided on construction,
and assumes that each call to Write fully transfers a single message,
or returns an error.
A writer is not safe for concurrent use, it is expected it will be used by
a single Conn in a safe manner.
Writer
41}
42