canonicalizer

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Canonicalize

func Canonicalize(obj interface{}, opts ...Option) ([]byte, error)

Canonicalize returns hash-format representation of the data structure. Use the opts parameter for applying additional serialization options.

Nested types must implement Canonicalizer interface.

The implementation makes use of struct tags with the key 'hsh' as serialization template. Available options:

  • 'idx' [mandatory]: binary serialization sequence for given field.
  • 'size' [optional] : integer value size expressed in bytes. Supported values 1, 4, 8. If not set 1 is used as default.

e.g.

 type Object struct {
	    Number uint64 `hsh:"idx=1,size=8"`
	    Slice  []byte `hsh:"idx=2"`
 }

func RegisterTemplate

func RegisterTemplate(o interface{})

Types

type Canonicalizer

type Canonicalizer interface {
	Canonicalize() ([]byte, error)
}

Canonicalizer Interface for serializing data structures into deterministic hash-format.

type Option

type Option func(*serializeOptions) error

Option represent serialization optional parameters.

func OptionExcludeField

func OptionExcludeField(name string) Option

OptionExcludeField provides the ability for excluding fields from serialization.

Jump to

Keyboard shortcuts

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