1 /* LBS: An LFS-inspired filesystem backup system
2 * Copyright (C) 2006 Michael Vrable
4 * Backup data is stored in a collection of objects, which are grouped together
5 * into segments for storage purposes. This file provides interfaces for
6 * reading and writing objects and segments. */
18 typedef std::map<std::string, std::string> dictionary;
20 class IOException : public std::exception {
24 explicit IOException(const std::string &err) { error = err; }
25 virtual ~IOException() throw () { }
26 std::string getError() const { return error; }
31 virtual ~OutputStream() { }
32 virtual void write(const void *data, size_t len) = 0;
34 /* Convenience functions for writing other data types. Values are always
35 * written out in little-endian order. */
36 void write_u8(uint8_t val);
37 void write_u16(uint16_t val);
38 void write_u32(uint32_t val);
39 void write_u64(uint64_t val);
41 void write_s32(int32_t val) { write_u32((uint32_t)val); }
42 void write_s64(int64_t val) { write_u64((uint64_t)val); }
44 void write_varint(uint64_t val);
46 void write_string(const std::string &s);
47 void write_dictionary(const dictionary &d);
50 class StringOutputStream : public OutputStream {
52 std::stringstream buf;
56 virtual void write(const void *data, size_t len);
57 std::string contents() const { return buf.str(); }
60 class FileOutputStream : public OutputStream {
64 explicit FileOutputStream(FILE *file);
65 virtual ~FileOutputStream();
67 virtual void write(const void *data, size_t len);
70 std::string encode_u16(uint16_t val);
71 std::string encode_u32(uint32_t val);
72 std::string encode_u64(uint64_t val);
74 #endif // _LBS_STORE_H