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

Side by Side Diff: mojom/mojom_parser/serialization/serialization.go

Issue 1781643003: Mojom parser: Use Encoder.SetDeterministic(true) for stable encodings. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: New sha1s 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 package serialization 5 package serialization
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "mojo/public/go/bindings" 9 "mojo/public/go/bindings"
10 "mojom/mojom_parser/generated/mojom_files" 10 "mojom/mojom_parser/generated/mojom_files"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 saveEmitLineAndColumnNumbers := emitLineAndColumnNumbers 45 saveEmitLineAndColumnNumbers := emitLineAndColumnNumbers
46 emitLineAndColumnNumbers = emitLineAndColumnNumbersParam 46 emitLineAndColumnNumbers = emitLineAndColumnNumbersParam
47 saveEmitSerializedRuntimeTypeInfo := emitSerializedRuntimeTypeInfo 47 saveEmitSerializedRuntimeTypeInfo := emitSerializedRuntimeTypeInfo
48 emitSerializedRuntimeTypeInfo = emitSerializedRuntimeTypeInfoParam 48 emitSerializedRuntimeTypeInfo = emitSerializedRuntimeTypeInfoParam
49 49
50 fileGraph := translateDescriptor(d) 50 fileGraph := translateDescriptor(d)
51 if debug { 51 if debug {
52 debugString = myfmt.Sprintf("%#v", fileGraph) 52 debugString = myfmt.Sprintf("%#v", fileGraph)
53 } 53 }
54 encoder := bindings.NewEncoder() 54 encoder := bindings.NewEncoder()
55 encoder.SetDeterministic(true)
55 fileGraph.Encode(encoder) 56 fileGraph.Encode(encoder)
56 bytes, _, err = encoder.Data() 57 bytes, _, err = encoder.Data()
57 58
58 emitLineAndColumnNumbers = saveEmitLineAndColumnNumbers 59 emitLineAndColumnNumbers = saveEmitLineAndColumnNumbers
59 emitSerializedRuntimeTypeInfo = saveEmitSerializedRuntimeTypeInfo 60 emitSerializedRuntimeTypeInfo = saveEmitSerializedRuntimeTypeInfo
60 return 61 return
61 } 62 }
62 63
63 // translateDescriptor translates from a mojom.MojomDescriptor (the pure Go 64 // translateDescriptor translates from a mojom.MojomDescriptor (the pure Go
64 // representation used by the parser) to a mojom_files.MojomFileGraph (the 65 // representation used by the parser) to a mojom_files.MojomFileGraph (the
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 201 }
201 } 202 }
202 203
203 // TODO(rudominer) Do we need the EmbeddedEnums and EmbeddedConstants 204 // TODO(rudominer) Do we need the EmbeddedEnums and EmbeddedConstants
204 // fields in KeysByType. It seems these fields are not currently being 205 // fields in KeysByType. It seems these fields are not currently being
205 // used in mojom_translator.py. 206 // used in mojom_translator.py.
206 207
207 // SerializedRuntimeTypeInfo 208 // SerializedRuntimeTypeInfo
208 if emitSerializedRuntimeTypeInfo { 209 if emitSerializedRuntimeTypeInfo {
209 encoder := bindings.NewEncoder() 210 encoder := bindings.NewEncoder()
211 encoder.SetDeterministic(true)
210 typeInfo.Encode(encoder) 212 typeInfo.Encode(encoder)
211 bytes, _, err := encoder.Data() 213 bytes, _, err := encoder.Data()
212 if err != nil { 214 if err != nil {
213 panic(fmt.Sprintf("Error while serializing runtimeTypeIn fo: %s", err.Error())) 215 panic(fmt.Sprintf("Error while serializing runtimeTypeIn fo: %s", err.Error()))
214 } 216 }
215 file.SerializedRuntimeTypeInfo = &bytes 217 file.SerializedRuntimeTypeInfo = &bytes
216 } 218 }
217 219
218 return 220 return
219 } 221 }
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 673
672 // stringPointer is a convenience function for creating a pointer to a string wh ose value 674 // stringPointer is a convenience function for creating a pointer to a string wh ose value
673 // is the specified string. It may be used in situations where the compiler will 675 // is the specified string. It may be used in situations where the compiler will
674 // not allow you to take the address of a string value directly, such as the 676 // not allow you to take the address of a string value directly, such as the
675 // return value of a function. It is necessary to create pointers to strings bec ause 677 // return value of a function. It is necessary to create pointers to strings bec ause
676 // that is how the Mojom type |string?| (i.e. nullable string) is represented in 678 // that is how the Mojom type |string?| (i.e. nullable string) is represented in
677 // in the Mojom Go bindings. 679 // in the Mojom Go bindings.
678 func stringPointer(s string) *string { 680 func stringPointer(s string) *string {
679 return &s 681 return &s
680 } 682 }
OLDNEW
« no previous file with comments | « mojom/mojom_parser/generated/mojom_types/mojom_types.mojom.go ('k') | mojom/mojom_parser/serialization/serialization_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698