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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/generators/go_templates/source.tmpl
diff --git a/mojo/public/tools/bindings/generators/go_templates/source.tmpl b/mojo/public/tools/bindings/generators/go_templates/source.tmpl
index 7d79831bd8c20d6e6c8e66e074a8a91b00e7ca49..af8661c4dd2b6239cb811799b4bf5e6e395255c5 100644
--- a/mojo/public/tools/bindings/generators/go_templates/source.tmpl
+++ b/mojo/public/tools/bindings/generators/go_templates/source.tmpl
@@ -30,10 +30,33 @@ var runtimeTypeInfo__ = {{typepkg}}RuntimeTypeInfo{}
func init() {
// serializedRuntimeTypeInfo contains the bytes of the Mojo serialization of
// a mojom_types.RuntimeTypeInfo struct describing the Mojom types in this file.
- serializedRuntimeTypeInfo := []uint8{{serialized_runtime_type_info_literal}}
+ // The string contains the base64 encoding of the gzip-compressed bytes.
+ serializedRuntimeTypeInfo := "{{module.serialized_runtime_type_info}}"
// Deserialize RuntimeTypeInfo
- decoder := bindings.NewDecoder(serializedRuntimeTypeInfo, nil)
+ compressedBytes, err := base64.StdEncoding.DecodeString(serializedRuntimeTypeInfo)
+ if err != nil {
+ {# TODO(rudominer) Move this out of init() and do it lazily. Then
+ we should panic here. #}
+ return
+ }
+
+ reader, err2 := gzip.NewReader(bytes.NewBuffer(compressedBytes))
+ if err2 != nil {
+ panic(fmt.Sprintf("Error while decompressing runtimeTypeInfo: %s", err.Error()))
+ }
+ uncompressedBytes, err3 := ioutil.ReadAll(reader)
+ if err3 != nil {
+ {# TODO(rudominer) Move this out of init() and do it lazily. Then
+ we should panic here. #}
+ return
+ }
+ if err = reader.Close(); err != nil {
+ {# TODO(rudominer) Move this out of init() and do it lazily. Then
+ we should panic here. #}
+ return
+ }
+ decoder := bindings.NewDecoder(uncompressedBytes, nil)
runtimeTypeInfo__.Decode(decoder)
{% for mi in mojom_imports.values() %}

Powered by Google App Engine
This is Rietveld 408576698