jsonrecordserializer

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

This section is empty.

Functions

func DecodeJsonData added in v0.3.0

func DecodeJsonData(eventTypeName string, rawJsonData io.Reader, eventTypeIdentifier rangedb.EventTypeIdentifier) (interface{}, error)

DecodeJsonData decodes raw json into a struct or interface{}.

Event data will be parsed into a struct if supplied by getEventType.

func New

func New() *jsonSerializer

New constructs a jsonSerializer.

Example (DeserializeWithBoundEvent)
package main

import (
	"fmt"

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

func main() {
	// Given
	serializer := jsonrecordserializer.New()
	serializer.Bind(rangedbtest.ThingWasDone{})
	json := `{"aggregateType":"thing","aggregateID":"60f01cc527844cde9953c998a2c077a7","globalSequenceNumber":100,"streamSequenceNumber":2,"insertTimestamp":1576892379,"eventID":"","eventType":"ThingWasDone","data":{"id":"A","number":1},"metadata":null}`

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

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

import (
	"fmt"

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

func main() {
	// Given
	serializer := jsonrecordserializer.New()
	json := `{"aggregateType":"thing","aggregateID":"60f01cc527844cde9953c998a2c077a7","globalSequenceNumber":100,"streamSequenceNumber":2,"insertTimestamp":1576892379,"eventID":"","eventType":"ThingWasDone","data":{"id":"A","number":1},"metadata":null}`

	// When
	record, _ := serializer.Deserialize([]byte(json))
	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/jsonrecordserializer"
	"github.com/inklabs/rangedb/rangedbtest"
)

func main() {
	// Given
	serializer := jsonrecordserializer.New()
	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.Println(string(output))

}
Output:
{"aggregateType":"thing","aggregateID":"60f01cc527844cde9953c998a2c077a7","globalSequenceNumber":100,"streamSequenceNumber":2,"insertTimestamp":1576892379,"eventID":"","eventType":"ThingWasDone","data":{"id":"A","number":1},"metadata":null}

func UnmarshalRecord

func UnmarshalRecord(decoder *json.Decoder, eventTypeIdentifier rangedb.EventTypeIdentifier) (*rangedb.Record, error)

UnmarshalRecord decodes a Record using the supplied JSON decoder.

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