reg

package
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: Unlicense Imports: 7 Imported by: 0

Documentation

Overview

Package reg is a registry for message types that implement the coding.Codec interface.

It is essentially a factory for messages, each registered message type has a function that returns a codec.Codec interface type containing the concrete type specified by the magic bytes.

It can either be used to manually generate a type as in the factory model, or is used as a recogniser, accepting a splice.Splice and returning the concrete type indicated by the magic prefix of the splice.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeCodec

func MakeCodec(magic string) (cdc codec.Codec)

MakeCodec is a simple function to find a Codec factory function and return its output.

func Recognise

func Recognise(s *splice.Splice) (cdc codec.Codec)

Recognise selects a factory function and steps the cursor forward after the Magic to be ready to call the Decode method on the Codec inside.

func Register

func Register(magicString string, cdc func() codec.Codec)

Register adds a new factory constructor function associated with a provided Magic bytes.

Types

type CodecGenerators

type CodecGenerators map[string]func() codec.Codec

CodecGenerators is the map of generators that have been registered.

Jump to

Keyboard shortcuts

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