Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Unified Diff: mojo/public/cpp/bindings/lib/array_serialization.h

Issue 2112093002: Mojo C++ bindings: Merge EncodePointers/DecodePointers into Serialize/Deserialize, respectively. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@61_array_fix
Patch Set: . Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/lib/array_internal.h ('k') | mojo/public/cpp/bindings/lib/bindings_internal.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/array_serialization.h
diff --git a/mojo/public/cpp/bindings/lib/array_serialization.h b/mojo/public/cpp/bindings/lib/array_serialization.h
index c0e9318333b357dda246d71becb07a419ab77fba..5db27a5502a5a238ec1a6765d8f2854248a36e36 100644
--- a/mojo/public/cpp/bindings/lib/array_serialization.h
+++ b/mojo/public/cpp/bindings/lib/array_serialization.h
@@ -353,17 +353,14 @@ struct ArraySerializer<MojomType,
MojomTypeCategory::STRUCT>::value>::type> {
using UserType = typename std::remove_const<MaybeConstUserType>::type;
using Data = typename MojomTypeTraits<MojomType>::Data;
- using DataElement = typename Data::Element;
using Element = typename MojomType::Element;
+ using DataElementPtr = typename MojomTypeTraits<Element>::Data*;
using Traits = ArrayTraits<UserType>;
static size_t GetSerializedSize(UserTypeIterator* input,
SerializationContext* context) {
size_t element_count = input->GetSize();
- size_t size =
- sizeof(Data) +
- element_count *
- sizeof(Pointer<typename std::remove_pointer<DataElement>::type>);
+ size_t size = sizeof(Data) + element_count * sizeof(typename Data::Element);
for (size_t i = 0; i < element_count; ++i)
size += PrepareToSerialize<Element>(input->GetNext(), context);
return size;
@@ -376,13 +373,13 @@ struct ArraySerializer<MojomType,
SerializationContext* context) {
size_t size = input->GetSize();
for (size_t i = 0; i < size; ++i) {
- DataElement element;
- SerializeCaller<Element>::Run(input->GetNext(), buf, &element,
+ DataElementPtr data_ptr;
+ SerializeCaller<Element>::Run(input->GetNext(), buf, &data_ptr,
validate_params->element_validate_params,
context);
- output->at(i) = element;
+ output->at(i).Set(data_ptr);
MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
- !validate_params->element_is_nullable && !element,
+ !validate_params->element_is_nullable && !data_ptr,
VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
MakeMessageWithArrayIndex("null in array expecting valid pointers",
size, i));
@@ -391,19 +388,15 @@ struct ArraySerializer<MojomType,
static bool DeserializeElements(Data* input,
UserType* output,
SerializationContext* context) {
- bool success = true;
if (!Traits::Resize(*output, input->size()))
return false;
ArrayIterator<Traits, UserType> iterator(*output);
for (size_t i = 0; i < input->size(); ++i) {
- // Note that we rely on complete deserialization taking place in order to
- // transfer ownership of all encoded handles. Therefore we don't
- // short-circuit on failure here.
- if (!Deserialize<Element>(input->at(i), &iterator.GetNext(), context)) {
- success = false;
- }
+ if (!Deserialize<Element>(input->at(i).Get(), &iterator.GetNext(),
+ context))
+ return false;
}
- return success;
+ return true;
}
private:
@@ -415,7 +408,7 @@ struct ArraySerializer<MojomType,
template <typename InputElementType>
static void Run(InputElementType&& input,
Buffer* buf,
- DataElement* output,
+ DataElementPtr* output,
const ContainerValidateParams* validate_params,
SerializationContext* context) {
Serialize<T>(std::forward<InputElementType>(input), buf, output, context);
@@ -427,7 +420,7 @@ struct ArraySerializer<MojomType,
template <typename InputElementType>
static void Run(InputElementType&& input,
Buffer* buf,
- DataElement* output,
+ DataElementPtr* output,
const ContainerValidateParams* validate_params,
SerializationContext* context) {
Serialize<T>(std::forward<InputElementType>(input), buf, output,
@@ -487,19 +480,14 @@ struct ArraySerializer<
static bool DeserializeElements(Data* input,
UserType* output,
SerializationContext* context) {
- bool success = true;
if (!Traits::Resize(*output, input->size()))
return false;
ArrayIterator<Traits, UserType> iterator(*output);
for (size_t i = 0; i < input->size(); ++i) {
- // Note that we rely on complete deserialization taking place in order to
- // transfer ownership of all encoded handles. Therefore we don't
- // short-circuit on failure here.
- if (!Deserialize<Element>(&input->at(i), &iterator.GetNext(), context)) {
- success = false;
- }
+ if (!Deserialize<Element>(&input->at(i), &iterator.GetNext(), context))
+ return false;
}
- return success;
+ return true;
}
};
« no previous file with comments | « mojo/public/cpp/bindings/lib/array_internal.h ('k') | mojo/public/cpp/bindings/lib/bindings_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698