Newer
Older
This repo contains the implementation of the *RSVP (Request-and-Stream Variable Protocol)* for python.
The general protocol is described in more details [here][1].
## Dependencies
| | |
|-|-|
| Poetry | >= 1.2.0 |
Install python packages:
```bash
poetry install
```
## Quick start
### Server
Here is an example of how to create a RSVP server running on TCP. The basic idea is to create
an instance of the RsvpServer and add command callback functions that will be called when a specific
command is received.
#Define commands and their callbacks
# @RsvpServer.Command("EXCEPTION")
def handle_exception(ex : Exception) -> str:
error =f"{type(ex).__name__} {ex}"
try:
raise ex
except Exception as ex:
print(f"{type(ex).__name__}: {ex}")
return RsvpServer.reply(False, [RsvpString("ERROR", error)])
print(values)
return RsvpServer.reply(True, [RsvpInteger("CODE", 1)])
To add a command put decorator above your function. All the function will get a dict containing the
arguments sent by the client.
```py
@RsvpServer.Command(<COMMAND_NAME>)
Each callback must return a reply string using the following function
return RsvpServer.reply(ack : bool, args : list[RsvpBaseType])
There is only one callback predefined with and it's called *"EXCEPTION"* it called if an exception
is raised during the processing of the data. If this command is not defined the exception will be raises.
### Client
The client can be used to exchange data with the server.
```py
print(args)
if __name__ == "__main__":
client = RsvpClientTcp()
args = [
RsvpInteger("ARG1", 1),
RsvpDouble("ARG2", 2.0),
]
try:
print(client.send_command("START", args, callback=start_cb))
except Exception as ex:
print(f"[{type(ex).__name__}] Error: {ex}")
```
A method called send data is available to send data to the server:
```py
client.send_command(cmd_name: str, args: list[svpBaseType], function = None)
```
The function take the command name as a string, a list containing the arguments as RsvpBaseType and
an optional callback function that will be called when the server answer. If the callback is not defined the
### RsvpType classes
To mitigate errors we encourage the use of the special types for arguments. Available types are:
```py
RsvpInteger(name: str, value : int)
RsvpDouble(name: str, value : float)
RsvpBool(name: str value : bool)
RsvpString(name: str, value: str)
RsvpVectorDouble(name: str, value: dict[str, float])
RsvpVectorString(name: str, value: list[str])
```
All type are checked when creating a new object and it will raise an *RsvpWrongTypeException* exception the
*value* parameter is not of the correct type.
## Usage examples
In the *examples* folder you'll find some usage examples
## Run tests
```bash
poetry run pytest -v -s tests
```
## Add pyrsvp to your project
- [ ] Add CI/CD for tests and wheel generation
- [ ] Add serial support
[1]:https://labinfo.ing.he-arc.ch/gitlab/igib/documents-latex/rsvp-specs