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

Side by Side Diff: mojo/public/tools/bindings/generators/go_templates/source.tmpl

Issue 1776243004: Mojom runtime type info: Use compression and base64 encoding. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebasing 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file is autogenerated by: 5 // This file is autogenerated by:
6 // mojo/public/tools/bindings/mojom_bindings_generator.py 6 // mojo/public/tools/bindings/mojom_bindings_generator.py
7 // For: 7 // For:
8 // {{module.path}} 8 // {{module.path}}
9 // 9 //
10 10
(...skipping 12 matching lines...) Expand all
23 23
24 {%- if should_gen_mojom_types -%} 24 {%- if should_gen_mojom_types -%}
25 // This global variable contains a mojom_types.RuntimeTypeInfo struct 25 // This global variable contains a mojom_types.RuntimeTypeInfo struct
26 // describing the types defined in this file and all of its imports as 26 // describing the types defined in this file and all of its imports as
27 // well as the top-level interfaces defined in this file. 27 // well as the top-level interfaces defined in this file.
28 var runtimeTypeInfo__ = {{typepkg}}RuntimeTypeInfo{} 28 var runtimeTypeInfo__ = {{typepkg}}RuntimeTypeInfo{}
29 29
30 func init() { 30 func init() {
31 // serializedRuntimeTypeInfo contains the bytes of the Mojo serialization of 31 // serializedRuntimeTypeInfo contains the bytes of the Mojo serialization of
32 // a mojom_types.RuntimeTypeInfo struct describing the Mojom types in this fil e. 32 // a mojom_types.RuntimeTypeInfo struct describing the Mojom types in this fil e.
33 serializedRuntimeTypeInfo := []uint8{{serialized_runtime_type_info_literal}} 33 // The string contains the base64 encoding of the gzip-compressed bytes.
34 serializedRuntimeTypeInfo := "{{module.serialized_runtime_type_info}}"
34 35
35 // Deserialize RuntimeTypeInfo 36 // Deserialize RuntimeTypeInfo
36 decoder := bindings.NewDecoder(serializedRuntimeTypeInfo, nil) 37 compressedBytes, err := base64.StdEncoding.DecodeString(serializedRuntimeTypeI nfo)
38 if err != nil {
39 {# TODO(rudominer) Move this out of init() and do it lazily. Then
40 we should panic here. #}
41 return
42 }
43
44 reader, err2 := gzip.NewReader(bytes.NewBuffer(compressedBytes))
45 if err2 != nil {
46 panic(fmt.Sprintf("Error while decompressing runtimeTypeInfo: %s", err.Error ()))
47 }
48 uncompressedBytes, err3 := ioutil.ReadAll(reader)
49 if err3 != nil {
50 {# TODO(rudominer) Move this out of init() and do it lazily. Then
51 we should panic here. #}
52 return
53 }
54 if err = reader.Close(); err != nil {
55 {# TODO(rudominer) Move this out of init() and do it lazily. Then
56 we should panic here. #}
57 return
58 }
59 decoder := bindings.NewDecoder(uncompressedBytes, nil)
37 runtimeTypeInfo__.Decode(decoder) 60 runtimeTypeInfo__.Decode(decoder)
38 61
39 {% for mi in mojom_imports.values() %} 62 {% for mi in mojom_imports.values() %}
40 {%- if mi ~ '.' != typepkg and mi ~ '.' != descpkg %} 63 {%- if mi ~ '.' != typepkg and mi ~ '.' != descpkg %}
41 for s, udt := range {{mi}}.GetAllMojomTypeDefinitions() { 64 for s, udt := range {{mi}}.GetAllMojomTypeDefinitions() {
42 runtimeTypeInfo__.TypeMap[s] = udt 65 runtimeTypeInfo__.TypeMap[s] = udt
43 } 66 }
44 67
45 68
46 {% endif -%} 69 {% endif -%}
(...skipping 16 matching lines...) Expand all
63 86
64 {#- Struct definitions #} 87 {#- Struct definitions #}
65 {% for struct in structs %} 88 {% for struct in structs %}
66 {{struct_macros.define(struct, typepkg, package)}} 89 {{struct_macros.define(struct, typepkg, package)}}
67 {%- endfor %} 90 {%- endfor %}
68 91
69 {#- Union definitions #} 92 {#- Union definitions #}
70 {% for union in unions %} 93 {% for union in unions %}
71 {{union_macros.define(union, typepkg, package)}} 94 {{union_macros.define(union, typepkg, package)}}
72 {%- endfor %} 95 {%- endfor %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698