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

Unified Diff: third_party/mojo/src/mojo/public/tools/bindings/generators/go_templates/struct.tmpl

Issue 1019173002: Update mojo sdk to rev 7214b7ec7d27563b2666afad86cf1c5895c56c18 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Keep permission service alive if embedder drops requests Created 5 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 side-by-side diff with in-line comments
Download patch
Index: third_party/mojo/src/mojo/public/tools/bindings/generators/go_templates/struct.tmpl
diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/go_templates/struct.tmpl b/third_party/mojo/src/mojo/public/tools/bindings/generators/go_templates/struct.tmpl
index 457e33946e76de12d39ab3af1bc7a5510c46b8a1..27f91aed42a91a15a628a10aa78b0e0df3ff3bb5 100644
--- a/third_party/mojo/src/mojo/public/tools/bindings/generators/go_templates/struct.tmpl
+++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/go_templates/struct.tmpl
@@ -23,18 +23,32 @@ func (s *{{struct|name(exported)}}) Encode(encoder *bindings.Encoder) error {
return nil
}
+var {{struct|name(False)}}_Versions []bindings.DataHeader = []bindings.DataHeader{
+{% for versionInfo in struct.versions %}
+ bindings.DataHeader{{'{'}}{{versionInfo.num_bytes}}, {{versionInfo.version}}{{'}'}},
+{% endfor %}
+}
+
func (s *{{struct|name(exported)}}) Decode(decoder *bindings.Decoder) error {
-{% if struct.bytes %}
- version, err := decoder.StartStruct()
-{% else %}
- _, err := decoder.StartStruct()
-{% endif %}
+ header, err := decoder.StartStruct()
if err != nil {
return err
}
+ index := sort.Search(len({{struct|name(False)}}_Versions), func(i int) bool {
+ return {{struct|name(False)}}_Versions[i].ElementsOrVersion >= header.ElementsOrVersion
+ })
+ if index < len({{struct|name(False)}}_Versions) {
+ if {{struct|name(False)}}_Versions[index].ElementsOrVersion > header.ElementsOrVersion {
+ index--
+ }
+ expectedSize := {{struct|name(False)}}_Versions[index].Size
+ if expectedSize != header.Size {
+ return fmt.Errorf("invalid struct header size: should be %d, but was %d", expectedSize, header.Size)
+ }
+ }
{% for byte in struct.bytes %}
{% for packed_field in byte.packed_fields %}
- if version >= {{packed_field.min_version}} {
+ if header.ElementsOrVersion >= {{packed_field.min_version}} {
{{decode('s.'~packed_field.field|name(exported), packed_field.field.kind)|tab_indent(2)}}
}
{% endfor %}

Powered by Google App Engine
This is Rietveld 408576698