proto

package
v0.0.0-...-012d1c6 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

proto protobuf编解码的简单实现,限制是仅仅支持工具生成协议,好处是不依赖官方库,而且代码量也少

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSupport = errors.New("protobuf not support")

Functions

func Marshal

func Marshal(pb Message) ([]byte, error)

Marshal takes a protocol buffer message and encodes it into the wire format, returning the data. This is the main entry point.

func Unmarshal

func Unmarshal(buf []byte, pb Message) error

Unmarshal parses the protocol buffer representation in buf and places the decoded result in pb. If the struct underlying pb does not match the data in buf, the results can be unpredictable.

Unmarshal resets pb before starting to unmarshal, so any existing data in pb is always removed. Use UnmarshalMerge to preserve and append to existing data.

Types

type Marshaler

type Marshaler interface {
	Marshal() ([]byte, error)
}

Marshaler is the interface representing objects that can marshal themselves.

type Message

type Message interface {
	Reset()
	String() string
	ProtoMessage()
}

Text is implemented by generated protocol buffer messages.

type Unmarshaler

type Unmarshaler interface {
	Unmarshal([]byte) error
}

Unmarshaler is the interface representing objects that can unmarshal themselves. The argument points to data that may be overwritten, so implementations should not keep references to the buffer. Unmarshal implementations should not clear the receiver. Any unmarshaled data should be merged into the receiver. Callers of Unmarshal that do not want to retain existing data should Reset the receiver before calling Unmarshal.

Jump to

Keyboard shortcuts

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