github.com/alexflint/go-memdump@v1.1.0/README.md (about)

     1  [![Documentation](https://godoc.org/github.com/alexflint/go-memdump?status.svg)](https://godoc.org/github.com/alexflint/go-memdump)
     2  [![Build Status](https://github.com/alexflint/go-memdump/workflows/Go/badge.svg)](https://github.com/alexflint/go-memdump/actions)
     3  [![Coverage Status](https://coveralls.io/repos/github/alexflint/go-memdump/badge.svg?branch=master)](https://coveralls.io/github/alexflint/go-memdump?branch=master)
     4  [![Report Card](https://goreportcard.com/badge/github.com/alexflint/go-memdump)](https://goreportcard.com/report/github.com/alexflint/go-memdump)
     5  
     6  ## Very fast, very unsafe serialization for Go
     7  
     8  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).
     9  
    10  The price you pay is:
    11  - you cannot load structs that contain maps or interfaces
    12  - your data is not portable across machine architectures (64 bit vs 32 bit, big-endian vs small-endian)
    13  
    14  ### Benchmarks
    15  
    16  The benchmarks were measured by encoding and decoding a tree containing 2,097,151 small structs. Code is under the bench dir.
    17  
    18  **Decode**
    19  ```
    20                   gob    28.17 MB/s      (39.8 MB in 1.41s)
    21                  json    30.17 MB/s      (113.8 MB in 3.77s)
    22               memdump  1031.54 MB/s      (113.2 MB in 0.11s)
    23  ```
    24  
    25  **Encode**
    26  ```
    27                   gob    37.07 MB/s      (39.8 MB in 1.07s)
    28                  json    77.20 MB/s      (113.8 MB in 1.47s)
    29               memdump    61.25 MB/s      (113.2 MB in 1.85s)
    30  ```
    31  
    32  To reproduce these results:
    33  ```shell
    34  $ go run ./bench/summarize.go
    35  ```
    36  
    37  ## Quick start
    38  
    39  ```shell
    40  go get github.com/alexflint/go-memdump
    41  ```
    42  
    43  Write data to a file:
    44  
    45  ```go
    46  type data struct {
    47  	Foo string
    48  	Bar int
    49  }
    50  
    51  w, err := os.Create("/tmp/data.memdump")
    52  if err != nil {
    53  	...
    54  }
    55  
    56  // note that you must pass a pointer when encoding
    57  mydata := data{Foo: "abc", Bar: 123}
    58  memdump.Encode(w, &mydata)
    59  ```
    60  
    61  Load data from a file:
    62  
    63  ```go
    64  r, err := os.Open("/tmp/data.memdump")
    65  if err != nil {
    66  	...
    67  }
    68  
    69  // note that you muss pass a pointer to a pointer when decoding
    70  var mydata *data
    71  memdump.Decode(r, &mydata)
    72  ```