25 const size_t kMagic = 0x7b1d1f7b5bf501db;
27 void WriteSizeAsLittleEndian(
size_t size, std::ostream* out) {
28 for (
int i = 0; i != 8; ++i) {
29 out->put(size & 0xff);
34 bool ReadSizeAsLittleEndian(std::istream* in,
size_t* size) {
36 for (
int i = 0; i != 8; ++i) {
38 *size +=
static_cast<size_t>(in->get()) << 56;
46 : out_(filename, std::ios::out | std::ios::binary) {
47 WriteSizeAsLittleEndian(kMagic, &
out_);
53 string compressed_data;
55 WriteSizeAsLittleEndian(compressed_data.size(), &
out_);
56 out_.write(compressed_data.data(), compressed_data.size());
65 : in_(filename, std::ios::in | std::ios::binary) {
67 if (!ReadSizeAsLittleEndian(&
in_, &magic) || magic != kMagic) {
68 in_.setstate(std::ios::failbit);
75 size_t compressed_size;
76 if (!ReadSizeAsLittleEndian(&
in_, &compressed_size)) {
79 string compressed_data(compressed_size,
'\0');
80 if (!
in_.read(&compressed_data.front(), compressed_size)) {
ProtoStreamWriter(const string &filename)
void FastGzipString(const string &uncompressed, string *compressed)
void FastGunzipString(const string &compressed, string *decompressed)
bool Read(string *decompressed_data)
ProtoStreamReader(const string &filename)
void Write(const string &uncompressed_data)