The buffer created here
buf = append(buf, TypeInt64) b := make([]byte, 8) i := varint.PutUvarint(b, uint64(v))
Isn't big enough for 64-bit integers (which can take up to 10 bytes when encoded as varints).