1package vmkit23import"errors"45// ErrTruncated is returned by every Reader method that runs past the end of6// the buffer. A snapshot is consensus state, so a short read is always a hard7// error and never a zero value.
Functions
not supported for pure packages by the node (vm/qfuncs)
Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.
8
var ErrTruncated = errors.New("vmkit: truncated snapshot")
9
10// ErrBadSnapshot is returned when a snapshot is well-formed but not for this
11// machine: wrong magic, wrong version, or a field outside its legal range.
12var ErrBadSnapshot = errors.New("vmkit: snapshot is not for this machine")
13
14// Writer builds a snapshot. Every integer is fixed-width big-endian and every
15// byte slice is length-prefixed, so the encoding is canonical: the same
16// machine state always produces the same bytes, on every node.
17//
18// Machines are not required to use it, but a machine that invents its own
19// layout owes the zoo an explanation, because the cross-VM snapshot cost
20// comparison only means something when the encodings match.
21type Writer struct {
22 buf []byte
23}
24
25// NewWriter returns a Writer with room for n bytes reserved up front.
26func NewWriter(n int) *Writer {
27if n < 0 {
28 n = 0
29 }
30return &Writer{buf: make([]byte, 0, n)}
31}
32
33// Byte appends one byte.
34func (w *Writer) Byte(b byte) { w.buf = append(w.buf, b) }