simpleoneof

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnexpectedType is returned if we got
	// type we can't handle
	ErrUnexpectedType = errors.New("unexpected type in structure")

	// ErrUnexpectedFieldInNestedStruct returned when the nested
	// struct has unexpected fields (other than string,list and dict)
	ErrUnexpectedFieldInNestedStruct = errors.New("unexpected field in nested struct")

	// ErrFailedToDecodeRequest returned when we can't
	// decode request data into proto.Message
	ErrFailedToDecodeRequest = errors.New("failed to decode request data")
)

Functions

func AddEncodingHeader

func AddEncodingHeader(ctx context.Context, rw http.ResponseWriter, msg proto.Message) error

AddEncodingHeader adds application/json; charset=utf-8 to response headers

Types

type Marshaler

type Marshaler struct {
	SingleTypes []reflect.Type
	NestedTypes []reflect.Type
	// contains filtered or unexported fields
}

Marshaler marshals proto3 oneof into flat json structures

func NewFlatMarshaler

func NewFlatMarshaler(
	singleTypes []reflect.Type,
	nestedTypes []reflect.Type,
) *Marshaler

NewFlatMarshaler creates marshaler

func NewFlatMarshalerForAssetsV2

func NewFlatMarshalerForAssetsV2(
	singleTypes []reflect.Type,
	nestedTypes []reflect.Type,
	ignoreFields []string,
) *Marshaler

NewFlatMarshalerForAssetsV2 creates marshaler for assetsv2

func NewFlatMarshalerForLocations

func NewFlatMarshalerForLocations(
	singleTypes []reflect.Type,
	nestedTypes []reflect.Type,
) *Marshaler

NewFlatMarshalerForLocations creates marshaler

func (*Marshaler) ContentType

func (m *Marshaler) ContentType(pb any) string

ContentType returns `application/json` content type.

This is because the Marshaler encodes our proto messages

as json.

func (*Marshaler) Marshal

func (m *Marshaler) Marshal(v any) ([]byte, error)

Marshal marshal v into json bytes

func (*Marshaler) NewDecoder

func (m *Marshaler) NewDecoder(r io.Reader) runtime.Decoder

NewDecoder create new WrappedDecoder

func (*Marshaler) NewEncoder

func (m *Marshaler) NewEncoder(w io.Writer) runtime.Encoder

NewEncoder get underlying proto encoder

func (*Marshaler) Unmarshal

func (m *Marshaler) Unmarshal(data []byte, v any) error

Unmarshal unmarshal json data into v

type SnakeMarshaler

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

func NewSnakeMarshaler

func NewSnakeMarshaler() *SnakeMarshaler

func (*SnakeMarshaler) ContentType

func (*SnakeMarshaler) ContentType(_ any) string

ContentType for a SnakeMarshaler is `application/octet-stream` because

the SnakeMarshaler encodes a protobuf message into json, in the format
of a byte slice.

func (*SnakeMarshaler) Marshal

func (s *SnakeMarshaler) Marshal(value any) ([]byte, error)

func (*SnakeMarshaler) NewDecoder

func (s *SnakeMarshaler) NewDecoder(reader io.Reader) runtime.Decoder

NewDecoder returns a Decoder which reads proto stream from "reader".

func (*SnakeMarshaler) NewEncoder

func (s *SnakeMarshaler) NewEncoder(writer io.Writer) runtime.Encoder

NewEncoder returns an Encoder which writes proto stream into "writer".

func (*SnakeMarshaler) Unmarshal

func (s *SnakeMarshaler) Unmarshal(data []byte, value any) error

type WrappedDecoder

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

WrappedDecoder decoder wrapping json with custom logic handling oneofs

func (*WrappedDecoder) Decode

func (m *WrappedDecoder) Decode(obj any) error

Decode bytes into obj

Jump to

Keyboard shortcuts

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