wrp

package
v0.9.0-alpha Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package wrp provides the functionality for converting to and from golang structures into binary wrp messages.

Index

Constants

View Source
const (
	AuthMessageType                  = MessageType(2)
	SimpleRequestResponseMessageType = MessageType(3)
	SimpleEventMessageType           = MessageType(4)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder interface {
	Decode(interface{}) error
	Reset(io.Reader)
	ResetBytes([]byte)
}

Decoder represents the underlying ugorji behavior that WRP supports

func NewDecoder

func NewDecoder(input io.Reader, f Format) Decoder

NewDecoder produces a ugorji Decoder using the appropriate WRP configuration for the given format

func NewDecoderBytes

func NewDecoderBytes(input []byte, f Format) Decoder

NewDecoderBytes produces a ugorji Decoder using the appropriate WRP configuration for the given format

type Encoder

type Encoder interface {
	Encode(interface{}) error
	Reset(io.Writer)
	ResetBytes(*[]byte)
}

Encoder represents the underlying ugorji behavior that WRP supports

func NewEncoder

func NewEncoder(output io.Writer, f Format) Encoder

NewEncoder produces a ugorji Encoder using the appropriate WRP configuration for the given format

func NewEncoderBytes

func NewEncoderBytes(output *[]byte, f Format) Encoder

NewEncoderBytes produces a ugorji Encoder using the appropriate WRP configuration for the given format

type Format

type Format int

Format indicates which format is desired

const (
	JSON Format = iota
	Msgpack
)

type Message

type Message struct {
	Type            MessageType `msgpack:"msg_type" json:"-"`
	Status          *int64      `msgpack:"status,omitempty" json:"status,omitempty"`
	TransactionUUID string      `msgpack:"transaction_uuid,omitempty" json:"transaction_uuid,omitempty"`
	Source          string      `msgpack:"source,omitempty" json:"source,omitempty"`
	Destination     string      `msgpack:"dest,omitempty" json:"dest,omitempty"`
	Payload         []byte      `msgpack:"payload,omitempty" json:"payload,omitempty"`
}

Message represents a single WRP message. The Type field determines how the other fields are interpreted. For example, if the Type is AuthMessageType, then only Status will be set.

TODO: Type isn't serialized as JSON right now. If it can be serialized without breaking clients, that would simplify the Message mapping tags.

func NewAuth

func NewAuth(status int64) *Message

NewAuth is a convenience factory function for creating an authorization WRP message

func NewSimpleEvent

func NewSimpleEvent(destination string, payload []byte) *Message

NewSimpleEvent is a convenience factory function for creating a simple event message

func NewSimpleRequestResponse

func NewSimpleRequestResponse(destination, source string, payload []byte) *Message

NewSimpleRequestResponse is a convenience factory function for creating a simple request/response message

func (*Message) DeduceType

func (m *Message) DeduceType() error

DeduceType examines the message fields other than Type to determine what the message type is, then sets that type on the message.

This method is a bit of a hack. It allows for formats like JSON where we don't deserialize the type from the message.

func (*Message) String

func (m *Message) String() string

String returns a useful string representation of this message

func (*Message) Valid

func (m *Message) Valid() error

Valid performs a basic validation check on a given message

type MessageType

type MessageType int64

MessageType indicates the kind of WRP message

func (MessageType) String

func (mt MessageType) String() string

Jump to

Keyboard shortcuts

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