std/encoding/protojson
import "github.com/eugenioenko/goalchemy/std/encoding/protojson"Package protojson encodes and decodes proto3 JSON for messages generated by protoc-gen-goalchemy, matching google.golang.org/protobuf/encoding/protojson. Marshal output equals protojson.Marshal’s after removing insignificant whitespace: fields in declaration order, zero values of implicit-presence fields omitted, 64-bit integers as strings, enums by name and map keys sorted. Unmarshal follows protojson.UnmarshalOptions{DiscardUnknown: true}, the options Connect clients use: unknown fields and unknown enum names are ignored, and either the JSON name or the proto name selects a field.
Marshal
Section titled “Marshal”func Marshal(m Message) ([]byte, error)Marshal returns the proto3 JSON encoding of m.
Register
Section titled “Register”func Register(names []string, newMessage func(name string) Message)Register makes generated messages known to Any by full name. Generated packages call it from init.
SortInt64s
Section titled “SortInt64s”func SortInt64s(keys []int64) []int64SortInt64s sorts signed integer map keys in protojson order.
SortUint64s
Section titled “SortUint64s”func SortUint64s(keys []uint64) []uint64SortUint64s sorts unsigned integer map keys in protojson order.
SortedKeys
Section titled “SortedKeys”func SortedKeys(keys []string) []stringSortedKeys returns the keys of a string-keyed map in protojson order.
Unmarshal
Section titled “Unmarshal”func Unmarshal(b []byte, m Message) errorUnmarshal decodes proto3 JSON into m, which it does not reset first.
UnmarshalValue
Section titled “UnmarshalValue”func UnmarshalValue(v jsonvalue.Value, m Message) errorUnmarshalValue decodes an already parsed proto3 JSON value into m.
type Any
Section titled “type Any”type Any struct { TypeURL string Fields jsonvalue.Value}Any is google.protobuf.Any. Fields holds the JSON members that follow “@type”: the embedded message’s fields, or the single member “value” for a well-known type. Payloads of registered generated messages and of the well-known types are kept in canonical form; other payloads are kept as received. Use NewAny and UnmarshalTo to convert typed messages.
NewAny
Section titled “NewAny”func NewAny(typeURL string, m Message) (*Any, error)NewAny packs m under typeURL, for example “type.googleapis.com/policy.Attribute”.
Any.DecodeProtoJSON
Section titled “Any.DecodeProtoJSON”func (x *Any) DecodeProtoJSON(d *Decoder, v jsonvalue.Value)DecodeProtoJSON implements Message.
Any.EncodeProtoJSON
Section titled “Any.EncodeProtoJSON”func (x *Any) EncodeProtoJSON(e *Encoder)EncodeProtoJSON implements Message.
Any.MarshalJSON
Section titled “Any.MarshalJSON”func (x *Any) MarshalJSON() ([]byte, error)MarshalJSON implements json.Marshaler.
Any.UnmarshalJSON
Section titled “Any.UnmarshalJSON”func (x *Any) UnmarshalJSON(b []byte) errorUnmarshalJSON implements json.Unmarshaler.
Any.UnmarshalTo
Section titled “Any.UnmarshalTo”func (x *Any) UnmarshalTo(m Message) errorUnmarshalTo decodes the embedded message into m.
type Decoder
Section titled “type Decoder”type Decoder struct {}Decoder walks parsed JSON for generated code. The first error is kept and later reads return zero values.
Decoder.Array
Section titled “Decoder.Array”func (d *Decoder) Array(v jsonvalue.Value, field string) boolArray reports whether v is an array, failing otherwise.
Decoder.Bool
Section titled “Decoder.Bool”func (d *Decoder) Bool(v jsonvalue.Value, field string) boolBool decodes a bool field.
Decoder.Bytes
Section titled “Decoder.Bytes”func (d *Decoder) Bytes(v jsonvalue.Value, field string) []byteBytes decodes a bytes field from standard or URL-safe base64, with or without padding.
Decoder.Duplicate
Section titled “Decoder.Duplicate”func (d *Decoder) Duplicate(name string)Duplicate fails because a field appeared under both of its names.
Decoder.Enum
Section titled “Decoder.Enum”func (d *Decoder) Enum(v jsonvalue.Value, field string, values map[string]int32) (n int32, ok bool)Enum decodes an enum field from its value name or number. ok is false for an unknown name, which proto3 JSON with DiscardUnknown ignores.
Decoder.Err
Section titled “Decoder.Err”func (d *Decoder) Err() errorErr returns the first decoding error.
Decoder.Fail
Section titled “Decoder.Fail”func (d *Decoder) Fail(msg string)Fail records msg as the decoding error unless one is already set.
Decoder.Float32
Section titled “Decoder.Float32”func (d *Decoder) Float32(v jsonvalue.Value, field string) float32Float32 decodes a float field.
Decoder.Float64
Section titled “Decoder.Float64”func (d *Decoder) Float64(v jsonvalue.Value, field string) float64Float64 decodes a double field.
Decoder.Int32
Section titled “Decoder.Int32”func (d *Decoder) Int32(v jsonvalue.Value, field string) int32Int32 decodes an int32, sint32 or sfixed32 field from a number or string.
Decoder.Int64
Section titled “Decoder.Int64”func (d *Decoder) Int64(v jsonvalue.Value, field string) int64Int64 decodes an int64, sint64 or sfixed64 field from a number or string.
Decoder.ListValue
Section titled “Decoder.ListValue”func (d *Decoder) ListValue(v jsonvalue.Value, field string) jsonvalue.ValueListValue decodes a google.protobuf.ListValue field.
Decoder.MapKeyBool
Section titled “Decoder.MapKeyBool”func (d *Decoder) MapKeyBool(key string, field string) boolMapKeyBool decodes a bool map key.
Decoder.MapKeyInt64
Section titled “Decoder.MapKeyInt64”func (d *Decoder) MapKeyInt64(key string, bitSize int, field string) int64MapKeyInt64 decodes a signed integer map key.
Decoder.MapKeyUint64
Section titled “Decoder.MapKeyUint64”func (d *Decoder) MapKeyUint64(key string, bitSize int, field string) uint64MapKeyUint64 decodes an unsigned integer map key.
Decoder.NullElement
Section titled “Decoder.NullElement”func (d *Decoder) NullElement(field string)NullElement fails on a null list element or map value of a non-Value type.
Decoder.Object
Section titled “Decoder.Object”func (d *Decoder) Object(v jsonvalue.Value, message string) boolObject reports whether v is an object, failing otherwise.
Decoder.OneofSet
Section titled “Decoder.OneofSet”func (d *Decoder) OneofSet(name, oneof string)OneofSet fails because a second member of the same oneof appeared.
Decoder.String
Section titled “Decoder.String”func (d *Decoder) String(v jsonvalue.Value, field string) stringString decodes a string field.
Decoder.Struct
Section titled “Decoder.Struct”func (d *Decoder) Struct(v jsonvalue.Value, field string) jsonvalue.ValueStruct decodes a google.protobuf.Struct field.
Decoder.Uint32
Section titled “Decoder.Uint32”func (d *Decoder) Uint32(v jsonvalue.Value, field string) uint32Uint32 decodes a uint32 or fixed32 field from a number or string.
Decoder.Uint64
Section titled “Decoder.Uint64”func (d *Decoder) Uint64(v jsonvalue.Value, field string) uint64Uint64 decodes a uint64 or fixed64 field from a number or string.
Decoder.Value
Section titled “Decoder.Value”func (d *Decoder) Value(v jsonvalue.Value, field string) jsonvalue.ValueValue decodes a google.protobuf.Value field; JSON null is a set value.
type Duration
Section titled “type Duration”type Duration struct { Seconds int64 Nanos int32}Duration is google.protobuf.Duration, encoded as decimal seconds with an “s” suffix.
DurationOf
Section titled “DurationOf”func DurationOf(d time.Duration) *DurationDurationOf returns the Duration for d.
Duration.AsDuration
Section titled “Duration.AsDuration”func (x *Duration) AsDuration() time.DurationAsDuration returns the span as a time.Duration, saturating on overflow.
Duration.DecodeProtoJSON
Section titled “Duration.DecodeProtoJSON”func (x *Duration) DecodeProtoJSON(d *Decoder, v jsonvalue.Value)DecodeProtoJSON implements Message.
Duration.EncodeProtoJSON
Section titled “Duration.EncodeProtoJSON”func (x *Duration) EncodeProtoJSON(e *Encoder)EncodeProtoJSON implements Message.
Duration.MarshalJSON
Section titled “Duration.MarshalJSON”func (x *Duration) MarshalJSON() ([]byte, error)MarshalJSON implements json.Marshaler.
Duration.UnmarshalJSON
Section titled “Duration.UnmarshalJSON”func (x *Duration) UnmarshalJSON(b []byte) errorUnmarshalJSON implements json.Unmarshaler.
type Empty
Section titled “type Empty”type Empty struct {}Empty is google.protobuf.Empty, encoded as {}.
Empty.DecodeProtoJSON
Section titled “Empty.DecodeProtoJSON”func (x *Empty) DecodeProtoJSON(d *Decoder, v jsonvalue.Value)DecodeProtoJSON implements Message.
Empty.EncodeProtoJSON
Section titled “Empty.EncodeProtoJSON”func (x *Empty) EncodeProtoJSON(e *Encoder)EncodeProtoJSON implements Message.
Empty.MarshalJSON
Section titled “Empty.MarshalJSON”func (x *Empty) MarshalJSON() ([]byte, error)MarshalJSON implements json.Marshaler.
Empty.UnmarshalJSON
Section titled “Empty.UnmarshalJSON”func (x *Empty) UnmarshalJSON(b []byte) errorUnmarshalJSON implements json.Unmarshaler.
type Encoder
Section titled “type Encoder”type Encoder struct {}Encoder accumulates one JSON document. Generated code drives it; the first error is kept and later writes are ignored.
Encoder.BeginArray
Section titled “Encoder.BeginArray”func (e *Encoder) BeginArray()BeginArray starts a JSON array value.
Encoder.BeginObject
Section titled “Encoder.BeginObject”func (e *Encoder) BeginObject()BeginObject starts a JSON object value.
Encoder.Bool
Section titled “Encoder.Bool”func (e *Encoder) Bool(b bool)Bool writes b.
Encoder.Bytes
Section titled “Encoder.Bytes”func (e *Encoder) Bytes(b []byte)Bytes writes b as padded standard base64.
Encoder.EndArray
Section titled “Encoder.EndArray”func (e *Encoder) EndArray()EndArray closes the innermost array.
Encoder.EndObject
Section titled “Encoder.EndObject”func (e *Encoder) EndObject()EndObject closes the innermost object.
Encoder.Enum
Section titled “Encoder.Enum”func (e *Encoder) Enum(n int32, name string)Enum writes name, or n when the value has no name.
Encoder.Err
Section titled “Encoder.Err”func (e *Encoder) Err() errorErr returns the first encoding error.
Encoder.Fail
Section titled “Encoder.Fail”func (e *Encoder) Fail(msg string)Fail records msg as the encoding error unless one is already set.
Encoder.Float32
Section titled “Encoder.Float32”func (e *Encoder) Float32(f float32)Float32 writes f as a JSON number, or “NaN”, “Infinity” or “-Infinity”.
Encoder.Float64
Section titled “Encoder.Float64”func (e *Encoder) Float64(f float64)Float64 writes f as a JSON number, or “NaN”, “Infinity” or “-Infinity”.
Encoder.Int32
Section titled “Encoder.Int32”func (e *Encoder) Int32(n int32)Int32 writes n as a JSON number.
Encoder.Int64
Section titled “Encoder.Int64”func (e *Encoder) Int64(n int64)Int64 writes n as a JSON string.
Encoder.Key
Section titled “Encoder.Key”func (e *Encoder) Key(name string)Key writes an object member name; the member’s value follows.
Encoder.ListValue
Section titled “Encoder.ListValue”func (e *Encoder) ListValue(v jsonvalue.Value)ListValue writes v, which must be an array, as google.protobuf.ListValue.
Encoder.Message
Section titled “Encoder.Message”func (e *Encoder) Message(m Message)Message writes m, or {} when m is nil.
Encoder.Null
Section titled “Encoder.Null”func (e *Encoder) Null()Null writes null.
Encoder.String
Section titled “Encoder.String”func (e *Encoder) String(s string)String writes s, which must be valid UTF-8.
Encoder.Struct
Section titled “Encoder.Struct”func (e *Encoder) Struct(v jsonvalue.Value)Struct writes v, which must be an object, as google.protobuf.Struct.
Encoder.Uint32
Section titled “Encoder.Uint32”func (e *Encoder) Uint32(n uint32)Uint32 writes n as a JSON number.
Encoder.Uint64
Section titled “Encoder.Uint64”func (e *Encoder) Uint64(n uint64)Uint64 writes n as a JSON string.
Encoder.Value
Section titled “Encoder.Value”func (e *Encoder) Value(v jsonvalue.Value)Value writes v as google.protobuf.Value: objects as Structs with sorted keys and numbers as doubles.
type Error
Section titled “type Error”type Error struct { Msg string}Error describes an invalid value found while encoding or decoding.
Error.Error
Section titled “Error.Error”func (e *Error) Error() stringtype FieldMask
Section titled “type FieldMask”type FieldMask struct { Paths []string}FieldMask is google.protobuf.FieldMask, encoded as comma-separated lowerCamelCase paths.
FieldMask.DecodeProtoJSON
Section titled “FieldMask.DecodeProtoJSON”func (x *FieldMask) DecodeProtoJSON(d *Decoder, v jsonvalue.Value)DecodeProtoJSON implements Message.
FieldMask.EncodeProtoJSON
Section titled “FieldMask.EncodeProtoJSON”func (x *FieldMask) EncodeProtoJSON(e *Encoder)EncodeProtoJSON implements Message.
FieldMask.MarshalJSON
Section titled “FieldMask.MarshalJSON”func (x *FieldMask) MarshalJSON() ([]byte, error)MarshalJSON implements json.Marshaler.
FieldMask.UnmarshalJSON
Section titled “FieldMask.UnmarshalJSON”func (x *FieldMask) UnmarshalJSON(b []byte) errorUnmarshalJSON implements json.Unmarshaler.
type Message
Section titled “type Message”type Message interface { EncodeProtoJSON(e *Encoder) DecodeProtoJSON(d *Decoder, v jsonvalue.Value)}Message is implemented by generated messages and the well-known types.
type NullValue
Section titled “type NullValue”type NullValue int32NullValue is google.protobuf.NullValue, encoded as null.
const NullValue_NULL_VALUE NullValue = 0NullValue_NULL_VALUE is the only NullValue.
type Timestamp
Section titled “type Timestamp”type Timestamp struct { Seconds int64 Nanos int32}Timestamp is google.protobuf.Timestamp, encoded as an RFC 3339 string.
TimestampOf
Section titled “TimestampOf”func TimestampOf(t time.Time) *TimestampTimestampOf returns the Timestamp for t.
Timestamp.AsTime
Section titled “Timestamp.AsTime”func (t *Timestamp) AsTime() time.TimeAsTime returns the instant as a UTC time.Time.
Timestamp.DecodeProtoJSON
Section titled “Timestamp.DecodeProtoJSON”func (t *Timestamp) DecodeProtoJSON(d *Decoder, v jsonvalue.Value)DecodeProtoJSON implements Message.
Timestamp.EncodeProtoJSON
Section titled “Timestamp.EncodeProtoJSON”func (t *Timestamp) EncodeProtoJSON(e *Encoder)EncodeProtoJSON implements Message.
Timestamp.MarshalJSON
Section titled “Timestamp.MarshalJSON”func (t *Timestamp) MarshalJSON() ([]byte, error)MarshalJSON implements json.Marshaler.
Timestamp.UnmarshalJSON
Section titled “Timestamp.UnmarshalJSON”func (t *Timestamp) UnmarshalJSON(b []byte) errorUnmarshalJSON implements json.Unmarshaler.