-
-
Notifications
You must be signed in to change notification settings - Fork 36.5k
src: use Blob{Des|S}erializer for SEA blobs #47962
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
Changes from 4 commits
66c599a
7f90459
1e4dfec
a1ca8dc
87c72f7
ef3fb40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,8 +13,8 @@ | |||||
|
|
||||||
| #include "debug_utils-inl.h" | ||||||
|
|
||||||
| // This is related to the blob that is used in snapshots and has nothing to do | ||||||
| // with `node_blob.h`. | ||||||
| // This is related to the blob that is used in snapshots and single executable | ||||||
| // applications and has nothing to do with `node_blob.h`. | ||||||
|
|
||||||
| namespace node { | ||||||
|
|
||||||
|
|
@@ -130,22 +130,20 @@ std::vector<T> BlobDeserializer<Impl>::ReadVector() { | |||||
|
|
||||||
| template <typename Impl> | ||||||
| std::string BlobDeserializer<Impl>::ReadString() { | ||||||
| size_t length = ReadArithmetic<size_t>(); | ||||||
|
|
||||||
| if (is_debug) { | ||||||
| Debug("ReadString(), length=%d: ", length); | ||||||
| } | ||||||
| std::string_view view = ReadStringView(); | ||||||
| Debug("ReadString(), length=%zu: \"%s\"\n", view.size(), view.data()); | ||||||
|
joyeecheung marked this conversation as resolved.
Outdated
|
||||||
| return std::string(view); | ||||||
| } | ||||||
|
|
||||||
| CHECK_GT(length, 0); // There should be no empty strings. | ||||||
| MallocedBuffer<char> buf(length + 1); | ||||||
| memcpy(buf.data, sink.data() + read_total, length + 1); | ||||||
| std::string result(buf.data, length); // This creates a copy of buf.data. | ||||||
| template <typename Impl> | ||||||
| std::string_view BlobDeserializer<Impl>::ReadStringView() { | ||||||
| size_t length = ReadArithmetic<size_t>(); | ||||||
| Debug("ReadStringView(), length=%zu: ", length); | ||||||
|
|
||||||
| if (is_debug) { | ||||||
| Debug("\"%s\", read %zu bytes\n", result.c_str(), length + 1); | ||||||
| } | ||||||
| std::string_view result(sink.data() + read_total, length); | ||||||
| Debug("%p, read %zu bytes\n", result.data(), result.size()); | ||||||
|
|
||||||
| read_total += length + 1; | ||||||
| read_total += length; | ||||||
| return result; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -262,26 +260,25 @@ size_t BlobSerializer<Impl>::WriteVector(const std::vector<T>& data) { | |||||
| // [ 4/8 bytes ] length | ||||||
| // [ |length| bytes ] contents | ||||||
| template <typename Impl> | ||||||
| size_t BlobSerializer<Impl>::WriteString(const std::string& data) { | ||||||
| CHECK_GT(data.size(), 0); // No empty strings should be written. | ||||||
| size_t BlobSerializer<Impl>::WriteStringView(std::string_view data) { | ||||||
| size_t written_total = WriteArithmetic<size_t>(data.size()); | ||||||
| if (is_debug) { | ||||||
| std::string str = ToStr(data); | ||||||
| Debug("WriteString(), length=%zu: \"%s\"\n", data.size(), data.c_str()); | ||||||
| } | ||||||
| Debug("WriteStringView(), length=%zu: %p\n", data.size(), data.data()); | ||||||
|
|
||||||
| // Write the null-terminated string. | ||||||
| size_t length = data.size() + 1; | ||||||
| sink.insert(sink.end(), data.c_str(), data.c_str() + length); | ||||||
| size_t length = data.size(); | ||||||
| sink.insert(sink.end(), data.data(), data.data() + length); | ||||||
| written_total += length; | ||||||
|
|
||||||
| if (is_debug) { | ||||||
| Debug("WriteString() wrote %zu bytes\n", written_total); | ||||||
| } | ||||||
| Debug("WriteStringView() wrote %zu bytes\n", written_total); | ||||||
|
|
||||||
| return written_total; | ||||||
| } | ||||||
|
|
||||||
| template <typename Impl> | ||||||
| size_t BlobSerializer<Impl>::WriteString(const std::string& data) { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the method that writes strings (which logs the string directly in debug mode). The one that doesn't is |
||||||
| Debug("WriteString(), length=%zu: \"%s\"\n", data.size(), data.data()); | ||||||
| return WriteStringView(data); | ||||||
| } | ||||||
|
|
||||||
| // Helper for writing an array of numeric types. | ||||||
| template <typename Impl> | ||||||
| template <typename T> | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.