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

[TODO] add ObjectId constructor from String #6

Open
lganzzzo opened this issue Nov 4, 2020 · 0 comments
Open

[TODO] add ObjectId constructor from String #6

lganzzzo opened this issue Nov 4, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@lganzzzo
Copy link
Member

lganzzzo commented Nov 4, 2020

Until this implemented users can use the following method:

#include "oatpp-mongo/bson/Types.hpp"
#include "oatpp/encoding/Hex.hpp"
#include "oatpp/core/data/stream/BufferStream.hpp"

oatpp::mongo::bson::ObjectId objectIdFromString(const oatpp::String& hexText) {
  oatpp::data::stream::BufferOutputStream stream(12);
  oatpp::encoding::Hex::decode(&stream, hexText->getData(), hexText->getSize(), false);
  if(stream.getCurrentPosition() != 12) {
    throw std::runtime_error("Error. Invalid string.");
  }
  return oatpp::mongo::bson::ObjectId(stream.getData());
}

auto objId = objectIdFromString("5f9b6ecb21a7da049662e7d2");
OATPP_LOGD("AAA", "objId='%s'", objId->toString()->c_str());
@lganzzzo lganzzzo added the enhancement New feature or request label Nov 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant