encoding

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSpecifyThriftFile = errors.New("specify a Thrift file using --thrift")

ErrSpecifyThriftFile is returned if no Thrift file is specified for a Thrift request.

Functions

This section is empty.

Types

type Encoding

type Encoding string

Encoding is the representation of the data on the wire.

const (
	UnspecifiedEncoding Encoding = ""
	JSON                Encoding = "json"
	Thrift              Encoding = "thrift"
	Raw                 Encoding = "raw"
	Protobuf            Encoding = "proto"
)

The list of supported encodings.

func (Encoding) GetHealth

func (e Encoding) GetHealth(serviceName string) (Serializer, error)

GetHealth returns a serializer for the Health endpoint.

func (Encoding) String

func (e Encoding) String() string

func (*Encoding) UnmarshalFlag

func (e *Encoding) UnmarshalFlag(s string) error

UnmarshalFlag allows Encoding to be used as a flag.

func (*Encoding) UnmarshalText

func (e *Encoding) UnmarshalText(text []byte) error

UnmarshalText imlements the encoding.TextUnmarshaler interface used by JSON, YAML, etc.

type MethodType

type MethodType int

MethodType is type of the RPC method

const (
	// Unary method type is a traditional RPC
	Unary MethodType = iota + 1
	// ClientStream method type RPC sends multiple messages
	ClientStream
	// ServerStream method type RPC receives multiple messages
	ServerStream
	// BidirectionalStream type RPC can send and receive multiple messages
	BidirectionalStream
)

type ProtoErrorDeserializer

type ProtoErrorDeserializer interface {
	// Error converts an error into something that can be displayed to a user.
	ErrorDetails(err error) ([]interface{}, error)
}

ProtoErrorDeserializer deserializes errors. Error details are very specific to proto.

type Serializer

type Serializer interface {
	// Encoding returns the encoding for this serializer.
	Encoding() Encoding

	// Request creates a transport.Request from the given []byte input.
	Request(body []byte) (*transport.Request, error)

	// Response converts a transport.Response into something that can be displayed to a user.
	// For non-raw encodings, this is typically a map[string]interface{}.
	Response(body *transport.Response) (response interface{}, err error)

	// CheckSuccess checks whether the response body is a success, and if not, returns an
	// error with the failure reason.
	CheckSuccess(body *transport.Response) error

	// MethodType returns the type of RPC method
	MethodType() MethodType
}

Serializer serializes and deserializes data for a specific encoding and method.

func NewJSON

func NewJSON(methodName string) Serializer

NewJSON returns a JSON serializer.

func NewProtobuf

func NewProtobuf(fullMethodName string, source protobuf.DescriptorProvider) (Serializer, error)

NewProtobuf returns a protobuf serializer.

func NewRaw

func NewRaw(methodName string) Serializer

NewRaw returns a raw serializer.

func NewThrift

func NewThrift(p ThriftParams) (Serializer, error)

NewThrift returns a Thrift serializer.

type StreamRequestReader

type StreamRequestReader interface {
	// NextBody returns the encoded request body if available, and if not, returns an
	// io.EOF to indicate end of requests and caller must not call it again
	NextBody() ([]byte, error)
}

StreamRequestReader interface exposes method to read multiple request body

type StreamSerializer

type StreamSerializer interface {
	// StreamRequest creates a root stream request, a stream request reader using
	// body reader provided
	StreamRequest(body io.Reader) (*transport.StreamRequest, StreamRequestReader, error)
}

StreamSerializer serializes and deserializes data for a stream requests

type ThriftParams

type ThriftParams struct {
	File        string
	Method      string
	Multiplexed bool
	Envelope    bool
}

ThriftParams contains the parameters for the NewThrift function. We use a struct as there are multiple consecutive arguments of the same type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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