dvs

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: MIT Imports: 3 Imported by: 0

README

mus-stream-dvs-go

mus-stream-dvs-go provides data versioning support for the mus-stream-go serializer. With mus-stream-dvs-go we can do 2 things:

  1. Marshal the current data version as if it was an old version.
  2. Unmarshal the old data version as if it was the current version.

It completely repeats the structure of mus-dvs-go, and differs only in that it uses Writer, Reader interfaces rather than а slice of bytes.

Tests

Test coverage is 100%.

How To Use

You can learn more about this in the mus-dvs-go documentation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DVS

type DVS[V any] struct {
	// contains filtered or unexported fields
}

DVS provides versioning support for the mus-stream-go serializer.

func New

func New[V any](reg com.Registry) DVS[V]

New creates a new DVS.

func (DVS[V]) Marshal added in v0.4.0

func (dvs DVS[V]) Marshal(dtm com.DTM, v V, w muss.Writer) (n int,
	err error)

Marshal migrates v to the version specified by dtm and then writes dtm + resulting v version encoding.

Returns the number of written bytes and one of the ErrUnknownDTM, ErrWrongTypeVersion or Writer errors.

func (DVS[V]) Unmarshal added in v0.4.0

func (dvs DVS[V]) Unmarshal(r muss.Reader) (dtm com.DTM, v V, n int,
	err error)

Unmarshal unmarshals dtm + data, and then migrates data to the version specified by dtm.

Returns the number of read bytes and one of the ErrUnknownDTM, ErrWrongTypeVersion or Reader errors.

type MigrationVersion

type MigrationVersion[V any] interface {
	MigrateCurrentAndMarshal(v V, w muss.Writer) (n int, err error)
	UnmarshalAndMigrateOld(r muss.Reader) (v V, n int, err error)
}

MigrationVersion represents a generic type version for Registry that can be migrated.

It contains methods to support all mus-stream-dvs-go functionality.

type Version

type Version[T any, V any] struct {
	DTS            dts.DTS[T]
	MigrateOld     com.MigrateOld[T, V]
	MigrateCurrent com.MigrateCurrent[V, T]
}

Version is an implementation of the MigrationVersion interface.

func (Version[T, V]) MigrateCurrentAndMarshal added in v0.4.0

func (ver Version[T, V]) MigrateCurrentAndMarshal(v V, w muss.Writer) (n int,
	err error)

func (Version[T, V]) UnmarshalAndMigrateOld added in v0.4.0

func (ver Version[T, V]) UnmarshalAndMigrateOld(r muss.Reader) (v V, n int,
	err error)

Jump to

Keyboard shortcuts

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