A very simple RPC - Remote Procedure Calls, implemented in Odin with JSON marshaling/unmarshaling.
This is a RPC client and a RPC server made in Odin. The heavy lifthing is made by JSON module.
-
In this example there are 7 RPC calls:
add- Sums 2 intmul- Multiply 2 f64add_vec- Sums 2 vectors element by elementswap_vec- Swap vetors ( a = b, c = a )echo_string- Echoes a stringprocess_person- Processes Person complex structuretransform_data- Transforms a nexted structure
-
Suports for the parameters and return type:
- Strut inside struct
- Internal arrays and slices
- Mensages of any size ( including megabytes )
- Has return of errors.
rpc_types.odin- types, structs, parameter and return typesrpc_server.odin- Implementation of RPC serverrpc_client.odin- Implementation of RPC clientmain_server.odin- Main server programmain_client.odin- Main client programa
make all_server
make run_servermake all_client
make run_client- Client serialize parameters to JSON
- Client send size ( 4 bytes ) + JSON data
- Server receives, deserializes e executs funtion
- Server serializes result to JSON
- Server sends size ( 4 bytes ) + JSON data
- Client receives and deserializes result
This simple RPC supports nexted structures like:
Person :: struct {
name : string,
age : int,
address : Address,
phone_numbers : [ ]string,
}
Data_Container :: struct {
id : int,
values : [ ]f64,
nested : struct {
flag : bool,
items : [ ]string,
},
person : Person,
}MIT Open Source License
Best regards,
Joao Carvalho