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

Side by Side Diff: mojom/generators/c/templates/struct.tmpl.go

Issue 2163793002: C bindings: Implement _Validate(), and some pre-requisites (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: address comments Created 4 years, 4 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 templates 5 package templates
6 6
7 const GenerateStructDeclarations = ` 7 const GenerateStructDeclarations = `
8 {{- /* . (dot) refers to the Go type |cgen.StructTemplate| */ -}} 8 {{- /* . (dot) refers to the Go type |cgen.StructTemplate| */ -}}
9 {{define "GenerateStructDeclarations" -}} 9 {{define "GenerateStructDeclarations" -}}
10 {{- $struct := . -}} 10 {{- $struct := . -}}
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 const struct {{$struct.Name}}* in_data); 44 const struct {{$struct.Name}}* in_data);
45 45
46 void {{$struct.Name}}_EncodePointersAndHandles( 46 void {{$struct.Name}}_EncodePointersAndHandles(
47 struct {{$struct.Name}}* inout_struct, uint32_t in_struct_size, 47 struct {{$struct.Name}}* inout_struct, uint32_t in_struct_size,
48 struct MojomHandleBuffer* inout_handle_buffer); 48 struct MojomHandleBuffer* inout_handle_buffer);
49 49
50 void {{$struct.Name}}_DecodePointersAndHandles( 50 void {{$struct.Name}}_DecodePointersAndHandles(
51 struct {{$struct.Name}}* inout_struct, uint32_t in_struct_size, 51 struct {{$struct.Name}}* inout_struct, uint32_t in_struct_size,
52 MojoHandle inout_handles[], uint32_t in_num_handles); 52 MojoHandle inout_handles[], uint32_t in_num_handles);
53 53
54 MojomValidationResult {{$struct.Name}}_Validate(
55 const struct {{$struct.Name}}* in_struct, uint32_t in_struct_size,
56 uint32_t in_num_handles);
57
54 {{end}} 58 {{end}}
55 ` 59 `
56 60
57 // TODO(vardhan): Move other struct constant definitions in here. 61 // TODO(vardhan): Move other struct constant definitions in here.
58 const GenerateStructDefinitions = ` 62 const GenerateStructDefinitions = `
59 {{- /* . (dot) refers to the Go type |cgen.StructTemplate| */ -}} 63 {{- /* . (dot) refers to the Go type |cgen.StructTemplate| */ -}}
60 {{define "GenerateStructDefinitions" -}} 64 {{define "GenerateStructDefinitions" -}}
61 {{- $struct := . -}} 65 {{- $struct := . -}}
62 66
63 {{range $const := $struct.Constants -}} 67 {{range $const := $struct.Constants -}}
(...skipping 18 matching lines...) Expand all
82 86
83 void {{$struct.Name}}_DecodePointersAndHandles( 87 void {{$struct.Name}}_DecodePointersAndHandles(
84 struct {{$struct.Name}}* inout_struct, uint32_t in_struct_size, 88 struct {{$struct.Name}}* inout_struct, uint32_t in_struct_size,
85 MojoHandle inout_handles[], uint32_t in_num_handles) { 89 MojoHandle inout_handles[], uint32_t in_num_handles) {
86 MojomStruct_DecodePointersAndHandles( 90 MojomStruct_DecodePointersAndHandles(
87 &{{$struct.Name}}__TypeDesc, 91 &{{$struct.Name}}__TypeDesc,
88 (struct MojomStructHeader*)inout_struct, in_struct_size, 92 (struct MojomStructHeader*)inout_struct, in_struct_size,
89 inout_handles, in_num_handles); 93 inout_handles, in_num_handles);
90 } 94 }
91 95
96 MojomValidationResult {{$struct.Name}}_Validate(
97 const struct {{$struct.Name}}* in_struct, uint32_t in_struct_size,
98 uint32_t in_num_handles) {
99 struct MojomValidationContext context = {
100 .next_handle_index = 0,
101 .next_pointer = (char*)in_struct + in_struct->header_.num_bytes,
102 };
103 return MojomStruct_Validate(
104 &{{$struct.Name}}__TypeDesc,
105 (struct MojomStructHeader*)in_struct, in_struct_size, in_num_handles,
106 &context);
107 }
108
92 {{end}} 109 {{end}}
93 ` 110 `
OLDNEW
« no previous file with comments | « mojom/generators/c/templates/interface.tmpl.go ('k') | mojom/generators/c/templates/type_table.tmpl.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698