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].
The CI publishes a *pypy* package on gitlab. This package can be used in other projects.
### Add pyrsvp to Poetry project
Add a secondary source to your poetry project
poetry source add -s igib https://labinfo.ing.he-arc.ch/gitlab/api/v4/projects/2369/packages/pypi/simple
```
Add *pyrsvp* package
```bash
poetry add pyrsvp --source igib
```
### Add using PIP
```bash
pip install pyrsvp --index-url https://labinfo.ing.he-arc.ch/gitlab/api/v4/projects/2369/packages/pypi/simple/
### 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
## Developers
### Dependencies
| | |
|-|-|
| Poetry | >= 1.2.0 |
Install python dependencies:
[1]:https://labinfo.ing.he-arc.ch/gitlab/igib/documents-latex/rsvp-specs