protocol

package
v1.31.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: MIT Imports: 5 Imported by: 31

Documentation

Overview

Package protocol provides implementations of different Thrift protocols.

Index

Constants

This section is empty.

Variables

View Source
var BinaryStreamer stream.Protocol

BinaryStreamer implements a streaming version of the Thrift Binary Protocol.

Functions

This section is empty.

Types

type EnvelopeAgnosticProtocol added in v1.9.0

type EnvelopeAgnosticProtocol interface {
	Protocol

	// DecodeRequest reads an enveloped or un-enveloped struct from the given
	// ReaderAt.
	// This allows a Thrift request handler to transparently accept requests
	// regardless of whether the caller is configured to submit envelopes.
	// The caller specifies the expected envelope type, one of OneWay or Unary,
	// on which the decoder asserts if the envelope is present.
	DecodeRequest(et wire.EnvelopeType, r io.ReaderAt) (wire.Value, Responder, error)
}

EnvelopeAgnosticProtocol defines a specific way for a Thrift value to be encoded or decoded, additionally being able to decode requests without prior knowledge of whether the request is enveloped.

The Binary protocol in particular can be upcast to EnvelopeAgnosticProtocol.

var EnvelopeAgnosticBinary EnvelopeAgnosticProtocol

EnvelopeAgnosticBinary implements the Thrift Binary Protocol, using DecodeRequest for request bodies that may or may not have an envelope. This in turn produces a responder with an EncodeResponse method so a handler can reply in-kind.

EnvelopeAgnosticBinary makes some practical assumptions about messages to be able to distinguish enveloped, versioned enveloped, and not-enveloped messages reliably:

  1. No message will use an envelope version greater than 0x7fff. This would flip the bit that makes versioned envelopes recognizable. The only envelope version we recognize today is version 1.

  2. No message with an unversioned envelope will have a message name (procedure name) longer than 0x00ffffffff (three bytes of length prefix). This would roll into the byte that distinguishes the type of the first field of an un-enveloped struct. This would require a 16MB procedure name.

The overlapping grammars are:

  1. Enveloped (strict, with version)

    versionbits:4 methodname~4 seqid:4 struct

    versionbits := 0x80000000 | (version:2 << 16) | messagetype:2

  2. Enveloped (non-strict, without version)

    methodname~4 messagetype:1 seqid:4 struct

  3. Unenveloped

    struct := (typeid:1 fieldid:2 <value>)* typeid:1=0x00

A message can be,

  1. Enveloped (strict)

    The message must begin with 0x80 -- the first byte of the version number.

  2. Enveloped (non-strict)

    The message begins with the length of the method name. As long as the method name is not 16 MB long, the first byte of this message is 0x00. If the message contains at least 9 other bytes, it is enveloped using the non-strict format.

    4 bytes method name length (minimum = 0) n bytes method name 1 byte message type 4 bytes sequence ID 1 byte empty struct (0x00) -------- >10 bytes

  3. Unenveloped

    If the message begins with 0x00 but does not contain any more bytes, it's a bare, un-enveloped empty struct.

    If the message begins with any other byte, it's an unenveloped message or an invalid request.

type EnvelopeV0Responder deprecated added in v1.9.0

type EnvelopeV0Responder = binary.EnvelopeV0Responder

EnvelopeV0Responder responds to requests with a non-strict (unversioned) envelope.

Deprecated: Don't use this directly. Use DecodeRequest.

type EnvelopeV1Responder deprecated added in v1.9.0

type EnvelopeV1Responder = binary.EnvelopeV1Responder

EnvelopeV1Responder responds to requests with a strict, version 1 envelope.

Deprecated: Don't use this directly. Use DecodeRequest.

type Protocol

type Protocol interface {
	// Encode the given Value and write the result to the given Writer.
	Encode(v wire.Value, w io.Writer) error

	// EncodeEnveloped encodes the enveloped value and writes the result
	// to the given Writer.
	EncodeEnveloped(e wire.Envelope, w io.Writer) error

	// Decode reads a Value of the given type from the given Reader.
	Decode(r io.ReaderAt, t wire.Type) (wire.Value, error)

	// DecodeEnveloped reads an enveloped value from the given Reader.
	// Enveloped values are assumed to be TStructs.
	DecodeEnveloped(r io.ReaderAt) (wire.Envelope, error)
}

Protocol defines a specific way for a Thrift value to be encoded or decoded.

var Binary Protocol

Binary implements the Thrift Binary Protocol. Binary can be cast up to EnvelopeAgnosticProtocol to support DecodeRequest.

Deprecated: Don't use this directly. Use binary.Default.

type Responder deprecated added in v1.9.0

type Responder = envelope.Responder

Responder captures how to respond to a request, concerning whether and what kind of envelope to use, how to match the sequence identifier of the corresponding request.

Deprecated: Use envelope.Responder.

var NoEnvelopeResponder Responder = binary.NoEnvelopeResponder

NoEnvelopeResponder responds to a request without an envelope.

Deprecated: Don't use this directly. Use DecodeRequest.

Directories

Path Synopsis
Package binary implements the Thrift Binary protocol.
Package binary implements the Thrift Binary protocol.
Package stream provides streaming implementations of encoding and decoding Thrift values.
Package stream provides streaming implementations of encoding and decoding Thrift values.

Jump to

Keyboard shortcuts

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