-/* In-memory representation of a UUID (Universally-Unique Identifier), which is
- * used to name a segment. */
-struct uuid {
- uint8_t bytes[16];
-};
-
-/* IOException will be thrown if an error occurs while reading or writing in
- * one of the I/O wrappers. Depending upon the context; this may be fatal or
- * not--typically, errors reading/writing the store will be serious, but errors
- * reading an individual file are less so. */
-class IOException : public std::exception {
-private:
- std::string error;
-public:
- explicit IOException(const std::string &err) { error = err; }
- virtual ~IOException() throw () { }
- std::string getError() const { return error; }
-};
-
-/* OutputStream is an abstract interface for writing data without seeking.
- * Output could be to a file, to an object within a segment, or even to a
- * memory buffer to help serialize data. */
-class OutputStream {
-public:
- OutputStream();
- virtual ~OutputStream() { }
-
- // Write the given data buffer
- void write(const void *data, size_t len);
-
- // Return the total number of bytes written so far
- int64_t get_pos() const { return bytes_written; }
-
- // Convenience functions for writing other data types. Values are always
- // written out in little-endian order.
- void write_u8(uint8_t val);
- void write_u16(uint16_t val);
- void write_u32(uint32_t val);
- void write_u64(uint64_t val);
-
- void write_s32(int32_t val) { write_u32((uint32_t)val); }
- void write_s64(int64_t val) { write_u64((uint64_t)val); }
-
- void write_varint(uint64_t val);
-
- void write_uuid(const struct uuid &u);
- void write_string(const std::string &s);
- void write_dictionary(const dictionary &d);
-
-protected:
- // Function which actually causes a write: must be overridden by
- // implementation.
- virtual void write_internal(const void *data, size_t len) = 0;
-
-private:
- int64_t bytes_written;
-};
-
-/* An OutputStream implementation which writes data to memory and returns the
- * result as a string. */
-class StringOutputStream : public OutputStream {
-public:
- StringOutputStream();
- std::string contents() const { return buf.str(); }
-
-protected:
- virtual void write_internal(const void *data, size_t len);
-
-private:
- std::stringstream buf;