msgpackrecordserializer

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2021 License: BSD-3-Clause Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrorEOF = errors.New("EOF")

ErrorEOF defines an end of file error.

Functions

func MarshalRecord

func MarshalRecord(record *rangedb.Record) ([]byte, error)

MarshalRecord encodes a Record as msgpack.

The record, excluding data, is encoded first. Then, event data is encoded. Encoding the event data second allows decoding to parse into a struct if defined.

func New

func New() *msgpackSerializer

New constructs a msgpackSerializer.

Example (DeserializeWithBoundEvent)
package main

import (
	"fmt"

	"github.com/inklabs/rangedb/provider/msgpackrecordserializer"
	"github.com/inklabs/rangedb/rangedbtest"
)

func main() {
	// Given
	serializer := msgpackrecordserializer.New()
	serializer.Bind(rangedbtest.ThingWasDone{})
	input := "\x89\xa1a\xa5thing\xa1i\xd9 60f01cc527844cde9953c998a2c077a7\xa1g\xcf\x00\x00\x00\x00\x00\x00\x00d\xa1s\xcf\x00\x00\x00\x00\x00\x00\x00\x02\xa1u\xcf\x00\x00\x00\x00]\xfdwۡe\xa0\xa1t\xacThingWasDone\xa1d\xc0\xa1m\xc0\x82\xa2id\xa1A\xa6number\xd3\x00\x00\x00\x00\x00\x00\x00\x01"

	// When
	record, _ := serializer.Deserialize([]byte(input))
	fmt.Printf("%#v\n", record.Data)

}
Output:
&rangedbtest.ThingWasDone{ID:"A", Number:1}
Example (DeserializeWithUnboundEvent)
package main

import (
	"fmt"

	"github.com/inklabs/rangedb/provider/msgpackrecordserializer"
)

func main() {
	// Given
	serializer := msgpackrecordserializer.New()
	input := "\x89\xa1a\xa5thing\xa1i\xd9 60f01cc527844cde9953c998a2c077a7\xa1g\xcf\x00\x00\x00\x00\x00\x00\x00d\xa1s\xcf\x00\x00\x00\x00\x00\x00\x00\x02\xa1u\xcf\x00\x00\x00\x00]\xfdwۡe\xa0\xa1t\xacThingWasDone\xa1d\xc0\xa1m\xc0\x82\xa2id\xa1A\xa6number\xd3\x00\x00\x00\x00\x00\x00\x00\x01"

	// When
	record, _ := serializer.Deserialize([]byte(input))
	fmt.Printf("%#v\n", record.Data)

}
Output:
map[string]interface {}{"id":"A", "number":1}
Example (Serialize)
package main

import (
	"fmt"

	"github.com/inklabs/rangedb"
	"github.com/inklabs/rangedb/provider/msgpackrecordserializer"
	"github.com/inklabs/rangedb/rangedbtest"
)

func main() {
	// Given
	serializer := msgpackrecordserializer.New()
	serializer.Bind(rangedbtest.ThingWasDone{})
	event := &rangedbtest.ThingWasDone{
		ID:     "A",
		Number: 1,
	}
	record := &rangedb.Record{
		AggregateType:        "thing",
		AggregateID:          "60f01cc527844cde9953c998a2c077a7",
		GlobalSequenceNumber: 100,
		StreamSequenceNumber: 2,
		EventType:            "ThingWasDone",
		InsertTimestamp:      1576892379,
		Data:                 event,
		Metadata:             nil,
	}

	// When
	output, _ := serializer.Serialize(record)
	fmt.Printf("%q\n", output)

}
Output:
"\x89\xa1a\xa5thing\xa1i\xd9 60f01cc527844cde9953c998a2c077a7\xa1g\xcf\x00\x00\x00\x00\x00\x00\x00d\xa1s\xcf\x00\x00\x00\x00\x00\x00\x00\x02\xa1u\xcf\x00\x00\x00\x00]\xfdwۡe\xa0\xa1t\xacThingWasDone\xa1d\xc0\xa1m\xc0\x82\xa2id\xa1A\xa6number\xd3\x00\x00\x00\x00\x00\x00\x00\x01"

func UnmarshalRecord

func UnmarshalRecord(decoder *msgpack.Decoder, getEventType func(eventTypeName string) (reflect.Type, bool)) (*rangedb.Record, error)

UnmarshalRecord decodes a Record using the supplied msgpack decoder.

The record, excluding data, is decoded first. Then, event data is decoded. Event data will be parsed into a struct if supplied by getEventType.

Types

This section is empty.

Jump to

Keyboard shortcuts

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