-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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 1 commit
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -130,22 +130,28 @@ std::vector<T> BlobDeserializer<Impl>::ReadVector() { | |||||
|
|
||||||
| template <typename Impl> | ||||||
| std::string BlobDeserializer<Impl>::ReadString() { | ||||||
| std::string_view view = ReadStringView(); | ||||||
| std::string result(view.data(), | ||||||
| view.size()); // This creates a copy of view.data. | ||||||
|
joyeecheung marked this conversation as resolved.
Outdated
|
||||||
| return result; | ||||||
|
joyeecheung marked this conversation as resolved.
Outdated
|
||||||
| } | ||||||
|
|
||||||
| template <typename Impl> | ||||||
| std::string_view BlobDeserializer<Impl>::ReadStringView() { | ||||||
| size_t length = ReadArithmetic<size_t>(); | ||||||
|
|
||||||
| if (is_debug) { | ||||||
| Debug("ReadString(), length=%d: ", length); | ||||||
| Debug("ReadStringView(), length=%d: ", length); | ||||||
| } | ||||||
|
|
||||||
| 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. | ||||||
| std::string_view result(sink.data() + read_total, length); | ||||||
|
|
||||||
| if (is_debug) { | ||||||
| Debug("\"%s\", read %zu bytes\n", result.c_str(), length + 1); | ||||||
| Debug("\"%s\", read %zu bytes\n", result.data(), result.size()); | ||||||
| } | ||||||
|
|
||||||
| read_total += length + 1; | ||||||
| read_total += length; | ||||||
| return result; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -262,17 +268,15 @@ 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) { | ||||||
| size_t BlobSerializer<Impl>::WriteStringView(const std::string_view& data) { | ||||||
|
joyeecheung marked this conversation as resolved.
Outdated
|
||||||
| CHECK_GT(data.size(), 0); // No empty strings should be written. | ||||||
|
joyeecheung marked this conversation as resolved.
Outdated
|
||||||
| 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()); | ||||||
|
joyeecheung marked this conversation as resolved.
Outdated
|
||||||
| } | ||||||
|
|
||||||
| // 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) { | ||||||
|
joyeecheung marked this conversation as resolved.
Outdated
|
||||||
|
|
@@ -282,6 +286,14 @@ size_t BlobSerializer<Impl>::WriteString(const std::string& data) { | |||||
| 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 |
||||||
| if (is_debug) { | ||||||
| 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.