zfmt

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2024 License: Apache-2.0 Imports: 16 Imported by: 7

README

zfmt

License GitHub Actions Codecov

Installation

go get -u github.com/zillow/zfmt

Note that zap only supports the two most recent minor versions of Go.

About

Note that zap only supports the two most recent minor versions of Go. A module which defines several concrete Formatter types responsible for serializing/deserializing objects. The module centralizes this functionality and is leveraged by several zillow transport libs for use in configuration driven serialization.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AvroFormatter

type AvroFormatter struct{}

func (*AvroFormatter) Marshall

func (p *AvroFormatter) Marshall(v any) ([]byte, error)

func (*AvroFormatter) Unmarshal

func (p *AvroFormatter) Unmarshal(b []byte, v any) error

type Formatter

type Formatter interface {
	Marshall(v any) ([]byte, error)
	Unmarshal(data []byte, v any) error
}

Formatter allows the user to extend formatting capability to unsupported data types

func GetFormatter

func GetFormatter(fmt FormatterType, schemaID int) (Formatter, error)

GetFormatter returns supported formatter from its name

type FormatterType

type FormatterType string

FormatterType defines a formatter

const (
	// JSONFmt indicates json formatter
	JSONFmt FormatterType = "json"
	// ProtoRawFmt indicates protocol buffer formatter. Does not Base64 encode/decode.
	ProtoRawFmt FormatterType = "proto_raw"
	// ProtoBase64Fmt indicates protocol buffer formatter. Base64 encodes/decodes the message. Only intended for use with SQS.
	ProtoBase64Fmt FormatterType = "proto_base64"
	// ProtoJSONFmt indicates usage protojson formatter (which should be used for json formatted proto messages).
	ProtoJSONFmt FormatterType = "proto_json"
	// StringFmt indicates string formatter
	StringFmt FormatterType = "string"
	// AvroFmt indicates apache avro formatter
	AvroFmt FormatterType = "avro"
	// AvroSchemaFmt indicates apache avro formatter with schemaID encoded
	AvroSchemaFmt FormatterType = "avro_schema"
	// JSONSchemaFmt indicates json formatter with schemaID encoded
	JSONSchemaFmt FormatterType = "json_schema"
	// ProtoSchemaDeprecatedFmt indicates proto formatter with schemaID encoded - deprecated because it doesn't work properly.
	ProtoSchemaDeprecatedFmt FormatterType = "proto_schema_deprecated"
)

type GeneratedAvroRecord

type GeneratedAvroRecord interface {
	soe.AvroRecord
	types.Field
	Schema() string
}

GeneratedAvroRecord combines interfaces that make Encoding/Decoding possible for gogen-avro struct

type JSONFormatter

type JSONFormatter struct{}

JSONFormatter encodes/decodes go struct to json format

func (*JSONFormatter) Marshall

func (j *JSONFormatter) Marshall(v any) ([]byte, error)

func (*JSONFormatter) Unmarshal

func (j *JSONFormatter) Unmarshal(b []byte, v any) error

type ProtoJSONFormatter

type ProtoJSONFormatter struct{}

ProtoJSONFormatter encodes/decodes proto go struct to json format

func (*ProtoJSONFormatter) Marshall

func (j *ProtoJSONFormatter) Marshall(v any) ([]byte, error)

func (*ProtoJSONFormatter) Unmarshal

func (j *ProtoJSONFormatter) Unmarshal(b []byte, v any) error

type ProtobufBase64Formatter

type ProtobufBase64Formatter struct{}

ProtobufBase64Formatter implements formatter interface for both protobuf v1 and v2 messages. Intended for use with SQS

func (*ProtobufBase64Formatter) Marshall

func (p *ProtobufBase64Formatter) Marshall(v any) ([]byte, error)

Marshall as proto and then base64 encode (useful for technologies like SQS which limit the character set)

func (*ProtobufBase64Formatter) Unmarshal

func (p *ProtobufBase64Formatter) Unmarshal(b []byte, v any) error

Unmarshal with base64 decoding

type ProtobufRawFormatter

type ProtobufRawFormatter struct{}

ProtobufRawFormatter implements formatter interface for both protobuf v1 and v2 messages. Does not base64 encode.

func (*ProtobufRawFormatter) Marshall

func (p *ProtobufRawFormatter) Marshall(v any) ([]byte, error)

Marshall encodes the data as a proto binary

func (*ProtobufRawFormatter) Unmarshal

func (p *ProtobufRawFormatter) Unmarshal(b []byte, v any) error

Unmarshal accepts proto binary and hydrates a proto generated struct

type SchematizedAvroFormatter

type SchematizedAvroFormatter struct {
	SchemaID int
	// contains filtered or unexported fields
}

SchematizedAvroFormatter follows the Confluent Wire Format https://docs.confluent.io/current/schema-registry/serdes-develop/index.html#wire-format

func (*SchematizedAvroFormatter) Marshall

func (p *SchematizedAvroFormatter) Marshall(v any) ([]byte, error)

Marshall converts input into avro binary data with schema ID attached

func (*SchematizedAvroFormatter) Unmarshal

func (p *SchematizedAvroFormatter) Unmarshal(b []byte, v any) error

Unmarshal fills avro binary data into provided interface v and validates the schema ID

type SchematizedJSONFormatter

type SchematizedJSONFormatter struct {
	SchemaID int
	// contains filtered or unexported fields
}

SchematizedJSONFormatter follows the Confluent Wire Format https://docs.confluent.io/current/schema-registry/serdes-develop/index.html#wire-format

func (*SchematizedJSONFormatter) Marshall

func (p *SchematizedJSONFormatter) Marshall(v any) ([]byte, error)

Marshall converts input into avro binary data with schema ID attached

func (*SchematizedJSONFormatter) Unmarshal

func (p *SchematizedJSONFormatter) Unmarshal(b []byte, v any) error

Unmarshal fills avro binary data into provided interface v and validates the schema ID

type SchematizedProtoFormatterDeprecated

type SchematizedProtoFormatterDeprecated struct {
	SchemaID int
	// contains filtered or unexported fields
}

SchematizedProtoFormatterDeprecated follows the Confluent Wire Format https://docs.confluent.io/current/schema-registry/serdes-develop/index.html#wire-format

func (*SchematizedProtoFormatterDeprecated) Marshall

func (p *SchematizedProtoFormatterDeprecated) Marshall(v any) ([]byte, error)

Marshall converts input into avro binary data with schema ID attached

func (*SchematizedProtoFormatterDeprecated) Unmarshal

func (p *SchematizedProtoFormatterDeprecated) Unmarshal(b []byte, v any) error

Unmarshal fills avro binary data into provided interface v and validates the schema ID

type StringFormatter

type StringFormatter struct{}

StringFormatter ...

func (*StringFormatter) Marshall

func (f *StringFormatter) Marshall(i any) ([]byte, error)

Marshall ...

func (*StringFormatter) Unmarshal

func (f *StringFormatter) Unmarshal(b []byte, i any) error

Directories

Path Synopsis
avro module
internal module
json module
proto module

Jump to

Keyboard shortcuts

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