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

feat: Also expose C++ set, getBytes, getVector methods #1260

Closed
wants to merge 1 commit into from

Conversation

mrousavy
Copy link
Contributor

Also exposes these methods to Apple Platforms:

    bool set(const char *value, MMKVKey_t key);
    bool set(const char *value, MMKVKey_t key, uint32_t expireDuration);

    bool set(const std::string &value, MMKVKey_t key);
    bool set(const std::string &value, MMKVKey_t key, uint32_t expireDuration);

    bool set(const mmkv::MMBuffer &value, MMKVKey_t key);
    bool set(const mmkv::MMBuffer &value, MMKVKey_t key, uint32_t expireDuration);

    bool set(const std::vector<std::string> &vector, MMKVKey_t key);
    bool set(const std::vector<std::string> &vector, MMKVKey_t key, uint32_t expireDuration);

    // inplaceModification is recommended for faster speed
    bool getString(MMKVKey_t key, std::string &result, bool inplaceModification = true);

    mmkv::MMBuffer getBytes(MMKVKey_t key);

    bool getBytes(MMKVKey_t key, mmkv::MMBuffer &result);

    bool getVector(MMKVKey_t key, std::vector<std::string> &result);

Previously, those methods were hidden under a #ifdef APPLE / #else branch, so that on Apple you could only use the NSObject<NSCoding> classes.

In my C++ environment (where I already had strings), it was a redundant extra step to convert from std::string <> NSString, and from MMBuffer <> NSData, so this PR removes that intermediate conversion step.

Unfortunately I couldn't do the same thing for allKeys, as only the return type changes (NSArray* vs std::vector<std::string>), so it cannot be overloaded.

We could introduce an additional method that is available whether MMKV_APPLE is true or not, but that's up to you if you want to do that @lingol.

@lingol
Copy link
Collaborator

lingol commented Mar 27, 2024

First thing first, thanks for your contribution.

  1. We don't accept PRs to the master branch, it must goes to the dev branch first.
  2. These methods were not there for iOS before. You can't just simply expose them. https://github.com/Tencent/MMKV/blob/master/Core/MMKV.cpp#L606

@mrousavy mrousavy marked this pull request as draft March 27, 2024 08:24
@mrousavy
Copy link
Contributor Author

Ah, my bad - I missed that they are not built either. I'll get back to you later today, will do some testing - this PR should've been draft in the first place as I didn't test yet.

@mrousavy mrousavy closed this Mar 27, 2024
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

Successfully merging this pull request may close these issues.

None yet

2 participants