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

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

Issue 1421193003: New Mojom Parser: Serialization. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Use revered fqn for type keys. Make line numbers optional. Created 5 years, 1 month 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 mojom 5 package mojom
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 ) 9 )
10 10
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 } 467 }
468 468
469 /////////////////////////////////////////////////////////////////////// 469 ///////////////////////////////////////////////////////////////////////
470 /// Miscelleneous utilities 470 /// Miscelleneous utilities
471 /// ////////////////////////////////////////////////////////////////// 471 /// //////////////////////////////////////////////////////////////////
472 472
473 func computeTypeKey(fullyQualifiedName string) (typeKey string) { 473 func computeTypeKey(fullyQualifiedName string) (typeKey string) {
474 if typeKey, ok := fqnToTypeKey[fullyQualifiedName]; ok == true { 474 if typeKey, ok := fqnToTypeKey[fullyQualifiedName]; ok == true {
475 return typeKey 475 return typeKey
476 } 476 }
477 » typeKey = fmt.Sprintf("%d", nextKey) 477 » // TODO(rudominer) Until we understand better what the requirements are for a type key
478 » nextKey++ 478 » // let's just use the reversed fully-qualified name as the type key. The reason
479 » // for the reversal is pragmatic: When debugging we can tell whether a s tring
480 » // is a type key or a fully-qualified-name
481 » numBytes := len(fullyQualifiedName)
482 » reversed := make([]byte, numBytes)
483 » for i := 0; i < numBytes; i++ {
484 » » reversed[i] = fullyQualifiedName[numBytes-i-1]
485 » }
486 » typeKey = string(reversed)
479 fqnToTypeKey[fullyQualifiedName] = typeKey 487 fqnToTypeKey[fullyQualifiedName] = typeKey
480 return 488 return
481 } 489 }
482 490
483 var fqnToTypeKey map[string]string 491 var fqnToTypeKey map[string]string
484 var nextKey int
485 492
486 func init() { 493 func init() {
487 fqnToTypeKey = make(map[string]string) 494 fqnToTypeKey = make(map[string]string)
488 } 495 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698