protoenc

package module
v0.0.0-...-8a8b08d Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: MIT Imports: 8 Imported by: 0

README

protoenc

Protobuf encoder for serializing messages in a format compatible with the Confluent wire format.

Usage

// First you construct encoder which would register schema for the message (you can pass empty message)
enc, err := protoenc.NewEncoder(context.Background(), client, subject, (*test.Test)(nil))
...
// Then to serialize message you call Marshal method
bytes, err := enc.Marshal(&test.Test{Id: "1234"})

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrWrongMessage is returned when Marshal/MarshalAppend receive
	// a message different from one in the constructor.
	ErrWrongMessage = errors.New("unexpected message type")
)

Functions

This section is empty.

Types

type Encoder

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

func NewEncoder

func NewEncoder(ctx context.Context, client SchemaRegistryClient, subject string, msg proto.Message) (*Encoder, error)

func (*Encoder) Marshal

func (e *Encoder) Marshal(msg proto.Message) ([]byte, error)

Marshal returns the confluent wire-format encoding of msg. See https://docs.confluent.io/cloud/current/sr/fundamentals/serdes-develop/index.html#wire-format for details.

func (*Encoder) MarshalAppend

func (e *Encoder) MarshalAppend(b []byte, msg proto.Message) ([]byte, error)

MarshalAppend appends the confluent wire-format encoding of msg with stored recordID and index to b, returning the result. See https://docs.confluent.io/cloud/current/sr/fundamentals/serdes-develop/index.html#wire-format for details.

type SchemaRegistryClient

type SchemaRegistryClient interface {
	CreateSchema(ctx context.Context, subject string, s sr.Schema) (sr.SubjectSchema, error)
}

Directories

Path Synopsis
internal
mock
Code generated by MockGen.
Code generated by MockGen.

Jump to

Keyboard shortcuts

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