brpc

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CompressTypeNo     int32 = 0
	CompressTypeSnappy int32 = 1
	CompressTypeGzip   int32 = 2
)
View Source
const (
	ErrorCodeUnknown int32 = -255
)

Variables

View Source
var (
	ErrInvalidProtocol = errors.New("invalid protocol")
	ErrInvalidHeader   = errors.New("invalid header")
	ErrInvalidMeta     = errors.New("invalid meta")
)
View Source
var (
	FrameType_name = map[int32]string{
		0: "Unknown",
		1: "Rst",
		2: "Close",
		3: "Data",
		4: "FeedBack",
	}
	FrameType_value = map[string]int32{
		"Unknown":  0,
		"Rst":      1,
		"Close":    2,
		"Data":     3,
		"FeedBack": 4,
	}
)

Enum value maps for FrameType.

View Source
var ErrBodyTooLarge = errors.New("body size is too large")
View Source
var ErrCompressUnknown = errors.New("unsupported compress type")
View Source
var ErrMethodNotFound = errors.New("service or method not found")
View Source
var File_streaming_proto protoreflect.FileDescriptor
View Source
var MaxBodySize = uint32(10 << 20)

MaxBodySize 默认的最大 body 大小

Functions

func GetErrorCode

func GetErrorCode(msg *Message) int32

func IsMetaInvalid

func IsMetaInvalid(meta *Meta) error

Types

type ChunkInfo

type ChunkInfo struct {
	StreamId int64 `protobuf:"varint,1,opt,name=stream_id,json=streamId,proto3" json:"stream_id,omitempty"`
	ChunkId  int64 `protobuf:"varint,2,opt,name=chunk_id,json=chunkId,proto3" json:"chunk_id,omitempty"`
	// contains filtered or unexported fields
}

func (*ChunkInfo) Descriptor deprecated

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

Deprecated: Use ChunkInfo.ProtoReflect.Descriptor instead.

func (*ChunkInfo) GetChunkId

func (x *ChunkInfo) GetChunkId() int64

func (*ChunkInfo) GetStreamId

func (x *ChunkInfo) GetStreamId() int64

func (*ChunkInfo) ProtoMessage

func (*ChunkInfo) ProtoMessage()

func (*ChunkInfo) ProtoReflect

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

func (*ChunkInfo) Reset

func (x *ChunkInfo) Reset()

func (*ChunkInfo) String

func (x *ChunkInfo) String() string

type Feedback

type Feedback struct {
	ConsumedSize int64 `protobuf:"varint,1,opt,name=consumed_size,json=consumedSize,proto3" json:"consumed_size,omitempty"`
	// contains filtered or unexported fields
}

func (*Feedback) Descriptor deprecated

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

Deprecated: Use Feedback.ProtoReflect.Descriptor instead.

func (*Feedback) GetConsumedSize

func (x *Feedback) GetConsumedSize() int64

func (*Feedback) ProtoMessage

func (*Feedback) ProtoMessage()

func (*Feedback) ProtoReflect

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

func (*Feedback) Reset

func (x *Feedback) Reset()

func (*Feedback) String

func (x *Feedback) String() string

type FrameType

type FrameType int32
const (
	FrameType_Unknown  FrameType = 0
	FrameType_Rst      FrameType = 1
	FrameType_Close    FrameType = 2
	FrameType_Data     FrameType = 3
	FrameType_FeedBack FrameType = 4
)

func (FrameType) Descriptor

func (FrameType) Descriptor() protoreflect.EnumDescriptor

func (FrameType) Enum

func (x FrameType) Enum() *FrameType

func (FrameType) EnumDescriptor deprecated

func (FrameType) EnumDescriptor() ([]byte, []int)

Deprecated: Use FrameType.Descriptor instead.

func (FrameType) Number

func (x FrameType) Number() protoreflect.EnumNumber

func (FrameType) String

func (x FrameType) String() string

func (FrameType) Type

type Handler

type Handler interface {
	Handle()
}
type Header struct {
	BodySize uint32
	MetaSize uint32
}

func ReadHeader

func ReadHeader(rd io.Reader) (Header, error)

func (Header) Bytes

func (h Header) Bytes() []byte

func (Header) IsValid

func (h Header) IsValid() error

func (Header) PayloadSize

func (h Header) PayloadSize() uint32

func (Header) WroteTo

func (h Header) WroteTo(w io.Writer) (int64, error)

type Message

type Message struct {
	Meta       *Meta
	Attachment io.Reader
	// contains filtered or unexported fields
}

func (*Message) MethodName

func (req *Message) MethodName() string

func (*Message) ServiceName

func (req *Message) ServiceName() string

func (*Message) Unmarshal

func (req *Message) Unmarshal(msg proto.Message) error

func (*Message) WithMeta

func (req *Message) WithMeta(fn func(m *Meta))

func (*Message) WroteTo

func (req *Message) WroteTo(w io.Writer) (int64, error)

type Meta

type Meta struct {
	Request            *RequestMeta    `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"`
	Response           *ResponseMeta   `protobuf:"bytes,2,opt,name=response,proto3" json:"response,omitempty"`
	CompressType       int32           `protobuf:"varint,3,opt,name=compress_type,json=compressType,proto3" json:"compress_type,omitempty"`
	CorrelationId      int64           `protobuf:"varint,4,opt,name=correlation_id,json=correlationId,proto3" json:"correlation_id,omitempty"`
	AttachmentSize     int32           `protobuf:"varint,5,opt,name=attachment_size,json=attachmentSize,proto3" json:"attachment_size,omitempty"`
	ChunkInfo          *ChunkInfo      `protobuf:"bytes,6,opt,name=chunk_info,json=chunkInfo,proto3" json:"chunk_info,omitempty"`
	AuthenticationData []byte          `protobuf:"bytes,7,opt,name=authentication_data,json=authenticationData,proto3" json:"authentication_data,omitempty"`
	StreamSettings     *StreamSettings `protobuf:"bytes,8,opt,name=stream_settings,json=streamSettings,proto3" json:"stream_settings,omitempty"`
	// contains filtered or unexported fields
}

func (*Meta) Descriptor deprecated

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

Deprecated: Use Meta.ProtoReflect.Descriptor instead.

func (*Meta) GetAttachmentSize

func (x *Meta) GetAttachmentSize() int32

func (*Meta) GetAuthenticationData

func (x *Meta) GetAuthenticationData() []byte

func (*Meta) GetChunkInfo

func (x *Meta) GetChunkInfo() *ChunkInfo

func (*Meta) GetCompressType

func (x *Meta) GetCompressType() int32

func (*Meta) GetCorrelationId

func (x *Meta) GetCorrelationId() int64

func (*Meta) GetRequest

func (x *Meta) GetRequest() *RequestMeta

func (*Meta) GetResponse

func (x *Meta) GetResponse() *ResponseMeta

func (*Meta) GetStreamSettings

func (x *Meta) GetStreamSettings() *StreamSettings

func (*Meta) ProtoMessage

func (*Meta) ProtoMessage()

func (*Meta) ProtoReflect

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

func (*Meta) Reset

func (x *Meta) Reset()

func (*Meta) String

func (x *Meta) String() string

type ReadWriter

type ReadWriter interface {
	Next(ctx context.Context) (*Message, error)
	Write(ctx context.Context, msg *Message) error
}

type Reader

type Reader struct {
	// MaxBodySize 可选,最大 Body 大小,为 0 是会使用 全局变量 MaxBodySize
	MaxBodySize uint32
}

func (*Reader) GetMaxBodySize

func (r *Reader) GetMaxBodySize() uint32

func (*Reader) ReadHeader

func (r *Reader) ReadHeader(rd io.Reader) (Header, error)

func (*Reader) ReadMessage

func (r *Reader) ReadMessage(rd io.Reader, h Header) (*Message, error)

func (*Reader) ReadMeta

func (r *Reader) ReadMeta(rd io.Reader, metaSize uint32) (*Meta, error)

func (*Reader) ReadPackage

func (r *Reader) ReadPackage(rd io.Reader) (Header, *Message, error)

type RequestMeta

type RequestMeta struct {
	ServiceName  string `protobuf:"bytes,1,opt,name=service_name,json=serviceName,proto3" json:"service_name,omitempty"`
	MethodName   string `protobuf:"bytes,2,opt,name=method_name,json=methodName,proto3" json:"method_name,omitempty"`
	LogId        int64  `protobuf:"varint,3,opt,name=log_id,json=logId,proto3" json:"log_id,omitempty"`
	TraceId      int64  `protobuf:"varint,4,opt,name=trace_id,json=traceId,proto3" json:"trace_id,omitempty"`
	SpanId       int64  `protobuf:"varint,5,opt,name=span_id,json=spanId,proto3" json:"span_id,omitempty"`
	ParentSpanId int64  `protobuf:"varint,6,opt,name=parent_span_id,json=parentSpanId,proto3" json:"parent_span_id,omitempty"`
	RequestId    string `protobuf:"bytes,7,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"`  // correspond to x-request-id in http header
	TimeoutMs    int32  `protobuf:"varint,8,opt,name=timeout_ms,json=timeoutMs,proto3" json:"timeout_ms,omitempty"` // client's timeout setting for current call
	// contains filtered or unexported fields
}

func (*RequestMeta) Descriptor deprecated

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

Deprecated: Use RequestMeta.ProtoReflect.Descriptor instead.

func (*RequestMeta) GetLogId

func (x *RequestMeta) GetLogId() int64

func (*RequestMeta) GetMethodName

func (x *RequestMeta) GetMethodName() string

func (*RequestMeta) GetParentSpanId

func (x *RequestMeta) GetParentSpanId() int64

func (*RequestMeta) GetRequestId

func (x *RequestMeta) GetRequestId() string

func (*RequestMeta) GetServiceName

func (x *RequestMeta) GetServiceName() string

func (*RequestMeta) GetSpanId

func (x *RequestMeta) GetSpanId() int64

func (*RequestMeta) GetTimeoutMs

func (x *RequestMeta) GetTimeoutMs() int32

func (*RequestMeta) GetTraceId

func (x *RequestMeta) GetTraceId() int64

func (*RequestMeta) ProtoMessage

func (*RequestMeta) ProtoMessage()

func (*RequestMeta) ProtoReflect

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

func (*RequestMeta) Reset

func (x *RequestMeta) Reset()

func (*RequestMeta) String

func (x *RequestMeta) String() string

type ResponseMeta

type ResponseMeta struct {
	ErrorCode int32  `protobuf:"varint,1,opt,name=error_code,json=errorCode,proto3" json:"error_code,omitempty"`
	ErrorText string `protobuf:"bytes,2,opt,name=error_text,json=errorText,proto3" json:"error_text,omitempty"`
	// contains filtered or unexported fields
}

func (*ResponseMeta) Descriptor deprecated

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

Deprecated: Use ResponseMeta.ProtoReflect.Descriptor instead.

func (*ResponseMeta) GetErrorCode

func (x *ResponseMeta) GetErrorCode() int32

func (*ResponseMeta) GetErrorText

func (x *ResponseMeta) GetErrorText() string

func (*ResponseMeta) ProtoMessage

func (*ResponseMeta) ProtoMessage()

func (*ResponseMeta) ProtoReflect

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

func (*ResponseMeta) Reset

func (x *ResponseMeta) Reset()

func (*ResponseMeta) String

func (x *ResponseMeta) String() string

type Router

type Router struct {
	Reader *Reader
	// contains filtered or unexported fields
}

func (*Router) Handle

func (r *Router) Handle(ctx context.Context, conn net.Conn)

func (*Router) Register

func (r *Router) Register(service, method string, handler Handler)

type SimpleHandler

type SimpleHandler interface {
	Handler
	HandleSimple(ctx context.Context, msg *Message) *Message
}

type StreamFrameMeta

type StreamFrameMeta struct {
	StreamId        int64     `protobuf:"varint,1,opt,name=stream_id,json=streamId,proto3" json:"stream_id,omitempty"`
	SourceStreamId  int64     `protobuf:"varint,2,opt,name=source_stream_id,json=sourceStreamId,proto3" json:"source_stream_id,omitempty"`
	FrameType       FrameType `protobuf:"varint,3,opt,name=frame_type,json=frameType,proto3,enum=brpc.FrameType" json:"frame_type,omitempty"`
	HasContinuation bool      `protobuf:"varint,4,opt,name=has_continuation,json=hasContinuation,proto3" json:"has_continuation,omitempty"`
	Feedback        *Feedback `protobuf:"bytes,5,opt,name=feedback,proto3" json:"feedback,omitempty"`
	// contains filtered or unexported fields
}

func (*StreamFrameMeta) Descriptor deprecated

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

Deprecated: Use StreamFrameMeta.ProtoReflect.Descriptor instead.

func (*StreamFrameMeta) GetFeedback

func (x *StreamFrameMeta) GetFeedback() *Feedback

func (*StreamFrameMeta) GetFrameType

func (x *StreamFrameMeta) GetFrameType() FrameType

func (*StreamFrameMeta) GetHasContinuation

func (x *StreamFrameMeta) GetHasContinuation() bool

func (*StreamFrameMeta) GetSourceStreamId

func (x *StreamFrameMeta) GetSourceStreamId() int64

func (*StreamFrameMeta) GetStreamId

func (x *StreamFrameMeta) GetStreamId() int64

func (*StreamFrameMeta) ProtoMessage

func (*StreamFrameMeta) ProtoMessage()

func (*StreamFrameMeta) ProtoReflect

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

func (*StreamFrameMeta) Reset

func (x *StreamFrameMeta) Reset()

func (*StreamFrameMeta) String

func (x *StreamFrameMeta) String() string

type StreamHandler

type StreamHandler interface {
	Handler
	HandleStream(ctx context.Context, msg *Message, rw ReadWriter) error
}

type StreamSettings

type StreamSettings struct {
	StreamId     int64 `protobuf:"varint,1,opt,name=stream_id,json=streamId,proto3" json:"stream_id,omitempty"`
	NeedFeedback bool  `protobuf:"varint,2,opt,name=need_feedback,json=needFeedback,proto3" json:"need_feedback,omitempty"`
	Writable     bool  `protobuf:"varint,3,opt,name=writable,proto3" json:"writable,omitempty"`
	// contains filtered or unexported fields
}

func (*StreamSettings) Descriptor deprecated

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

Deprecated: Use StreamSettings.ProtoReflect.Descriptor instead.

func (*StreamSettings) GetNeedFeedback

func (x *StreamSettings) GetNeedFeedback() bool

func (*StreamSettings) GetStreamId

func (x *StreamSettings) GetStreamId() int64

func (*StreamSettings) GetWritable

func (x *StreamSettings) GetWritable() bool

func (*StreamSettings) ProtoMessage

func (*StreamSettings) ProtoMessage()

func (*StreamSettings) ProtoReflect

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

func (*StreamSettings) Reset

func (x *StreamSettings) Reset()

func (*StreamSettings) String

func (x *StreamSettings) String() string

Jump to

Keyboard shortcuts

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