jsoncodec

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package jsoncodec provides some helpful wrappers and a core Codec implementation to make using JSON payloads easy within systems using Galaxycache.

In general, it is recommended to use the github.com/vimeo/galaxycache/protocodec.CodecV2 codec if at all possible, as protobuf generally provides lower overhead in both space and proccessing-time, schemas that can evolve, and the ability to rename fields as necessary.

This package should *_not_* be used for caching protobuf message-types, it is *_always_* better to use binary marshaling with github.com/vimeo/galaxycache/protocodec.CodecV2 in that case.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackendGetter

func BackendGetter[T any](f func(ctx context.Context, key string) (T, error)) galaxycache.BackendGetter

BackendGetter is an adapter that implements galaxycache.BackendGetter (it wraps an unexported type because type-inference is much better on function-calls)

func GalaxyGet

func GalaxyGet[T any](ctx context.Context, g *galaxycache.Galaxy, key string) (m *T, getErr error)

GalaxyGet is a simple wrapper around a Galaxy.Get method-call that takes care of constructing the Codec, etc. (making the interface more idiomatic for Go)

Types

type Codec

type Codec[T any] struct {
	// contains filtered or unexported fields
}

Codec wraps another type, providing a simple wrapper for clients that want to wrap JSON.

Note: protocodec should generally be prefered for new deployments. This implementation is provided to provide an easy way to insert Galaxycache into systems that are already using JSON internally for the payloads they'll be working with.

func (*Codec[T]) Get

func (c *Codec[T]) Get() *T

Get implies returns the internal protobuf message value

func (*Codec[T]) MarshalBinary

func (c *Codec[T]) MarshalBinary() ([]byte, error)

MarshalBinary on a ProtoCodec returns the encoded proto message

func (*Codec[T]) Set

func (c *Codec[T]) Set(v T)

Set bypasses Marshaling and lets you set the internal protobuf value

func (*Codec[T]) UnmarshalBinary

func (c *Codec[T]) UnmarshalBinary(data []byte) error

UnmarshalBinary on a ProtoCodec unmarshals provided data into the proto message

Jump to

Keyboard shortcuts

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