Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About layout of the mmaped file #68

Closed
jianzhongli opened this issue Oct 2, 2018 · 1 comment
Closed

About layout of the mmaped file #68

jianzhongli opened this issue Oct 2, 2018 · 1 comment

Comments

@jianzhongli
Copy link

After calling mmkv.putInt("int", 100) several times, I got a file named after mmkv id under the app's data folder. By inspecting the file content with xxd, I am a little bit confused about the layout of the file.
image-20181002110606026

  • The first four bytes are value of m_actualSize ,and we have 6700 0000 0x67 = 103 bytes.
  • Then we have 0603 696e 7401 64
    • 06 is the size of the map
    • 03 696e 74 represents the length(03 bytes) and content of the key (696e 74, "int")
    • 01 64 represents the length(01 bytes) and the content of the value (0x64 = 100)

Why do we need to write size of the map into the mmaped file anyway? It seems that the size is of no use when decoding.

unordered_map<string, MMBuffer> MiniPBCoder::decodeOneMap(size_t size) {
unordered_map<string, MMBuffer> dic;
if (size == 0) {
auto length = m_inputData->readInt32();
}
while (!m_inputData->isAtEnd()) {
const auto &key = m_inputData->readString();
if (key.length() > 0) {
auto value = m_inputData->readData();
if (value.length() > 0) {
dic[key] = move(value);
} else {
dic.erase(key);
}
}
}
return dic;
}

@lingol
Copy link
Collaborator

lingol commented Oct 2, 2018

You're right. The size of of the map is not in used. It's here for historical compatibility reason.

Great skills of analyzing the data structure of the file, by the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants