3 releases
0.7.2 | Nov 26, 2024 |
---|---|
0.7.1 | Nov 22, 2024 |
0.7.0 | Nov 22, 2024 |
#1667 in Web programming
405 downloads per month
Used in 2 crates
110KB
2.5K
SLoC
protosocket-rpc
For making RPC servers and clients.
A protosocket rpc server consists of a couple key traits:
SocketService
: Your service that takes new connections and producesConnectionService
s.ConnectionService
: Your service that manages a connection, creating new RPC futures and doing bookkeeping.Message
: Your way to get protosocket metadata out of your encoded messages.
A protosocket rpc client is a little more basic, just relying on common protosocket traits and Message
.
Protosocket rpc lets you choose any encoding and does not wrap your messages at all. The bytes you
send are the bytes which are sent. This means you need to provide a way to communicate the basic protosocket
metadata on each message: A message_id u64 and a control code u8. The Message
trait helps to ensure you get
the needful functions wired through.
lib.rs
:
Protosocket RPC
This crate provides an rpc-style client and server for the protosocket
protocol. You can use whatever encoding you want, but you must provide both a
Serializer
and a Deserializer
for your messages. If you use prost
,
you can use the protosocket-prost
crate to provide these implementations.
See example-proto for an example of how to use this crate with protocol buffers.
Messages must provide a Message
implementation, which includes a message_id
and a control_code
. The message_id
is used to correlate requests and responses,
while the control_code
is used to provide special handling for messages. You can
receive Cancel when an rpc is aborted, and End when a streaming rpc is complete.
This RPC client is medium-low level wrapper around the low level protosocket crate, adding a layer of RPC semantics. You are expected to write a wrapper with the functions that make sense for your application, and use this client as the transport layer.
Clients and servers handle RPC cancellation.
Clients and servers need to agree about the request and response semantics. While it is supported to have dynamic streaming/unary response types, it is recommended to instead use separate rpc-initiating messages for streaming and unary rpcs.
Dependencies
~4–12MB
~135K SLoC