Loading data blob into buffer using C/C++ #3405
Replies: 1 comment 4 replies
-
An optional access error probably means your buffer is invalid. Your buffer reading code looks really complex so there's probably something wrong in there. However, that's a general C++ question, not an ICU4X question. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've tried loading the blob data into buffer using C as well as C++ . Below is the new C++ code which I've written:
int main(){
UnicodeString str ("ພາສາລາວ");
printUnicodeString(str);
cout<<endl;
//C++ code
std::ifstream fin("my_data_blob", std::ifstream::ate | std::ifstream::binary);
fin.seekg(0, std::ios::end);
std::streamsize blob_size = fin.tellg();
cout<<"size buffer "<<blob_size<<endl;
fin.seekg(0, std::ios::beg);
char* buffer = new char[blob_size];
fin.read(buffer, blob_size);
cout<<buffer<<endl;
std::vector<uint8_t> f_buffer(blob_size);
auto sample = reinterpret_cast<uint8_t*>(buffer);
auto sample2 = reinterpret_cast<uint8_t*>(buffer + blob_size);
f_buffer.insert(f_buffer.end(), reinterpret_cast<const uint8_t*>(buffer), reinterpret_cast<const uint8_t*>(buffer+ blob_size));
const diplomat::span blob(f_buffer.data(), f_buffer.size());
const auto provider_result = ICU4XDataProvider::create_from_byte_slice(blob).ok().value();
const auto segmenter_auto = ICU4XWordSegmenter::create_auto(provider_result).ok().value();
}
But this code is giving bad optional access error. Maybe there is some issue in loading blob into buffer. But this is the only way which I found to read blob's data into buffer. Are you aware of how to load your data blob into buffer?
Beta Was this translation helpful? Give feedback.
All reactions