rpcstream

package
v0.8.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2022 License: MIT Imports: 11 Imported by: 1

README

RPC Stream

This package implements running a RPC service on top of another.

The "host" service has a signature like:

syntax = "proto3";
package mypackage;

import "github.com/aperturerobotics/starpc/rpcstream/rpcstream.proto";

// HostService proxies RPC calls to a target Mux.
service HostService {
  // MyRpc opens a stream to proxy a RPC call.
  rpc MyRpc(stream .rpcstream.RpcStreamPacket) returns (stream .rpcstream.RpcStreamPacket);
}

NewRpcStreamOpenStream(componentID, hostService.MyRpc) will construct a new OpenStreamFunc which starts a RPC call to MyRpc and forwards the starpc packets over the two-way stream.

The component ID can be used to determine which Mux the client should access.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLength        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflow          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group")
)
View Source
var File_github_com_aperturerobotics_starpc_rpcstream_rpcstream_proto protoreflect.FileDescriptor

Functions

func HandleRpcStream

func HandleRpcStream(stream RpcStream, getter RpcStreamGetter) error

HandleRpcStream handles an incoming RPC stream (remote is the initiator).

func NewRpcStreamOpenStream

func NewRpcStreamOpenStream(rpcCaller RpcStreamCaller, componentID string) srpc.OpenStreamFunc

NewRpcStreamOpenStream constructs an OpenStream function with a RpcStream.

func OpenRpcStream added in v0.5.0

func OpenRpcStream(ctx context.Context, rpcCaller RpcStreamCaller, componentID string) (*srpc.PacketReaderWriter, error)

OpenRpcStream opens a RPC stream with a remote.

Types

type RpcAck added in v0.5.0

type RpcAck struct {

	// Error indicates there was some error setting up the stream.
	Error string `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"`
	// contains filtered or unexported fields
}

RpcAck is the ack message in a RPC stream.

func (*RpcAck) Descriptor deprecated added in v0.5.0

func (*RpcAck) Descriptor() ([]byte, []int)

Deprecated: Use RpcAck.ProtoReflect.Descriptor instead.

func (*RpcAck) EqualVT added in v0.5.0

func (this *RpcAck) EqualVT(that *RpcAck) bool

func (*RpcAck) GetError added in v0.5.0

func (x *RpcAck) GetError() string

func (*RpcAck) MarshalToSizedBufferVT added in v0.5.0

func (m *RpcAck) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*RpcAck) MarshalToVT added in v0.5.0

func (m *RpcAck) MarshalToVT(dAtA []byte) (int, error)

func (*RpcAck) MarshalVT added in v0.5.0

func (m *RpcAck) MarshalVT() (dAtA []byte, err error)

func (*RpcAck) ProtoMessage added in v0.5.0

func (*RpcAck) ProtoMessage()

func (*RpcAck) ProtoReflect added in v0.5.0

func (x *RpcAck) ProtoReflect() protoreflect.Message

func (*RpcAck) Reset added in v0.5.0

func (x *RpcAck) Reset()

func (*RpcAck) SizeVT added in v0.5.0

func (m *RpcAck) SizeVT() (n int)

func (*RpcAck) String added in v0.5.0

func (x *RpcAck) String() string

func (*RpcAck) UnmarshalVT added in v0.5.0

func (m *RpcAck) UnmarshalVT(dAtA []byte) error

type RpcStream

type RpcStream interface {
	srpc.Stream
	Send(*RpcStreamPacket) error
	Recv() (*RpcStreamPacket, error)
}

RpcStream implements a RPC call stream over a RPC call. Used to implement sub-components which have a different set of services & calls available.

type RpcStreamCaller

type RpcStreamCaller func(ctx context.Context) (RpcStream, error)

RpcStreamCaller is a function which starts the RpcStream call.

type RpcStreamGetter

type RpcStreamGetter func(ctx context.Context, componentID string) (srpc.Mux, error)

RpcStreamGetter returns the Mux for the component ID from the remote.

type RpcStreamInit

type RpcStreamInit struct {

	// ComponentId is the identifier of the component making the request.
	ComponentId string `protobuf:"bytes,1,opt,name=component_id,json=componentId,proto3" json:"component_id,omitempty"`
	// contains filtered or unexported fields
}

RpcStreamInit is the first message in a RPC stream.

func (*RpcStreamInit) Descriptor deprecated

func (*RpcStreamInit) Descriptor() ([]byte, []int)

Deprecated: Use RpcStreamInit.ProtoReflect.Descriptor instead.

func (*RpcStreamInit) EqualVT

func (this *RpcStreamInit) EqualVT(that *RpcStreamInit) bool

func (*RpcStreamInit) GetComponentId

func (x *RpcStreamInit) GetComponentId() string

func (*RpcStreamInit) MarshalToSizedBufferVT

func (m *RpcStreamInit) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*RpcStreamInit) MarshalToVT

func (m *RpcStreamInit) MarshalToVT(dAtA []byte) (int, error)

func (*RpcStreamInit) MarshalVT

func (m *RpcStreamInit) MarshalVT() (dAtA []byte, err error)

func (*RpcStreamInit) ProtoMessage

func (*RpcStreamInit) ProtoMessage()

func (*RpcStreamInit) ProtoReflect

func (x *RpcStreamInit) ProtoReflect() protoreflect.Message

func (*RpcStreamInit) Reset

func (x *RpcStreamInit) Reset()

func (*RpcStreamInit) SizeVT

func (m *RpcStreamInit) SizeVT() (n int)

func (*RpcStreamInit) String

func (x *RpcStreamInit) String() string

func (*RpcStreamInit) UnmarshalVT

func (m *RpcStreamInit) UnmarshalVT(dAtA []byte) error

type RpcStreamPacket added in v0.4.5

type RpcStreamPacket struct {

	// Types that are assignable to Body:
	//	*RpcStreamPacket_Init
	//	*RpcStreamPacket_Ack
	//	*RpcStreamPacket_Data
	Body isRpcStreamPacket_Body `protobuf_oneof:"body"`
	// contains filtered or unexported fields
}

RpcStreamPacket is a packet encapsulating data for a RPC stream.

func (*RpcStreamPacket) Descriptor deprecated added in v0.4.5

func (*RpcStreamPacket) Descriptor() ([]byte, []int)

Deprecated: Use RpcStreamPacket.ProtoReflect.Descriptor instead.

func (*RpcStreamPacket) EqualVT added in v0.4.5

func (this *RpcStreamPacket) EqualVT(that *RpcStreamPacket) bool

func (*RpcStreamPacket) GetAck added in v0.5.0

func (x *RpcStreamPacket) GetAck() *RpcAck

func (*RpcStreamPacket) GetBody added in v0.4.5

func (m *RpcStreamPacket) GetBody() isRpcStreamPacket_Body

func (*RpcStreamPacket) GetData added in v0.4.5

func (x *RpcStreamPacket) GetData() []byte

func (*RpcStreamPacket) GetInit added in v0.4.5

func (x *RpcStreamPacket) GetInit() *RpcStreamInit

func (*RpcStreamPacket) MarshalToSizedBufferVT added in v0.4.5

func (m *RpcStreamPacket) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*RpcStreamPacket) MarshalToVT added in v0.4.5

func (m *RpcStreamPacket) MarshalToVT(dAtA []byte) (int, error)

func (*RpcStreamPacket) MarshalVT added in v0.4.5

func (m *RpcStreamPacket) MarshalVT() (dAtA []byte, err error)

func (*RpcStreamPacket) ProtoMessage added in v0.4.5

func (*RpcStreamPacket) ProtoMessage()

func (*RpcStreamPacket) ProtoReflect added in v0.4.5

func (x *RpcStreamPacket) ProtoReflect() protoreflect.Message

func (*RpcStreamPacket) Reset added in v0.4.5

func (x *RpcStreamPacket) Reset()

func (*RpcStreamPacket) SizeVT added in v0.4.5

func (m *RpcStreamPacket) SizeVT() (n int)

func (*RpcStreamPacket) String added in v0.4.5

func (x *RpcStreamPacket) String() string

func (*RpcStreamPacket) UnmarshalVT added in v0.4.5

func (m *RpcStreamPacket) UnmarshalVT(dAtA []byte) error

type RpcStreamPacket_Ack added in v0.5.0

type RpcStreamPacket_Ack struct {
	// Ack is sent in response to Init.
	// Sent by the server.
	Ack *RpcAck `protobuf:"bytes,2,opt,name=ack,proto3,oneof"`
}

func (*RpcStreamPacket_Ack) MarshalToSizedBufferVT added in v0.5.0

func (m *RpcStreamPacket_Ack) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*RpcStreamPacket_Ack) MarshalToVT added in v0.5.0

func (m *RpcStreamPacket_Ack) MarshalToVT(dAtA []byte) (int, error)

func (*RpcStreamPacket_Ack) SizeVT added in v0.5.0

func (m *RpcStreamPacket_Ack) SizeVT() (n int)

type RpcStreamPacket_Data added in v0.4.5

type RpcStreamPacket_Data struct {
	// Data is the encapsulated data packet.
	Data []byte `protobuf:"bytes,3,opt,name=data,proto3,oneof"`
}

func (*RpcStreamPacket_Data) MarshalToSizedBufferVT added in v0.4.5

func (m *RpcStreamPacket_Data) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*RpcStreamPacket_Data) MarshalToVT added in v0.4.5

func (m *RpcStreamPacket_Data) MarshalToVT(dAtA []byte) (int, error)

func (*RpcStreamPacket_Data) SizeVT added in v0.4.5

func (m *RpcStreamPacket_Data) SizeVT() (n int)

type RpcStreamPacket_Init added in v0.4.5

type RpcStreamPacket_Init struct {
	// Init is the first packet in the stream.
	// Sent by the initiator.
	Init *RpcStreamInit `protobuf:"bytes,1,opt,name=init,proto3,oneof"`
}

func (*RpcStreamPacket_Init) MarshalToSizedBufferVT added in v0.4.5

func (m *RpcStreamPacket_Init) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*RpcStreamPacket_Init) MarshalToVT added in v0.4.5

func (m *RpcStreamPacket_Init) MarshalToVT(dAtA []byte) (int, error)

func (*RpcStreamPacket_Init) SizeVT added in v0.4.5

func (m *RpcStreamPacket_Init) SizeVT() (n int)

type RpcStreamReadWriter

type RpcStreamReadWriter struct {
	// contains filtered or unexported fields
}

RpcStreamReadWriter reads and writes a buffered RpcStream.

func NewRpcStreamReadWriter

func NewRpcStreamReadWriter(stream RpcStream) *RpcStreamReadWriter

NewRpcStreamReadWriter constructs a new read/writer.

func (*RpcStreamReadWriter) Close

func (r *RpcStreamReadWriter) Close() error

Close closes the packet rw.

func (*RpcStreamReadWriter) Read added in v0.5.0

func (r *RpcStreamReadWriter) Read(p []byte) (n int, err error)

Read reads a packet from the writer.

func (*RpcStreamReadWriter) Write added in v0.5.0

func (r *RpcStreamReadWriter) Write(p []byte) (n int, err error)

Write writes a packet to the writer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL