codec

package
v6.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package codec contains sub-packages with different codecs that can be used to encode and decode entities in Rainstorm.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"path/filepath"

	"github.com/AndersonBargas/rainstorm/v6"
	"github.com/AndersonBargas/rainstorm/v6/codec"
	"github.com/AndersonBargas/rainstorm/v6/codec/gob"
	"github.com/AndersonBargas/rainstorm/v6/codec/json"
	"github.com/AndersonBargas/rainstorm/v6/codec/msgpack"
	"github.com/AndersonBargas/rainstorm/v6/codec/protobuf"
	"github.com/AndersonBargas/rainstorm/v6/codec/sereal"
)

func main() {
	ctx := context.Background()
	dir, err := os.MkdirTemp("", "rainstorm-codecs")
	if err != nil {
		log.Fatal(err)
	}
	defer func() {
		if err := os.RemoveAll(dir); err != nil {
			log.Println("remove temporary directory:", err)
		}
	}()

	codecs := []struct {
		name  string
		codec codec.MarshalUnmarshaler
	}{
		{name: "gob", codec: gob.Codec},
		{name: "json", codec: json.Codec},
		{name: "msgpack", codec: msgpack.Codec},
		{name: "sereal", codec: sereal.Codec},
		{name: "protobuf", codec: protobuf.Codec},
	}

	for _, candidate := range codecs {
		db, err := rainstorm.Open(ctx, filepath.Join(dir, candidate.name+".db"), rainstorm.Codec(candidate.codec))
		if err != nil {
			log.Fatal(err)
		}

		fmt.Printf("%T\n", db.Codec())
		if err := db.Close(); err != nil {
			log.Fatal(err)
		}
	}

}
Output:
*gob.gobCodec
*json.jsonCodec
*msgpack.msgpackCodec
*sereal.serealCodec
*protobuf.protobufCodec

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MarshalUnmarshaler

type MarshalUnmarshaler interface {
	// Marshal encodes v.
	Marshal(v interface{}) ([]byte, error)
	// Unmarshal decodes b into v.
	Unmarshal(b []byte, v interface{}) error
	// Name returns the stable codec identifier stored in Rainstorm metadata.
	Name() string
}

MarshalUnmarshaler represents a codec used to marshal and unmarshal entities.

Directories

Path Synopsis
Package aes provides an AES-GCM encrypted codec that wraps another codec.MarshalUnmarshaler.
Package aes provides an AES-GCM encrypted codec that wraps another codec.MarshalUnmarshaler.
Package gob contains a codec to encode and decode entities in Gob format
Package gob contains a codec to encode and decode entities in Gob format
Package json contains a codec to encode and decode entities in JSON format
Package json contains a codec to encode and decode entities in JSON format
Package msgpack contains a codec to encode and decode entities in msgpack format
Package msgpack contains a codec to encode and decode entities in msgpack format
Package protobuf provides a codec for Protocol Buffers messages.
Package protobuf provides a codec for Protocol Buffers messages.
Package sereal contains a codec to encode and decode entities using Sereal
Package sereal contains a codec to encode and decode entities using Sereal

Jump to

Keyboard shortcuts

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