From 56dbad15e3dde6c3c11afecaddd48a1650f818fe Mon Sep 17 00:00:00 2001 From: lanyaye <30432896+lanyaye@users.noreply.github.com> Date: Tue, 25 Jul 2017 21:59:57 +0800 Subject: [PATCH] Fix proto_stream to support 32-bit platforms. (#427) In proto_stream.cc, size_t is only correct on 64-bit platforms. Changing it to uint64 adds support for 32-bit platforms. This fixes #426. --- cartographer/io/proto_stream.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cartographer/io/proto_stream.cc b/cartographer/io/proto_stream.cc index e715e39..1f8e3f5 100644 --- a/cartographer/io/proto_stream.cc +++ b/cartographer/io/proto_stream.cc @@ -22,20 +22,20 @@ namespace io { namespace { // First eight bytes to identify our proto stream format. -const size_t kMagic = 0x7b1d1f7b5bf501db; +const uint64 kMagic = 0x7b1d1f7b5bf501db; -void WriteSizeAsLittleEndian(size_t size, std::ostream* out) { +void WriteSizeAsLittleEndian(uint64 size, std::ostream* out) { for (int i = 0; i != 8; ++i) { out->put(size & 0xff); size >>= 8; } } -bool ReadSizeAsLittleEndian(std::istream* in, size_t* size) { +bool ReadSizeAsLittleEndian(std::istream* in, uint64* size) { *size = 0; for (int i = 0; i != 8; ++i) { *size >>= 8; - *size += static_cast(in->get()) << 56; + *size += static_cast(in->get()) << 56; } return !in->fail(); } @@ -63,7 +63,7 @@ bool ProtoStreamWriter::Close() { ProtoStreamReader::ProtoStreamReader(const string& filename) : in_(filename, std::ios::in | std::ios::binary) { - size_t magic; + uint64 magic; if (!ReadSizeAsLittleEndian(&in_, &magic) || magic != kMagic) { in_.setstate(std::ios::failbit); } @@ -72,7 +72,7 @@ ProtoStreamReader::ProtoStreamReader(const string& filename) ProtoStreamReader::~ProtoStreamReader() {} bool ProtoStreamReader::Read(string* decompressed_data) { - size_t compressed_size; + uint64 compressed_size; if (!ReadSizeAsLittleEndian(&in_, &compressed_size)) { return false; }