提交 94671412 编写于 作者: S sangoly 提交者: Yan Chunwei

[Navie buffer] make load/save be compatible with 32 and 64 arch test=develop (#1858)

上级 249cbf81
......@@ -68,13 +68,13 @@ void BinaryTable::LoadFromFile(const std::string &filename) {
void StringBuilder::Save() {
// memory format: [size][string data]
size_t mem_size = sizeof(size_t) + data_.size();
uint64_t mem_size = sizeof(uint64_t) + data_.size();
table()->Require(mem_size);
size_t str_len = data_.size();
uint64_t str_len = data_.size();
// write meta data of size.
memcpy(table()->cursor(), &str_len, sizeof(size_t));
table()->Consume(sizeof(size_t));
memcpy(table()->cursor(), &str_len, sizeof(uint64_t));
table()->Consume(sizeof(uint64_t));
// write the string data.
memcpy(table()->cursor(),
......@@ -85,9 +85,9 @@ void StringBuilder::Save() {
void StringBuilder::Load() {
// load meta data of size
size_t str_len{};
memcpy(&str_len, table()->cursor(), sizeof(size_t));
table()->Consume(sizeof(size_t));
uint64_t str_len{};
memcpy(&str_len, table()->cursor(), sizeof(uint64_t));
table()->Consume(sizeof(uint64_t));
// load string data.
data_.resize(str_len);
......
......@@ -303,10 +303,10 @@ class ListBuilder : public FieldBuilder {
template <typename Builder>
void ListBuilder<Builder>::Save() {
// store number of elements in the head.
size_t num_elems = size();
table()->Require(sizeof(size_t));
memcpy(table()->cursor(), &num_elems, sizeof(size_t));
table()->Consume(sizeof(size_t));
uint64_t num_elems = size();
table()->Require(sizeof(uint64_t));
memcpy(table()->cursor(), &num_elems, sizeof(uint64_t));
table()->Consume(sizeof(uint64_t));
// Save all the elements.
for (auto& elem : builders_) {
......@@ -318,12 +318,12 @@ template <typename Builder>
void ListBuilder<Builder>::Load() {
CHECK(builders_.empty()) << "Duplicate load";
// Load number of elements first.
size_t num_elems{};
memcpy(&num_elems, table()->cursor(), sizeof(num_elems));
table()->Consume(sizeof(size_t));
uint64_t num_elems{};
memcpy(&num_elems, table()->cursor(), sizeof(uint64_t));
table()->Consume(sizeof(uint64_t));
// Load all the elements.
for (size_t i = 0; i < num_elems; i++) {
for (uint64_t i = 0; i < num_elems; i++) {
builders_.emplace_back(table());
builders_.back().Load();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册