| 1005 | } |
| 1006 | |
| 1007 | size_t Key(const char *str, size_t len) { |
| 1008 | auto sloc = buf_.size(); |
| 1009 | WriteBytes(str, len + 1); |
| 1010 | if (flags_ & BUILDER_FLAG_SHARE_KEYS) { |
| 1011 | auto it = key_pool.find(sloc); |
| 1012 | if (it != key_pool.end()) { |
| 1013 | // Already in the buffer. Remove key we just serialized, and use |
| 1014 | // existing offset instead. |
| 1015 | buf_.resize(sloc); |
| 1016 | sloc = *it; |
| 1017 | } else { |
| 1018 | key_pool.insert(sloc); |
| 1019 | } |
| 1020 | } |
| 1021 | stack_.push_back(Value(static_cast<uint64_t>(sloc), FBT_KEY, BIT_WIDTH_8)); |
| 1022 | return sloc; |
| 1023 | } |
| 1024 | |
| 1025 | size_t Key(const char *str) { return Key(str, strlen(str)); } |
| 1026 | size_t Key(const std::string &str) { return Key(str.c_str(), str.size()); } |
no test coverage detected