jsonpb

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2023 License: MIT Imports: 10 Imported by: 4

README

jsonpb

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnexpectedToken = errors.New("unexpected token")
	ErrTypeMismatch    = errors.New("field type mismatch")
)
View Source
var (
	ErrInvalidWireType = errors.New("invalid wire type")
)

Functions

func IsNumericKind

func IsNumericKind(k Kind) bool

func TranscodeToJson

func TranscodeToJson(j *JsonBuilder, p *proto.Decoder, msg *Message) error

TranscodeToJson 通过 proto.Decoder 解析 pb,并且追加到 JsonBuilder 中

func TranscodeToProto

func TranscodeToProto(p *proto.Encoder, j *JsonIter, msg *Message) error

TranscodeToProto 通过 JsonIter 解析 JSON,并且根据 msg 将 JSON 内容转译到 protobuf 二进制。 注意,受限于 metadata 可表达的结构和一些取舍,对 JSON 的解析并不按照 JSON 标准。

Types

type Field

type Field struct {
	Name     string
	Kind     Kind
	Ref      *Message
	Tag      uint32
	Repeated bool
	Omit     OmitRule
}

type JsonBuilder

type JsonBuilder struct {
	// contains filtered or unexported fields
}

func UnsafeJsonBuilder

func UnsafeJsonBuilder(buf []byte) *JsonBuilder

func (*JsonBuilder) AppendByte

func (b *JsonBuilder) AppendByte(c byte)

func (*JsonBuilder) AppendBytes

func (b *JsonBuilder) AppendBytes(s ...byte)

func (*JsonBuilder) AppendEscapedString

func (b *JsonBuilder) AppendEscapedString(s string)

func (*JsonBuilder) AppendString

func (b *JsonBuilder) AppendString(s string)

func (*JsonBuilder) IntoBytes

func (b *JsonBuilder) IntoBytes() []byte

func (*JsonBuilder) Len

func (b *JsonBuilder) Len() int

func (*JsonBuilder) Reserve

func (b *JsonBuilder) Reserve(n int)

func (*JsonBuilder) String

func (b *JsonBuilder) String() string

type JsonIter

type JsonIter = jsonlit.Iter[[]byte]

type Kind

type Kind uint8
const (
	DoubleKind Kind = iota
	FloatKind
	Int32Kind
	Int64Kind
	Uint32Kind
	Uint64Kind
	Sint32Kind
	Sint64Kind
	Fixed32Kind
	Fixed64Kind
	Sfixed32Kind
	Sfixed64Kind
	BoolKind
	StringKind
	BytesKind
	MapKind
	MessageKind
)

type Message

type Message struct {
	Name   string
	Fields []Field
	// contains filtered or unexported fields
}

func NewMessage

func NewMessage(name string, fields []Field, indexTag bool, indexName bool) *Message

func (*Message) BakeNameIndex

func (m *Message) BakeNameIndex()

func (*Message) BakeTagIndex

func (m *Message) BakeTagIndex()

func (*Message) FieldByName

func (m *Message) FieldByName(name string) *Field

func (*Message) FieldByTag

func (m *Message) FieldByTag(tag uint32) *Field

func (*Message) FieldIndexByTag

func (m *Message) FieldIndexByTag(tag uint32) int

type OmitRule added in v0.2.0

type OmitRule uint8
const (
	// OmitProtoEmpty 只在 pb 输出"空值"时跳过字段
	OmitProtoEmpty OmitRule = iota
	// OmitEmpty 在 pb 和 json 输出"空值"跳过字段
	OmitEmpty
	// OmitAlways 总是跳过字段
	OmitAlways
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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