| 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 "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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 301 |
| 302 func translateTypeRef(typeRef mojom.TypeRef) mojom_types.Type { | 302 func translateTypeRef(typeRef mojom.TypeRef) mojom_types.Type { |
| 303 switch t := typeRef.(type) { | 303 switch t := typeRef.(type) { |
| 304 case mojom.SimpleType: | 304 case mojom.SimpleType: |
| 305 return translateSimpleType(t) | 305 return translateSimpleType(t) |
| 306 case mojom.StringType: | 306 case mojom.StringType: |
| 307 return translateStringType(t) | 307 return translateStringType(t) |
| 308 case mojom.HandleTypeRef: | 308 case mojom.HandleTypeRef: |
| 309 return translateHandleType(t) | 309 return translateHandleType(t) |
| 310 case mojom.ArrayTypeRef: | 310 case mojom.ArrayTypeRef: |
| 311 return translateArrayType(&t) |
| 312 case *mojom.ArrayTypeRef: |
| 311 return translateArrayType(t) | 313 return translateArrayType(t) |
| 312 case mojom.MapTypeRef: | 314 case mojom.MapTypeRef: |
| 315 return translateMapType(&t) |
| 316 case *mojom.MapTypeRef: |
| 313 return translateMapType(t) | 317 return translateMapType(t) |
| 314 case *mojom.UserTypeRef: | 318 case *mojom.UserTypeRef: |
| 315 return translateUserTypeRef(t) | 319 return translateUserTypeRef(t) |
| 316 default: | 320 default: |
| 317 panic(fmt.Sprintf("Unexpected TypeRef type %T", t)) | 321 panic(fmt.Sprintf("Unexpected TypeRef type %T", t)) |
| 318 } | 322 } |
| 319 } | 323 } |
| 320 | 324 |
| 321 func translateSimpleType(simpleType mojom.SimpleType) *mojom_types.TypeSimpleTyp
e { | 325 func translateSimpleType(simpleType mojom.SimpleType) *mojom_types.TypeSimpleTyp
e { |
| 322 var value mojom_types.SimpleType | 326 var value mojom_types.SimpleType |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 case mojom.HandleKindDataPipeConsumer: | 365 case mojom.HandleKindDataPipeConsumer: |
| 362 kind = mojom_types.HandleType_Kind_DataPipeConsumer | 366 kind = mojom_types.HandleType_Kind_DataPipeConsumer |
| 363 case mojom.HandleKindDataPipeProducer: | 367 case mojom.HandleKindDataPipeProducer: |
| 364 kind = mojom_types.HandleType_Kind_DataPipeProducer | 368 kind = mojom_types.HandleType_Kind_DataPipeProducer |
| 365 case mojom.HandleKindSharedBuffer: | 369 case mojom.HandleKindSharedBuffer: |
| 366 kind = mojom_types.HandleType_Kind_SharedBuffer | 370 kind = mojom_types.HandleType_Kind_SharedBuffer |
| 367 } | 371 } |
| 368 return &mojom_types.TypeHandleType{mojom_types.HandleType{handleType.Nul
lable(), kind}} | 372 return &mojom_types.TypeHandleType{mojom_types.HandleType{handleType.Nul
lable(), kind}} |
| 369 } | 373 } |
| 370 | 374 |
| 371 func translateArrayType(arrayType mojom.ArrayTypeRef) *mojom_types.TypeArrayType
{ | 375 func translateArrayType(arrayType *mojom.ArrayTypeRef) *mojom_types.TypeArrayTyp
e { |
| 372 return &mojom_types.TypeArrayType{mojom_types.ArrayType{ | 376 return &mojom_types.TypeArrayType{mojom_types.ArrayType{ |
| 373 Nullable: arrayType.Nullable(), | 377 Nullable: arrayType.Nullable(), |
| 374 FixedLength: int32(arrayType.FixedLength()), | 378 FixedLength: int32(arrayType.FixedLength()), |
| 375 ElementType: translateTypeRef(arrayType.ElementType())}} | 379 ElementType: translateTypeRef(arrayType.ElementType())}} |
| 376 } | 380 } |
| 377 | 381 |
| 378 func translateMapType(mapType mojom.MapTypeRef) *mojom_types.TypeMapType { | 382 func translateMapType(mapType *mojom.MapTypeRef) *mojom_types.TypeMapType { |
| 379 return &mojom_types.TypeMapType{mojom_types.MapType{ | 383 return &mojom_types.TypeMapType{mojom_types.MapType{ |
| 380 Nullable: mapType.Nullable(), | 384 Nullable: mapType.Nullable(), |
| 381 KeyType: translateTypeRef(mapType.KeyType()), | 385 KeyType: translateTypeRef(mapType.KeyType()), |
| 382 ValueType: translateTypeRef(mapType.ValueType())}} | 386 ValueType: translateTypeRef(mapType.ValueType())}} |
| 383 } | 387 } |
| 384 | 388 |
| 385 func translateUserTypeRef(userType *mojom.UserTypeRef) *mojom_types.TypeTypeRefe
rence { | 389 func translateUserTypeRef(userType *mojom.UserTypeRef) *mojom_types.TypeTypeRefe
rence { |
| 386 typeKey := stringPointer(userType.ResolvedType().TypeKey()) | 390 typeKey := stringPointer(userType.ResolvedType().TypeKey()) |
| 387 identifier := stringPointer(userType.Identifier()) | 391 identifier := stringPointer(userType.Identifier()) |
| 388 return &mojom_types.TypeTypeReference{mojom_types.TypeReference{ | 392 return &mojom_types.TypeTypeReference{mojom_types.TypeReference{ |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 | 558 |
| 555 // stringPointer is a convenience function for creating a pointer to a string wh
ose value | 559 // stringPointer is a convenience function for creating a pointer to a string wh
ose value |
| 556 // is the specified string. It may be used in situations where the compiler will | 560 // is the specified string. It may be used in situations where the compiler will |
| 557 // not allow you to take the address of a string value directly, such as the | 561 // not allow you to take the address of a string value directly, such as the |
| 558 // return value of a function. It is necessary to create pointers to strings bec
ause | 562 // return value of a function. It is necessary to create pointers to strings bec
ause |
| 559 // that is how the Mojom type |string?| (i.e. nullable string) is represented in | 563 // that is how the Mojom type |string?| (i.e. nullable string) is represented in |
| 560 // in the Mojom Go bindings. | 564 // in the Mojom Go bindings. |
| 561 func stringPointer(s string) *string { | 565 func stringPointer(s string) *string { |
| 562 return &s | 566 return &s |
| 563 } | 567 } |
| OLD | NEW |