encoder

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EncoderInterface

type EncoderInterface interface {
	Encode(msg interface{}) ([]byte, error)
}

EncoderInterface is an interface each Encoder will have to abide to it will be used by the publisher/producer object to marshal payloads check defualt implementation of JSONEncoder for more info Example for protobuf:

import "google.golang.org/protobuf/proto"

type ProtoEncoder struct{}

func (e *ProtoEncoder) Encode(msg interface{}) ([]byte, error) {
	return proto.Marshal(msg)
}

func NewProtoEncoder() EncoderInterface {
	return &ProtoEncoder{}
}

func NewJSONEncoder

func NewJSONEncoder() EncoderInterface

NewJSONEncoder returns an object implementing EncoderInterface

type JSONEncoder

type JSONEncoder struct{}

JSONEncoder is the default encoder for publihsers/producers it implements the EncoderInterface and simply marshals an interface to json

func (*JSONEncoder) Encode

func (e *JSONEncoder) Encode(msg interface{}) ([]byte, error)

Encode is the only method, needs to return ([]byte, error), in this case simply a wrapper around the json.Marshal funcrton

Jump to

Keyboard shortcuts

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