https://github.com/libyarp/yarp
YARP implementation for Go
https://github.com/libyarp/yarp
golang rpc rpc-library
Last synced: 3 months ago
JSON representation
YARP implementation for Go
- Host: GitHub
- URL: https://github.com/libyarp/yarp
- Owner: libyarp
- License: lgpl-3.0
- Created: 2022-04-25T14:53:49.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-08-30T13:59:33.000Z (over 2 years ago)
- Last Synced: 2025-08-03T00:08:38.678Z (8 months ago)
- Topics: golang, rpc, rpc-library
- Language: Go
- Homepage:
- Size: 26.4 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# yarp
YARP (Yet Another RPC Protocol) is a simple serialization format and RPC
protocol. YARP is:
- Lighter than JSON
- Lighter than HTTP
- Heavier than Protocol Buffers/gRPC, Cap'n'Proto, and MessagePack
And it does not intend to replace any of the former.
YARP does not use sticky connections, making it load-balancer-friendly, and
provides cleaner autogenerated code.
## Why should I use YARP?
You shouldn't. YARP is a proof of concept and currently considered quite
unstable; This may change over time, as it begins being used on real projects,
but it still does not provide features found in Protobufs/gRPC.
You are, however, welcome to use it as you deem fit. Feel free to open an issue
in case you stumble in an odd behaviour.
## How do I use YARP?
YARP is composed of three distinct parts:
1. Message and Service Definitions
2. Autogenerated code
3. Services implementation
YARP's IDL is quite similar to Protobuf's, making it familiar out-of-box. First,
define messages and services:
```
package io.libyarp;
message RandomBytesRequest {
desired_length int8 = 0; # Fields indexes begin at zero.
}
message RandomBytesResponse {
@repeated data uint8 = 0;
}
service RandomBytesService {
generate_random_bytes(RandomBytesRequest) -> RandomBytesResponse;
}
```
Then, provide the definition to [`yarpc`](https://github.com/libyarp/yarpc):
```
$ yarpc random_bytes_service.yarp --lang go --package rbs --out rbs.yarp.go
```
Finally, implement the service:
```go
package rbs
import "context"
import "math/rand"
import "github.com/libyarp/yarp"
type RandomBytesImplementation struct{}
func (r RandomBytesImplementation) GenerateRandomBytes(ctx context.Context, headers yarp.Header, req *RandomBytesRequest) (*RandomBytesResponse, yarp.Header, error) {
data := make([]byte, req.DesiredLength)
if _, err := rand.Read(data); err != nil {
return nil, nil, err
}
return &RandomBytesResponse{Data: data}, nil, nil
}
func main() {
s := yarp.NewServer("127.0.0.1:9027")
srv := RandomBytesImplementation{}
RegisterMessages()
RegisterRandomBytesService(s, &srv)
err := s.Start()
if err != nil {
// ...
}
}
```
## Protocol Documentation
TBW