any

package module
v0.0.0-...-0b3abbb Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2020 License: MIT Imports: 11 Imported by: 0

README

any Godoc

A Go module for a Queue (FIFO) of any structure. The Queue uses a []byte as it's buffer, so it's easy to send the queue across a wire, or store it anywhere handy (file, RDBMS, Redis, basically anywhere you can store bytes).

If you add a struct that's a proto.Message, then it's marshaled as a proto.Message, otherwise it's marshaled as JSON.

Installation

Standard go get:

go get github.com/jimlambrt/any

Usage

see:

// make a queue of anything
queue := any.Queue{Catalog: types}

// add anything
queue.Add(&user, &car, &rental)

// remove anything
queuedUser, err := queue.Remove()

Why?

Sometimes it's nice to be able to serialize anything into a queue that's buffered by a []byte

Documentation

Index

Constants

This section is empty.

Variables

Functions

func GetTypeName

func GetTypeName(i interface{}) (string, error)

GetTypeName returns the interfaces name

Types

type Any

type Any struct {
	IsPb     bool     `protobuf:"varint,3,opt,name=is_pb,json=isPb,proto3" json:"is_pb,omitempty"`
	Anything *any.Any `protobuf:"bytes,4,opt,name=anything,proto3" json:"anything,omitempty"`
	// contains filtered or unexported fields
}

func (*Any) Descriptor deprecated

func (*Any) Descriptor() ([]byte, []int)

Deprecated: Use Any.ProtoReflect.Descriptor instead.

func (*Any) GetAnything

func (x *Any) GetAnything() *any.Any

func (*Any) GetIsPb

func (x *Any) GetIsPb() bool

func (*Any) ProtoMessage

func (*Any) ProtoMessage()

func (*Any) ProtoReflect

func (x *Any) ProtoReflect() protoreflect.Message

func (*Any) Reset

func (x *Any) Reset()

func (*Any) String

func (x *Any) String() string

type Queue

type Queue struct {
	// QueueBuffer provides a buffer for the queue
	QueueBuffer
	// Catalog provides a catalog of types for the queue
	Catalog *TypeCatalog
	// contains filtered or unexported fields
}

Queue provides a FIFO queue which is concurrent safe

func (*Queue) Add

func (r *Queue) Add(things ...interface{}) error

Add something to the queue

func (*Queue) Remove

func (r *Queue) Remove() (interface{}, error)

Remove (FIFO) something from the queue and EOF if empty

type QueueBuffer

type QueueBuffer []byte

QueueBuffer will be used to buffer a queue

func (*QueueBuffer) Len

func (b *QueueBuffer) Len() int

Len returns the length of the buffer

func (*QueueBuffer) Next

func (b *QueueBuffer) Next(n int) []byte

Next returns the next n bytes from the buffer

func (*QueueBuffer) Read

func (b *QueueBuffer) Read(p []byte) (int, error)

Read reads the next len(p) bytes from the buffer or until the buffer is empty. It satisfies io.Reader

func (*QueueBuffer) Write

func (b *QueueBuffer) Write(p []byte) (int, error)

Write prepends the contents of p to the buffer and satisfies io.Writer

type TypeCatalog

type TypeCatalog map[string]reflect.Type

TypeCatalog is an abstraction for dealing with oplog data and their underlying types

func NewTypeCatalog

func NewTypeCatalog(withTypes ...interface{}) (*TypeCatalog, error)

NewTypeCatalog creates a catalog with the types you pass in

func (TypeCatalog) Get

func (t TypeCatalog) Get(name string) (interface{}, error)

Get retrieves the interface via a name

func (TypeCatalog) Set

func (t TypeCatalog) Set(i interface{}) error

Set creates an entry in the catalog for the interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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