Debian Codegraph @

testscript/plugin/protocol.go

raw symbols SCIP
1 package plugin
2
3 import "encoding/json"
4
5 // This file defines the JSON-RPC wire format used between [NewClient] and
6 // [NewServer]. These types are private implementation details of the plugin
7 // transport; the protocol can be documented separately if a non-Go plugin
8 // implementation is ever needed.
9 //
10 // A request is a JSON object {"id","method","params"}; a response is a JSON
11 // object {"id","result","error"}. Requests and responses are concatenated
12 // JSON values on the connection. Each request is answered by exactly one
13 // response with the same id; a non-empty error reports a failure of the
14 // invoked method.
15
16 const (
17 methodInfo = "Info"
18 methodNewInstance = "NewInstance"
19 methodRunCmd = "RunCmd"
20 methodCloseInstance = "CloseInstance"
21 )
22
23 // protocolVersion is the version of the wire protocol implemented by this
24 // package. The client sends the highest version it supports in the Info
25 // request; the server replies with the version it has selected, which is never
26 // greater than the version the client sent. Currently both are always 1, but
27 // the exchange lets future versions negotiate protocol changes. The version is
28 // an internal detail of the transport and is not exposed in the Go API.
29 const protocolVersion = 1
30
31 // infoArgs is the argument to the Info method.
32 type infoArgs struct {
33 // Version is the highest protocol version the client supports.
34 Version int
35 }
36
37 // infoResult is the result of the Info method.
38 type infoResult struct {
39 // Version is the protocol version the server has selected. It is never
40 // greater than the version the client sent in infoArgs.
41 Version int
42 Info PluginInfo
43 }
44
45 type rpcRequest struct {
46 ID uint64 `json:"id"`
47 Method string `json:"method"`
48 Params json.RawMessage `json:"params,omitempty"`
49 }
50
51 type rpcResponse struct {
52 ID uint64 `json:"id"`
53 Result json.RawMessage `json:"result,omitempty"`
54 Error string `json:"error,omitempty"`
55 }
56
57 // newInstanceResult is the result of the NewInstance method. Env holds the
58 // result of the new instance's Env method, folded into the creation reply to
59 // save a round trip.
60 type newInstanceResult struct {
61 InstID int
62 Env map[string]string
63 }
64
65 type runCmdArgs struct {
66 InstID int
67 Params CmdParams
68 }
69
70 type closeInstanceArgs struct {
71 InstID int
72 }