Categorygithub.com/alexflint/go-memdump
modulepackage
1.1.0
Repository: https://github.com/alexflint/go-memdump.git
Documentation: pkg.go.dev

# README

Documentation Build Status Coverage Status Report Card

Very fast, very unsafe serialization for Go

This package provides a fast way to load large amounts of data into Go structs. Memdump can load datasets containing millions of small structs at over 1 GB/s (compared to ~30 MB/s for gob or json).

The price you pay is:

  • you cannot load structs that contain maps or interfaces
  • your data is not portable across machine architectures (64 bit vs 32 bit, big-endian vs small-endian)

Benchmarks

The benchmarks were measured by encoding and decoding a tree containing 2,097,151 small structs. Code is under the bench dir.

Decode

                 gob    28.17 MB/s      (39.8 MB in 1.41s)
                json    30.17 MB/s      (113.8 MB in 3.77s)
             memdump  1031.54 MB/s      (113.2 MB in 0.11s)

Encode

                 gob    37.07 MB/s      (39.8 MB in 1.07s)
                json    77.20 MB/s      (113.8 MB in 1.47s)
             memdump    61.25 MB/s      (113.2 MB in 1.85s)

To reproduce these results:

$ go run ./bench/summarize.go

Quick start

go get github.com/alexflint/go-memdump

Write data to a file:

type data struct {
	Foo string
	Bar int
}

w, err := os.Create("/tmp/data.memdump")
if err != nil {
	...
}

// note that you must pass a pointer when encoding
mydata := data{Foo: "abc", Bar: 123}
memdump.Encode(w, &mydata)

Load data from a file:

r, err := os.Open("/tmp/data.memdump")
if err != nil {
	...
}

// note that you muss pass a pointer to a pointer when decoding
var mydata *data
memdump.Decode(r, &mydata)

# Packages

No description provided by the author
No description provided by the author

# Functions

Decode reads an object of the specified type from the input and stores a pointer to it at the location specified by ptrptr, which must be a pointer to a pointer.
Encode writes a memdump of the provided object to output.
NewDecoder creates a Decoder that reads memdumps.
NewDelimitedReader creates a reader for delimited segments.
NewEncoder creates an Encoder that writes memdumps to the provided writer.
NewHeterogeneousDecoder creates a HeterogeneousDecoder that reads memdumps.
NewHeterogeneousEncoder creates an HeterogeneousEncoder that writes memdumps to the provided writer.

# Variables

ErrBufferTooSmall is returned by delimetedReader if the input buffer is smaller than the length of the delimeter.
ErrIncompatibleLayout is returned by decoders when the object on the wire has an in-memory layout that is not compatible with the requested Go type.
ErrUnexpectedEOF is returned by delimetedReader if EOF is reached before finding a delimeter.

# Structs

Decoder reads memdumps from the provided reader.
DelimitedReader reads delimited segments.
Encoder writes memdumps to the provided writer.
HeterogeneousDecoder reads memdumps from the provided reader.
HeterogeneousEncoder writes memdumps to the provided writer.