Skip to content

libyarp/yarp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

$ yarpc random_bytes_service.yarp --lang go --package rbs --out rbs.yarp.go

Finally, implement the service:

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