Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new streaming interfaces for the no-wire representation implementation of ThriftRW #485

Merged
merged 1 commit into from
Jun 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions protocol/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,91 @@ type Responder interface {
// The EnvelopeType should be either wire.Reply or wire.Exception.
EncodeResponse(v wire.Value, t wire.EnvelopeType, w io.Writer) error
}

// StreamProtocol defines a specific way for a Thrift value to be encoded or
// decoded, implemented in a streaming fashion.
type StreamProtocol interface {
// StreamWriter returns a streaming implementation of an encoder for a
// Thrift value.
StreamWriter(w io.Writer) Writer
// StreamReader returns a streaming implementation of a decoder for a
// Thrift value.
StreamReader(r io.Reader) Reader
}

// FieldHeader defines the metadata needed to define the beginning of a field
// in a Thrift value.
type FieldHeader struct {
ID int16
Type wire.Type
}

// MapHeader defines the metadata needed to define the beginning of a map in a
// Thrift value.
type MapHeader struct {
KeyType wire.Type
ValueType wire.Type
Length int
}

// SetHeader defines the metadata needed to define the beginning of a set in a
// Thrift value.
type SetHeader struct {
Length int
Type wire.Type
}

// ListHeader defines the metadata needed to define the beginning of a list in a
// Thrift value.
type ListHeader struct {
Length int
Type wire.Type
}

// Writer defines an encoder for a Thrift value, implemented in a streaming
// fashion.
type Writer interface {
WriteBool(b bool) error
WriteInt8(i int8) error
WriteInt16(i int16) error
WriteInt32(i int32) error
WriteInt64(i int64) error
WriteString(s string) error
WriteDouble(f float64) error
WriteBinary(b []byte) error
WriteStructBegin() error
WriteStructEnd() error
WriteFieldBegin(f FieldHeader) error
WriteFieldEnd() error
WriteMapBegin(m MapHeader) error
WriteMapEnd() error
WriteSetBegin(s SetHeader) error
WriteSetEnd() error
WriteListBegin(l ListHeader) error
WriteListEnd() error
}

// Reader defines an decoder for a Thrift value, implemented in a streaming
// fashion.
type Reader interface {
ReadBool() (bool, error)
ReadInt8() (int8, error)
ReadInt16() (int16, error)
ReadInt32() (int32, error)
ReadInt64() (int64, error)
ReadString() (string, error)
ReadDouble() (float64, error)
ReadBinary() ([]byte, error)
ReadStructBegin() error
ReadStructEnd() error
ReadFieldBegin() (FieldHeader, bool, error)
ReadFieldEnd() error
ReadListBegin() (ListHeader, error)
ReadListEnd() error
ReadSetBegin() (SetHeader, error)
ReadSetEnd() error
ReadMapBegin() (MapHeader, error)
ReadMapEnd() error
// Skip skips over the bytes of the wire type and any applicable headers.
Skip(w wire.Type) error
}