| OLD | NEW |
| 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 package serialization | 5 package serialization |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" |
| 9 "compress/gzip" |
| 10 "encoding/base64" |
| 8 "fmt" | 11 "fmt" |
| 9 "mojo/public/go/bindings" | 12 "mojo/public/go/bindings" |
| 10 "mojom/mojom_parser/generated/mojom_files" | 13 "mojom/mojom_parser/generated/mojom_files" |
| 11 "mojom/mojom_parser/generated/mojom_types" | 14 "mojom/mojom_parser/generated/mojom_types" |
| 12 "mojom/mojom_parser/mojom" | 15 "mojom/mojom_parser/mojom" |
| 13 myfmt "third_party/golang/src/fmt" | 16 myfmt "third_party/golang/src/fmt" |
| 14 ) | 17 ) |
| 15 | 18 |
| 16 ////////////////////////////////////////////////// | 19 ////////////////////////////////////////////////// |
| 17 /// Mojom Descriptor Serialization | 20 /// Mojom Descriptor Serialization |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 206 |
| 204 // TODO(rudominer) Do we need the EmbeddedEnums and EmbeddedConstants | 207 // TODO(rudominer) Do we need the EmbeddedEnums and EmbeddedConstants |
| 205 // fields in KeysByType. It seems these fields are not currently being | 208 // fields in KeysByType. It seems these fields are not currently being |
| 206 // used in mojom_translator.py. | 209 // used in mojom_translator.py. |
| 207 | 210 |
| 208 // SerializedRuntimeTypeInfo | 211 // SerializedRuntimeTypeInfo |
| 209 if emitSerializedRuntimeTypeInfo { | 212 if emitSerializedRuntimeTypeInfo { |
| 210 encoder := bindings.NewEncoder() | 213 encoder := bindings.NewEncoder() |
| 211 encoder.SetDeterministic(true) | 214 encoder.SetDeterministic(true) |
| 212 typeInfo.Encode(encoder) | 215 typeInfo.Encode(encoder) |
| 213 » » bytes, _, err := encoder.Data() | 216 » » byteSlice, _, err := encoder.Data() |
| 214 if err != nil { | 217 if err != nil { |
| 215 panic(fmt.Sprintf("Error while serializing runtimeTypeIn
fo: %s", err.Error())) | 218 panic(fmt.Sprintf("Error while serializing runtimeTypeIn
fo: %s", err.Error())) |
| 216 } | 219 } |
| 217 » » file.SerializedRuntimeTypeInfo = &bytes | 220 » » var compressedBytes bytes.Buffer |
| 221 » » gzipWriter, _ := gzip.NewWriterLevel(&compressedBytes, gzip.Best
Compression) |
| 222 » » _, err = gzipWriter.Write(byteSlice) |
| 223 » » if err != nil { |
| 224 » » » panic(fmt.Sprintf("Error while gzipping runtimeTypeInfo:
%s", err.Error())) |
| 225 » » } |
| 226 » » err = gzipWriter.Close() |
| 227 » » if err != nil { |
| 228 » » » panic(fmt.Sprintf("Error while gzipping runtimeTypeInfo:
%s", err.Error())) |
| 229 » » } |
| 230 » » byteSlice = compressedBytes.Bytes() |
| 231 » » encoded := base64.StdEncoding.EncodeToString(byteSlice) |
| 232 » » file.SerializedRuntimeTypeInfo = &encoded |
| 218 } | 233 } |
| 219 | 234 |
| 220 return | 235 return |
| 221 } | 236 } |
| 222 | 237 |
| 223 // addServiceTypeInfo will add a ServiceTypeInfo to the ServicesByName field of
|typeInfo| corresponding | 238 // addServiceTypeInfo will add a ServiceTypeInfo to the ServicesByName field of
|typeInfo| corresponding |
| 224 // to |intrfc| if |intrfc| is a top-level interface, meaning that it has a non-n
il service name. In that | 239 // to |intrfc| if |intrfc| is a top-level interface, meaning that it has a non-n
il service name. In that |
| 225 // case this method returns true. Otherwise this method will do nothing and retu
rn fals. | 240 // case this method returns true. Otherwise this method will do nothing and retu
rn fals. |
| 226 func addServiceTypeInfo(intrfc *mojom.MojomInterface, typeInfo *mojom_types.Runt
imeTypeInfo) (isTopLevel bool) { | 241 func addServiceTypeInfo(intrfc *mojom.MojomInterface, typeInfo *mojom_types.Runt
imeTypeInfo) (isTopLevel bool) { |
| 227 isTopLevel = intrfc.ServiceName != nil | 242 isTopLevel = intrfc.ServiceName != nil |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 | 688 |
| 674 // stringPointer is a convenience function for creating a pointer to a string wh
ose value | 689 // stringPointer is a convenience function for creating a pointer to a string wh
ose value |
| 675 // is the specified string. It may be used in situations where the compiler will | 690 // is the specified string. It may be used in situations where the compiler will |
| 676 // not allow you to take the address of a string value directly, such as the | 691 // not allow you to take the address of a string value directly, such as the |
| 677 // return value of a function. It is necessary to create pointers to strings bec
ause | 692 // return value of a function. It is necessary to create pointers to strings bec
ause |
| 678 // that is how the Mojom type |string?| (i.e. nullable string) is represented in | 693 // that is how the Mojom type |string?| (i.e. nullable string) is represented in |
| 679 // in the Mojom Go bindings. | 694 // in the Mojom Go bindings. |
| 680 func stringPointer(s string) *string { | 695 func stringPointer(s string) *string { |
| 681 return &s | 696 return &s |
| 682 } | 697 } |
| OLD | NEW |