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

Side by Side Diff: mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl

Issue 1800753005: C++ bindings: A struct's Deserialize() now does validation before deserializing. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 9 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 unified diff | Download patch
OLDNEW
1 {% from "enum_macros.tmpl" import enum_decl -%} 1 {% from "enum_macros.tmpl" import enum_decl -%}
2 class {{struct.name}} { 2 class {{struct.name}} {
3 public: 3 public:
4 using Data_ = internal::{{struct.name}}_Data; 4 using Data_ = internal::{{struct.name}}_Data;
5 5
6 {#--- Enums #} 6 {#--- Enums #}
7 {%- for enum in struct.enums -%} 7 {%- for enum in struct.enums -%}
8 {{enum_decl(enum, is_static=true)|indent(2)}} 8 {{enum_decl(enum, is_static=true)|indent(2)}}
9 {%- endfor %} 9 {%- endfor %}
10 10
(...skipping 26 matching lines...) Expand all
37 37
38 // Returns true on successful serialization. On failure, part of the data may 38 // Returns true on successful serialization. On failure, part of the data may
39 // be serialized, until the point of failure. This API does not support 39 // be serialized, until the point of failure. This API does not support
40 // serializing handles. 40 // serializing handles.
41 // 41 //
42 // TODO(vardhan): For now, we return true for success. Should we define a 42 // TODO(vardhan): For now, we return true for success. Should we define a
43 // public error type for serialization? (we shouldn't reuse 43 // public error type for serialization? (we shouldn't reuse
44 // internal::ValidationError). 44 // internal::ValidationError).
45 bool Serialize(void* buf, size_t buf_size); 45 bool Serialize(void* buf, size_t buf_size);
46 46
47 // Deserializes the given |buf| representing a serialized version of this 47 // Deserializes the given |buf| of given size |buf_size| representing a
48 // struct. Assumes that the serialized |buf| is valid. 48 // serialized version of this struct. The buffer is validated before
49 // it is deserialized. Returns true on successful deserialization.
49 // 50 //
50 // TODO(vardhan): 51 // TODO(vardhan): Recover the validation error if there is one?
51 // - Should we pass in how big |buf| is and validate that it is 52 bool Deserialize(void* buf, size_t buf_size);
52 // <= GetSerializedSize()? If so, should this validation happen all the
53 // time?
54 // - Deserialize() will CHECK-fail if you try to deserialize something with
55 // a bad offset, etc. For IPC, we |Validate()| before running
56 // deserialization if we want safety, but we probably want a recoverable
57 // error for this API.
58 // - What's the validation story?
59 void Deserialize(void* buf);
60 53
61 {% if struct|is_cloneable_kind %} 54 {% if struct|is_cloneable_kind %}
62 {{struct.name}}Ptr Clone() const; 55 {{struct.name}}Ptr Clone() const;
63 {%- endif %} 56 {%- endif %}
64 bool Equals(const {{struct.name}}& other) const; 57 bool Equals(const {{struct.name}}& other) const;
65 58
66 {#--- Struct members #} 59 {#--- Struct members #}
67 {% for field in struct.fields %} 60 {% for field in struct.fields %}
68 {%- set type = field.kind|cpp_wrapper_type %} 61 {%- set type = field.kind|cpp_wrapper_type %}
69 {%- set name = field.name %} 62 {%- set name = field.name %}
70 {{type}} {{name}}; 63 {{type}} {{name}};
71 {%- endfor %} 64 {%- endfor %}
72 }; 65 };
73 66
74 {#--- Enum Operators #} 67 {#--- Enum Operators #}
75 {% from "enum_macros.tmpl" import global_enum_operators_decl -%} 68 {% from "enum_macros.tmpl" import global_enum_operators_decl -%}
76 {%- for enum in struct.enums %} 69 {%- for enum in struct.enums %}
77 {{global_enum_operators_decl(enum, class_name=struct.name)}} 70 {{global_enum_operators_decl(enum, class_name=struct.name)}}
78 {%- endfor %} 71 {%- endfor %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698