dispatcher

package
v2.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2020 License: Apache-2.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dispatcher

type Dispatcher struct {
	// Protobuf should pass through to Google Protobuf in production paths
	Protobuf Protobuf
}

Dispatcher is used to handle the boilerplate proto tasks of unmarshaling inputs and remarshaling outputs so that the receiver may focus on the implementation details rather than the proto hassles.

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(inputBytes []byte, methodName string, receiver interface{}) ([]byte, error)

Dispatch deserializes the input bytes to the correct type for the method in the receiver, then if successful, marshals the output message to bytes and returns it. On error, it simply returns the error. The method on the receiver must take a single parameter which is a concrete proto message type and it should return a proto message and error.

type Protobuf

type Protobuf interface {
	Marshal(msg proto.Message) (marshaled []byte, err error)
	Unmarshal(marshaled []byte, msg proto.Message) error
}

Protobuf defines the subset of protobuf lifecycle needs and allows for injection of mocked marshaling errors.

type ProtobufImpl

type ProtobufImpl struct{}

ProtobufImpl is the standard implementation to use for Protobuf

func (ProtobufImpl) Marshal

func (p ProtobufImpl) Marshal(msg proto.Message) ([]byte, error)

Marshal passes through to proto.Marshal

func (ProtobufImpl) Unmarshal

func (p ProtobufImpl) Unmarshal(marshaled []byte, msg proto.Message) error

Unmarshal passes through to proto.Unmarshal

Source Files

  • dispatcher.go
  • protobuf.go

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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