Documentation
¶
Overview ¶
Package store provides functions to store a protobuf message to different formats: json, bin, and txt.
Index ¶
- func MarshalToBin(msg proto.Message) (out []byte, err error)
- func MarshalToJSON(msg proto.Message, options *MarshalOptions) (out []byte, err error)
- func MarshalToText(msg proto.Message, pretty bool) (out []byte, err error)
- func Store(msg proto.Message, dir string, fmt format.Format, options ...Option) error
- type FilterFunc
- type MarshalOptions
- type Option
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalToBin ¶
MarshalToBin marshals the given proto.Message in the wire (binary) format. You can depend on the output being stable.
func MarshalToJSON ¶
func MarshalToJSON(msg proto.Message, options *MarshalOptions) (out []byte, err error)
MarshalToJSON marshals the given proto.Message in the JSON format. You can depend on the output being stable.
func MarshalToText ¶
MarshalToText marshals the given proto.Message in the text (textproto) format. You can depend on the output being stable.
Types ¶
type FilterFunc ¶
FilterFunc filter in messagers if returned value is true.
NOTE: name is the protobuf message name, e.g.: "message ItemConf{...}".
FilterFunc is redefined here (also defined in "load" package) to avoid "import cycle" problem.
type MarshalOptions ¶
type MarshalOptions struct {
// Output pretty format of JSON and Text, with multiline and indent.
//
// Default: false.
Pretty bool
// EmitUnpopulated specifies whether to emit unpopulated fields. It does not
// emit unpopulated oneof fields or unpopulated extension fields.
// The JSON value emitted for unpopulated fields are as follows:
// ╔═══════╤════════════════════════════╗
// ║ JSON │ Protobuf field ║
// ╠═══════╪════════════════════════════╣
// ║ false │ proto3 boolean fields ║
// ║ 0 │ proto3 numeric fields ║
// ║ "" │ proto3 string/bytes fields ║
// ║ null │ proto2 scalar fields ║
// ║ null │ message fields ║
// ║ [] │ list fields ║
// ║ {} │ map fields ║
// ╚═══════╧════════════════════════════╝
//
// NOTE: worksheet with FieldPresence set as true ignore this option.
//
// Refer: https://github.com/protocolbuffers/protobuf/blob/main/docs/field_presence.md
//
// Default: false.
EmitUnpopulated bool
// UseProtoNames uses proto field name instead of lowerCamelCase name in JSON
// field names.
UseProtoNames bool
// UseEnumNumbers emits enum values as numbers.
UseEnumNumbers bool
}
type Option ¶
type Option func(*Options)
Option is the functional option type.
func EmitUnpopulated ¶
EmitUnpopulated specifies whether to emit unpopulated fields.
func Filter ¶
func Filter(filter FilterFunc) Option
Filter can only filter in certain specific messagers based on the condition that you provide.
NOTE: only used in https://github.com/tableauio/loader.
func UseEnumNumbers ¶
UseEnumNumbers specifies whether to emit enum values as numbers for JSON field values.
func UseProtoNames ¶
UseProtoNames specifies whether to use proto field name instead of lowerCamelCase name in JSON field names.
type Options ¶
type Options struct {
// Filter can only filter in certain specific messagers based on the
// condition that you provide.
//
// NOTE: only used in https://github.com/tableauio/loader.
//
// Default: nil.
Filter FilterFunc
// Specify output file name (without file extension).
//
// Default: "".
Name string
// Output pretty format of JSON and Text, with multiline and indent.
//
// Default: false.
Pretty bool
// EmitUnpopulated specifies whether to emit unpopulated fields. It does not
// emit unpopulated oneof fields or unpopulated extension fields.
// The JSON value emitted for unpopulated fields are as follows:
// ╔═══════╤════════════════════════════╗
// ║ JSON │ Protobuf field ║
// ╠═══════╪════════════════════════════╣
// ║ false │ proto3 boolean fields ║
// ║ 0 │ proto3 numeric fields ║
// ║ "" │ proto3 string/bytes fields ║
// ║ null │ proto2 scalar fields ║
// ║ null │ message fields ║
// ║ [] │ list fields ║
// ║ {} │ map fields ║
// ╚═══════╧════════════════════════════╝
//
// NOTE: worksheet with FieldPresence set as true ignore this option.
//
// Refer: https://github.com/protocolbuffers/protobuf/blob/main/docs/field_presence.md
//
// Default: false.
EmitUnpopulated bool
// UseProtoNames uses proto field name instead of lowerCamelCase name in JSON
// field names.
UseProtoNames bool
// UseEnumNumbers emits enum values as numbers.
UseEnumNumbers bool
}
func ParseOptions ¶
ParseOptions parses functional options and merge them to default Options.