protocol

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const CodecJsonName = "json"
View Source
const CodecSimpleName = "simple"

Variables

This section is empty.

Functions

func RegisterCodec

func RegisterCodec(codec Codec)

Types

type Codec

type Codec interface {
	// Marshal returns the wire format of v.
	Marshal(v *Message) ([]byte, error)
	// Unmarshal parses the wire format into v.
	Unmarshal(data []byte, v *Message) error
	// Name returns the name of the Codec implementation. The returned string
	// will be used as part of content type in transmission.  The result must be
	// static; the result cannot change between calls.
	Name() string
}

func GetCodec

func GetCodec(codecType string) Codec

The content-subtype is expected to be lowercase.

type CodecJson

type CodecJson struct{}

func (CodecJson) Marshal

func (c CodecJson) Marshal(v *Message) ([]byte, error)

func (CodecJson) Name

func (c CodecJson) Name() string

func (CodecJson) Unmarshal

func (c CodecJson) Unmarshal(data []byte, v *Message) error

type CodecSimple

type CodecSimple struct{}

func (CodecSimple) Marshal

func (c CodecSimple) Marshal(msg *Message) ([]byte, error)

func (CodecSimple) Name

func (c CodecSimple) Name() string

func (CodecSimple) Unmarshal

func (c CodecSimple) Unmarshal(data []byte, msg *Message) error

type Message

type Message struct {
	Meta struct {
		Version int    `json:"version"`
		UUID    string `json:"uuid"`
		// Nanosecond
		Timestamp int64 `json:"timestamp"`
	}
	Data struct {
		Headers map[string]string `json:"headers"`
		Method  string            `json:"method"`
		Request string            `json:"request"`
	}
}

Message represents data across plugins

type Protocol

type Protocol interface {
	Encode(msg *Message) (bt []byte, err error)
	Decode(bt []byte) (msg *Message, err error)
}

Jump to

Keyboard shortcuts

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