protocol

package
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 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     Meta     `json:"meta"`
	Method   string   `json:"method"`
	Request  *MsgItem `json:"request"`
	Response *MsgItem `json:"response"`
}

Message represents data across plugins

type Meta added in v0.2.6

type Meta struct {
	Version int    `json:"version"`
	UUID    string `json:"uuid"`
	// Nanosecond
	Timestamp       int64 `json:"timestamp"`
	ContainResponse bool  `json:"containResponse"`
}

type MsgItem added in v0.2.6

type MsgItem struct {
	Headers map[string]string `json:"headers"`
	Body    string            `json:"body"`
}

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