Skip to content

Commit

Permalink
feat: Use new protocol examples and terminology in protocol overview
Browse files Browse the repository at this point in the history
  • Loading branch information
pojntfx committed Nov 8, 2023
1 parent f419f3f commit f6b3afc
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,23 +490,39 @@ To reproduce the tests, see the [benchmark source code](./cmd/) and the [visuali

### Protocol

The protocol used by dudirekta is simple and based on JSONL.
The protocol used by dudirekta is simple and independent of transport and serialization layer; in the following examples, we'll use JSON.

A function call to e.g. the `Println` function from above looks like this:

```json
[true, "1", "Println", ["Hello, world!"]]
{
"request": {
"call": "b3332cf0-4e50-4684-a909-05772e14595e",
"function": "Println",
"args": [
"Hello, world!"
]
},
"response": null
}
```

The first element specifies whether the message is a function call (`true`) or return (`false`). The second element is the ID of the function call, generated by the client; the third element is the function name and the last element is an array of the function's arguments serialized to JSON.
The request/response wrapper specifies whether the message is a function call (`request`) or return (`response`). `call` is the ID of the function call, as generated by the client; `function` is the function name and `args` is an array of the function's arguments.

A function return looks like this:

```json
[false, "1", "", ""]
{
"request": null,
"response": {
"call": "b3332cf0-4e50-4684-a909-05772e14595e",
"value": null,
"err": ""
}
}
```

Here, the first element specifies that the message is a function return (`false`). The second element is the ID of the function call from above, the third element is the function's return value serialized to JSON, and the last element is the error message; `nil` errors are represented by the empty string.
Here, `response` specifies that the message is a function return. `call` is the ID of the function call from above, `value` is the function's return value, and the last element is the error message; `nil` errors are represented by the empty string.

Keep in mind that dudirekta is bidirectional, meaning that both the client and server can send and receive both types of messages to each other.

Expand Down

0 comments on commit f6b3afc

Please sign in to comment.