Esempio n. 1
0
func (e *Event) encode() []byte {
	buf := bytes.NewBuffer([]byte{})

	binary.WriteUvarint(buf, len(e.Data))
	buf.Write(e.Data)

	binary.WriteUvarint(buf, len(e.offsets))

	for name, offset := range e.offsets {
		binary.WriteUvarint(buf, len(name))
		buf.Write([]byte(name))
		binary.WriteUvarint64(buf, offset)
	}

	return buf.Bytes()
}
Esempio n. 2
0
File: db.go Progetto: jmptrader/esdb
func (db *DB) Save() ([]byte, error) {
	buf := &bytes.Buffer{}

	binary.WriteInt64(buf, int64(db.current))
	binary.WriteInt64(buf, db.MostRecent)

	binary.WriteUvarint(buf, len(db.closed))

	for _, commit := range db.closed {
		binary.WriteInt64(buf, int64(commit))
	}

	return buf.Bytes(), nil
}
Esempio n. 3
0
// Events are encoded in the following byte format:
// [Uvarint:length][int32:timestamp][bytes(length):data]
func (e *Event) push(out io.Writer) {
	binary.WriteUvarint(out, len(e.Data))
	binary.WriteInt32(out, e.Timestamp)
	out.Write(e.Data)
	e.Data = nil
}