From eb94f057ed805964e90597ef8e6b38bcb4c04bdc Mon Sep 17 00:00:00 2001 From: Pascal Perez <pascallouis@google.com> Date: Tue, 26 Mar 2019 22:49:25 +0000 Subject: [PATCH] [fidlgen][go] Do not export request/response structs To bridge between function arguments/returns and encoding/decoding, the Go bindings generate request/response structs holdings the various argument/return values. However, developers should not interact which these, instead using method calls and receiving returns. With the introduction of the error syntax, the fidlc compiler creates a name for the struct holding the value, i.e. the first variant of the result union where the second is the error. The name for this struct is suffixed by "Response" which used to clash with the response struct mentioned above. By keeping the request/response struct private (unexported), we avoid this clash. (This does not solve the more general problem of name clashing -- nor does it try to.) FIDL-519 #comment Change-Id: I50767de8d4b3e2d2cfd1b4f7fd4585ead9a455fd --- .../src/fidl/compiler/backend/golang/ir/ir.go | 61 +- .../compiler/backend/golang/ir/ir_test.go | 8 +- .../backend/goldens/protocols.test.fidl.json | 373 +++++++-- .../protocols.test.fidl.json.cc.golden | 472 +++++++++++ .../protocols.test.fidl.json.go.golden | 603 ++++++++++---- .../goldens/protocols.test.fidl.json.h.golden | 348 +++++++- .../protocols.test.fidl.json.llcpp.cc.golden | 321 ++++++++ .../protocols.test.fidl.json.llcpp.h.golden | 312 +++++++ ....test.fidl.json.overnet_internal.cc.golden | 7 + ...s.test.fidl.json.overnet_internal.h.golden | 21 + .../protocols.test.fidl.json.rs.golden | 766 ++++++++++++++++++ ...rotocols.test.fidl.json_test_base.h.golden | 13 + .../backend/typestest/protocols.test.fidl | 10 + 13 files changed, 3054 insertions(+), 261 deletions(-) diff --git a/garnet/go/src/fidl/compiler/backend/golang/ir/ir.go b/garnet/go/src/fidl/compiler/backend/golang/ir/ir.go index c6d7ed26af4..0b892950f5a 100644 --- a/garnet/go/src/fidl/compiler/backend/golang/ir/ir.go +++ b/garnet/go/src/fidl/compiler/backend/golang/ir/ir.go @@ -582,12 +582,6 @@ var handleTypes = map[types.HandleSubtype]string{ types.Vmar: "_zx.VMAR", } -func exportIdentifier(name types.EncodedCompoundIdentifier) types.CompoundIdentifier { - ci := types.ParseCompoundIdentifier(name) - ci.Name = types.Identifier(common.ToUpperCamelCase(string(ci.Name))) - return ci -} - func isReservedWord(str string) bool { _, ok := reservedWords[str] return ok @@ -624,8 +618,13 @@ func (_ *compiler) compileIdentifier(id types.Identifier, export bool, ext strin return changeIfReserved(types.Identifier(str), ext) } -func (c *compiler) compileCompoundIdentifier(eci types.EncodedCompoundIdentifier, ext string) string { - ci := exportIdentifier(eci) +func (c *compiler) compileCompoundIdentifier(eci types.EncodedCompoundIdentifier, export bool, ext string) string { + ci := types.ParseCompoundIdentifier(eci) + if export { + ci.Name = types.Identifier(common.ToUpperCamelCase(string(ci.Name))) + } else { + ci.Name = types.Identifier(common.ToLowerCamelCase(string(ci.Name))) + } pkg := compileLibraryIdentifier(ci.Library) strs := []string{} if c.inExternalLibrary(ci) { @@ -707,7 +706,7 @@ func (c *compiler) compileType(val types.Type) (r Type, t Tag, t2 tagNew) { t2.reverseOfBounds = append(t2.reverseOfBounds, nullability) r = Type(e) case types.RequestType: - e := c.compileCompoundIdentifier(val.RequestSubtype, RequestSuffix) + e := c.compileCompoundIdentifier(val.RequestSubtype, true, RequestSuffix) var nullability int if val.Nullable { t.Nullable = true @@ -733,7 +732,7 @@ func (c *compiler) compileType(val types.Type) (r Type, t Tag, t2 tagNew) { case types.PrimitiveType: r = c.compilePrimitiveSubtype(val.PrimitiveSubtype) case types.IdentifierType: - e := c.compileCompoundIdentifier(val.Identifier, "") + e := c.compileCompoundIdentifier(val.Identifier, true, "") declType, ok := c.decls[val.Identifier] if !ok { log.Fatal("Unknown identifier: ", val.Identifier) @@ -781,7 +780,7 @@ func (c *compiler) compileBits(val types.Bits) Bits { t, _, _ := c.compileType(val.Type) r := Bits{ Attributes: val.Attributes, - Name: c.compileCompoundIdentifier(val.Name, ""), + Name: c.compileCompoundIdentifier(val.Name, true, ""), Type: t, } for _, v := range val.Members { @@ -796,7 +795,7 @@ func (c *compiler) compileConst(val types.Const) Const { t, _, _ := c.compileType(val.Type) return Const{ Attributes: val.Attributes, - Name: c.compileCompoundIdentifier(val.Name, ""), + Name: c.compileCompoundIdentifier(val.Name, true, ""), Type: t, Value: c.compileConstant(val.Value), } @@ -813,7 +812,7 @@ func (c *compiler) compileEnumMember(val types.EnumMember) EnumMember { func (c *compiler) compileEnum(val types.Enum) Enum { r := Enum{ Attributes: val.Attributes, - Name: c.compileCompoundIdentifier(val.Name, ""), + Name: c.compileCompoundIdentifier(val.Name, true, ""), Type: c.compilePrimitiveSubtype(val.Type), } for _, v := range val.Members { @@ -836,7 +835,7 @@ func (c *compiler) compileStructMember(val types.StructMember) StructMember { func (c *compiler) compileStruct(val types.Struct) Struct { r := Struct{ Attributes: val.Attributes, - Name: c.compileCompoundIdentifier(val.Name, ""), + Name: c.compileCompoundIdentifier(val.Name, true, ""), Size: val.Size, Alignment: val.Alignment, } @@ -862,8 +861,8 @@ func (c *compiler) compileUnionMember(unionName string, val types.UnionMember) U func (c *compiler) compileUnion(val types.Union) Union { r := Union{ Attributes: val.Attributes, - Name: c.compileCompoundIdentifier(val.Name, ""), - TagName: c.compileCompoundIdentifier(val.Name, TagSuffix), + Name: c.compileCompoundIdentifier(val.Name, true, ""), + TagName: c.compileCompoundIdentifier(val.Name, true, TagSuffix), Size: val.Size, Alignment: val.Alignment, } @@ -890,8 +889,8 @@ func (c *compiler) compileXUnion(val types.XUnion) XUnion { } return XUnion{ Attributes: val.Attributes, - Name: c.compileCompoundIdentifier(val.Name, ""), - TagName: c.compileCompoundIdentifier(val.Name, TagSuffix), + Name: c.compileCompoundIdentifier(val.Name, true, ""), + TagName: c.compileCompoundIdentifier(val.Name, true, TagSuffix), Size: val.Size, Alignment: val.Alignment, Members: members, @@ -926,7 +925,7 @@ func (c *compiler) compileTable(val types.Table) Table { } return Table{ Attributes: val.Attributes, - Name: c.compileCompoundIdentifier(val.Name, ""), + Name: c.compileCompoundIdentifier(val.Name, true, ""), Size: val.Size, Alignment: val.Alignment, Members: members, @@ -949,16 +948,16 @@ func (c *compiler) compileMethod(ifaceName types.EncodedCompoundIdentifier, val Attributes: val.Attributes, Name: methodName, Ordinal: val.Ordinal, - OrdinalName: c.compileCompoundIdentifier(ifaceName, methodName+"Ordinal"), + OrdinalName: c.compileCompoundIdentifier(ifaceName, true, methodName+"Ordinal"), GenOrdinal: val.GenOrdinal, - GenOrdinalName: c.compileCompoundIdentifier(ifaceName, methodName+"GenOrdinal"), + GenOrdinalName: c.compileCompoundIdentifier(ifaceName, true, methodName+"GenOrdinal"), EventExpectName: "Expect" + methodName, IsEvent: !val.HasRequest && val.HasResponse, IsTransitional: val.IsTransitional(), } if val.HasRequest { req := Struct{ - Name: c.compileCompoundIdentifier(ifaceName, methodName+"Request"), + Name: c.compileCompoundIdentifier(ifaceName, false, methodName+"Request"), // We want just the size of the parameter array as a struct, not // including the message header size. Size: val.RequestSize - MessageHeaderSize, @@ -970,7 +969,7 @@ func (c *compiler) compileMethod(ifaceName types.EncodedCompoundIdentifier, val } if val.HasResponse { resp := Struct{ - Name: c.compileCompoundIdentifier(ifaceName, methodName+"Response"), + Name: c.compileCompoundIdentifier(ifaceName, false, methodName+"Response"), // We want just the size of the parameter array as a struct, not // including the message header size. Size: val.ResponseSize - MessageHeaderSize, @@ -990,15 +989,15 @@ func (c *compiler) compileInterface(val types.Interface) Interface { } r := Interface{ Attributes: val.Attributes, - Name: c.compileCompoundIdentifier(val.Name, ""), - TransitionalBaseName: c.compileCompoundIdentifier(val.Name, TransitionalBaseSuffix), - ProxyName: c.compileCompoundIdentifier(val.Name, ProxySuffix), + Name: c.compileCompoundIdentifier(val.Name, true, ""), + TransitionalBaseName: c.compileCompoundIdentifier(val.Name, true, TransitionalBaseSuffix), + ProxyName: c.compileCompoundIdentifier(val.Name, true, ProxySuffix), ProxyType: proxyType, - StubName: c.compileCompoundIdentifier(val.Name, StubSuffix), - RequestName: c.compileCompoundIdentifier(val.Name, RequestSuffix), - EventProxyName: c.compileCompoundIdentifier(val.Name, EventProxySuffix), - ServerName: c.compileCompoundIdentifier(val.Name, ServiceSuffix), - ServiceNameConstant: c.compileCompoundIdentifier(val.Name, ServiceNameSuffix), + StubName: c.compileCompoundIdentifier(val.Name, true, StubSuffix), + RequestName: c.compileCompoundIdentifier(val.Name, true, RequestSuffix), + EventProxyName: c.compileCompoundIdentifier(val.Name, true, EventProxySuffix), + ServerName: c.compileCompoundIdentifier(val.Name, true, ServiceSuffix), + ServiceNameConstant: c.compileCompoundIdentifier(val.Name, true, ServiceNameSuffix), ServiceNameString: val.GetServiceName(), } for _, v := range val.Methods { diff --git a/garnet/go/src/fidl/compiler/backend/golang/ir/ir_test.go b/garnet/go/src/fidl/compiler/backend/golang/ir/ir_test.go index 38b5379b0cd..e574e43e21f 100644 --- a/garnet/go/src/fidl/compiler/backend/golang/ir/ir_test.go +++ b/garnet/go/src/fidl/compiler/backend/golang/ir/ir_test.go @@ -634,7 +634,7 @@ func TestCompileInterface(t *testing.T) { GenOrdinalName: "TestFirstGenOrdinal", Name: "First", Request: &Struct{ - Name: "TestFirstRequest", + Name: "testFirstRequest", Members: []StructMember{ { Name: "Value", @@ -654,7 +654,7 @@ func TestCompileInterface(t *testing.T) { GenOrdinalName: "TestSecondGenOrdinal", Name: "Second", Request: &Struct{ - Name: "TestSecondRequest", + Name: "testSecondRequest", Members: []StructMember{ { Name: "Value", @@ -665,7 +665,7 @@ func TestCompileInterface(t *testing.T) { Size: 16, }, Response: &Struct{ - Name: "TestSecondResponse", + Name: "testSecondResponse", Members: []StructMember{ { Name: "Value", @@ -727,7 +727,7 @@ func TestCompileInterface(t *testing.T) { GenOrdinalName: "TestFirstGenOrdinal", Name: "First", Response: &Struct{ - Name: "TestFirstResponse", + Name: "testFirstResponse", Members: []StructMember{ { Name: "Value", diff --git a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json index 3f246611a79..caa37664e79 100644 --- a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json +++ b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json @@ -4,7 +4,49 @@ "library_dependencies": [], "bits_declarations": [], "const_declarations": [], - "enum_declarations": [], + "enum_declarations": [ + { + "name": "test.name/ErrorEnun", + "location": { + "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", + "line": 14, + "column": 5 + }, + "type": "uint32", + "members": [ + { + "name": "ERR_FOO", + "location": { + "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", + "line": 15, + "column": 4 + }, + "value": { + "kind": "literal", + "literal": { + "kind": "numeric", + "value": "1" + } + } + }, + { + "name": "ERR_BAR", + "location": { + "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", + "line": 16, + "column": 4 + }, + "value": { + "kind": "literal", + "literal": { + "kind": "numeric", + "value": "2" + } + } + } + ] + } + ], "interface_declarations": [ { "name": "test.name/WithAndWithoutRequestResponse", @@ -256,11 +298,95 @@ } ] }, + { + "name": "test.name/WithErrorSyntax", + "location": { + "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", + "line": 19, + "column": 9 + }, + "methods": [ + { + "ordinal": 2069369145, + "generated_ordinal": 2069369145, + "name": "ErrorAsPrimitive", + "location": { + "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", + "line": 20, + "column": 4 + }, + "has_request": true, + "maybe_request": [], + "maybe_request_size": 16, + "maybe_request_alignment": 8, + "has_response": true, + "maybe_response": [ + { + "type": { + "kind": "identifier", + "identifier": "test.name/WithErrorSyntax_ErrorAsPrimitive_Result", + "nullable": false + }, + "name": "result", + "location": { + "filename": "generated", + "line": 18, + "column": 0 + }, + "size": 8, + "max_out_of_line": 0, + "alignment": 4, + "offset": 16, + "max_handles": 0 + } + ], + "maybe_response_size": 24, + "maybe_response_alignment": 8 + }, + { + "ordinal": 1284890143, + "generated_ordinal": 1284890143, + "name": "ErrorAsEnum", + "location": { + "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", + "line": 21, + "column": 4 + }, + "has_request": true, + "maybe_request": [], + "maybe_request_size": 16, + "maybe_request_alignment": 8, + "has_response": true, + "maybe_response": [ + { + "type": { + "kind": "identifier", + "identifier": "test.name/WithErrorSyntax_ErrorAsEnum_Result", + "nullable": false + }, + "name": "result", + "location": { + "filename": "generated", + "line": 25, + "column": 0 + }, + "size": 8, + "max_out_of_line": 0, + "alignment": 4, + "offset": 16, + "max_handles": 0 + } + ], + "maybe_response_size": 24, + "maybe_response_alignment": 8 + } + ] + }, { "name": "test.name/OvernetInternalProtocol", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 15, + "line": 25, "column": 9 }, "maybe_attributes": [ @@ -276,7 +402,7 @@ "name": "MethodA", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 16, + "line": 26, "column": 4 }, "has_request": true, @@ -289,7 +415,7 @@ "name": "a", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 16, + "line": 26, "column": 18 }, "size": 8, @@ -306,7 +432,7 @@ "name": "b", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 16, + "line": 26, "column": 27 }, "size": 8, @@ -326,7 +452,7 @@ "name": "EventA", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 17, + "line": 27, "column": 7 }, "has_request": false, @@ -340,7 +466,7 @@ "name": "a", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 17, + "line": 27, "column": 20 }, "size": 8, @@ -357,7 +483,7 @@ "name": "b", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 17, + "line": 27, "column": 29 }, "size": 8, @@ -376,7 +502,7 @@ "name": "MethodB", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 18, + "line": 28, "column": 4 }, "has_request": true, @@ -389,7 +515,7 @@ "name": "a", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 18, + "line": 28, "column": 18 }, "size": 8, @@ -406,7 +532,7 @@ "name": "b", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 18, + "line": 28, "column": 27 }, "size": 8, @@ -428,7 +554,7 @@ "name": "result", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 18, + "line": 28, "column": 40 }, "size": 8, @@ -447,7 +573,7 @@ "name": "test.name/SocketControlProtocol", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 22, + "line": 32, "column": 9 }, "maybe_attributes": [ @@ -463,7 +589,7 @@ "name": "MethodA", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 23, + "line": 33, "column": 4 }, "has_request": true, @@ -476,7 +602,7 @@ "name": "a", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 23, + "line": 33, "column": 18 }, "size": 8, @@ -493,7 +619,7 @@ "name": "b", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 23, + "line": 33, "column": 27 }, "size": 8, @@ -513,7 +639,7 @@ "name": "EventA", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 24, + "line": 34, "column": 7 }, "has_request": false, @@ -527,7 +653,7 @@ "name": "a", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 24, + "line": 34, "column": 20 }, "size": 8, @@ -544,7 +670,7 @@ "name": "b", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 24, + "line": 34, "column": 29 }, "size": 8, @@ -563,7 +689,7 @@ "name": "MethodB", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 25, + "line": 35, "column": 4 }, "has_request": true, @@ -576,7 +702,7 @@ "name": "a", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 25, + "line": 35, "column": 18 }, "size": 8, @@ -593,7 +719,7 @@ "name": "b", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 25, + "line": 35, "column": 27 }, "size": 8, @@ -615,7 +741,7 @@ "name": "result", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 25, + "line": 35, "column": 40 }, "size": 8, @@ -634,7 +760,7 @@ "name": "test.name/ChannelProtocol", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 29, + "line": 39, "column": 9 }, "maybe_attributes": [ @@ -650,7 +776,7 @@ "name": "MethodA", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 30, + "line": 40, "column": 4 }, "has_request": true, @@ -663,7 +789,7 @@ "name": "a", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 30, + "line": 40, "column": 18 }, "size": 8, @@ -680,7 +806,7 @@ "name": "b", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 30, + "line": 40, "column": 27 }, "size": 8, @@ -700,7 +826,7 @@ "name": "EventA", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 31, + "line": 41, "column": 7 }, "has_request": false, @@ -714,7 +840,7 @@ "name": "a", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 31, + "line": 41, "column": 20 }, "size": 8, @@ -731,7 +857,7 @@ "name": "b", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 31, + "line": 41, "column": 29 }, "size": 8, @@ -750,7 +876,7 @@ "name": "MethodB", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 32, + "line": 42, "column": 4 }, "has_request": true, @@ -763,7 +889,7 @@ "name": "a", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 32, + "line": 42, "column": 18 }, "size": 8, @@ -780,7 +906,7 @@ "name": "b", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 32, + "line": 42, "column": 27 }, "size": 8, @@ -802,7 +928,7 @@ "name": "result", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 32, + "line": 42, "column": 40 }, "size": 8, @@ -821,7 +947,7 @@ "name": "test.name/KitchenSink", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 37, + "line": 47, "column": 9 }, "maybe_attributes": [ @@ -837,7 +963,7 @@ "name": "MethodA", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 38, + "line": 48, "column": 4 }, "has_request": true, @@ -850,7 +976,7 @@ "name": "a", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 38, + "line": 48, "column": 18 }, "size": 8, @@ -867,7 +993,7 @@ "name": "b", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 38, + "line": 48, "column": 27 }, "size": 8, @@ -887,7 +1013,7 @@ "name": "EventA", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 39, + "line": 49, "column": 7 }, "has_request": false, @@ -901,7 +1027,7 @@ "name": "a", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 39, + "line": 49, "column": 20 }, "size": 8, @@ -918,7 +1044,7 @@ "name": "b", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 39, + "line": 49, "column": 29 }, "size": 8, @@ -937,7 +1063,7 @@ "name": "MethodB", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 40, + "line": 50, "column": 4 }, "has_request": true, @@ -950,7 +1076,7 @@ "name": "a", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 40, + "line": 50, "column": 18 }, "size": 8, @@ -967,7 +1093,7 @@ "name": "b", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 40, + "line": 50, "column": 27 }, "size": 8, @@ -989,7 +1115,7 @@ "name": "result", "location": { "filename": "garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl", - "line": 40, + "line": 50, "column": 40 }, "size": 8, @@ -1005,22 +1131,171 @@ ] } ], - "struct_declarations": [], + "struct_declarations": [ + { + "name": "test.name/WithErrorSyntax_ErrorAsPrimitive_Response", + "location": { + "filename": "generated", + "line": 14, + "column": 0 + }, + "anonymous": false, + "members": [], + "size": 1, + "max_out_of_line": 0, + "alignment": 1, + "max_handles": 0 + }, + { + "name": "test.name/WithErrorSyntax_ErrorAsEnum_Response", + "location": { + "filename": "generated", + "line": 21, + "column": 0 + }, + "anonymous": false, + "members": [], + "size": 1, + "max_out_of_line": 0, + "alignment": 1, + "max_handles": 0 + } + ], "table_declarations": [], - "union_declarations": [], + "union_declarations": [ + { + "name": "test.name/WithErrorSyntax_ErrorAsPrimitive_Result", + "location": { + "filename": "generated", + "line": 17, + "column": 0 + }, + "maybe_attributes": [ + { + "name": "Result", + "value": "" + } + ], + "members": [ + { + "type": { + "kind": "identifier", + "identifier": "test.name/WithErrorSyntax_ErrorAsPrimitive_Response", + "nullable": false + }, + "name": "response", + "location": { + "filename": "generated", + "line": 15, + "column": 0 + }, + "size": 1, + "max_out_of_line": 0, + "alignment": 1, + "offset": 4 + }, + { + "type": { + "kind": "primitive", + "subtype": "uint32" + }, + "name": "err", + "location": { + "filename": "generated", + "line": 16, + "column": 0 + }, + "size": 4, + "max_out_of_line": 0, + "alignment": 4, + "offset": 4 + } + ], + "size": 8, + "max_out_of_line": 0, + "alignment": 4, + "max_handles": 0 + }, + { + "name": "test.name/WithErrorSyntax_ErrorAsEnum_Result", + "location": { + "filename": "generated", + "line": 24, + "column": 0 + }, + "maybe_attributes": [ + { + "name": "Result", + "value": "" + } + ], + "members": [ + { + "type": { + "kind": "identifier", + "identifier": "test.name/WithErrorSyntax_ErrorAsEnum_Response", + "nullable": false + }, + "name": "response", + "location": { + "filename": "generated", + "line": 22, + "column": 0 + }, + "size": 1, + "max_out_of_line": 0, + "alignment": 1, + "offset": 4 + }, + { + "type": { + "kind": "identifier", + "identifier": "test.name/ErrorEnun", + "nullable": false + }, + "name": "err", + "location": { + "filename": "generated", + "line": 23, + "column": 0 + }, + "size": 4, + "max_out_of_line": 0, + "alignment": 4, + "offset": 4 + } + ], + "size": 8, + "max_out_of_line": 0, + "alignment": 4, + "max_handles": 0 + } + ], "xunion_declarations": [], "declaration_order": [ + "test.name/WithErrorSyntax_ErrorAsPrimitive_Response", + "test.name/WithErrorSyntax_ErrorAsPrimitive_Result", + "test.name/WithErrorSyntax_ErrorAsEnum_Response", "test.name/KitchenSink", "test.name/ChannelProtocol", "test.name/SocketControlProtocol", "test.name/OvernetInternalProtocol", - "test.name/WithAndWithoutRequestResponse" + "test.name/WithAndWithoutRequestResponse", + "test.name/ErrorEnun", + "test.name/WithErrorSyntax_ErrorAsEnum_Result", + "test.name/WithErrorSyntax" ], "declarations": { + "test.name/ErrorEnun": "enum", "test.name/WithAndWithoutRequestResponse": "interface", + "test.name/WithErrorSyntax": "interface", "test.name/OvernetInternalProtocol": "interface", "test.name/SocketControlProtocol": "interface", "test.name/ChannelProtocol": "interface", - "test.name/KitchenSink": "interface" + "test.name/KitchenSink": "interface", + "test.name/WithErrorSyntax_ErrorAsPrimitive_Response": "struct", + "test.name/WithErrorSyntax_ErrorAsEnum_Response": "struct", + "test.name/WithErrorSyntax_ErrorAsPrimitive_Result": "union", + "test.name/WithErrorSyntax_ErrorAsEnum_Result": "union" } } diff --git a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.cc.golden b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.cc.golden index 7a1b319cac2..e19bbcc9d28 100644 --- a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.cc.golden +++ b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.cc.golden @@ -6,6 +6,158 @@ namespace test { namespace name { +extern "C" const fidl_type_t test_name_WithErrorSyntax_ErrorAsPrimitive_ResponseTable; +const fidl_type_t* WithErrorSyntax_ErrorAsPrimitive_Response::FidlType = &test_name_WithErrorSyntax_ErrorAsPrimitive_ResponseTable; + +void WithErrorSyntax_ErrorAsPrimitive_Response::Encode(::fidl::Encoder* _encoder, size_t _offset) { + ::fidl::Encode(_encoder, &__reserved, _offset + 0); +} + +void WithErrorSyntax_ErrorAsPrimitive_Response::Decode(::fidl::Decoder* _decoder, WithErrorSyntax_ErrorAsPrimitive_Response* value, size_t _offset) { + ::fidl::Decode(_decoder, &value->__reserved, _offset + 0); +} + +zx_status_t WithErrorSyntax_ErrorAsPrimitive_Response::Clone(WithErrorSyntax_ErrorAsPrimitive_Response* _result) const { + zx_status_t _status = ::fidl::Clone(__reserved, &_result->__reserved); + if (_status != ZX_OK) + return _status; + return ZX_OK; +} + +bool operator==(const WithErrorSyntax_ErrorAsPrimitive_Response& _lhs, const WithErrorSyntax_ErrorAsPrimitive_Response& _rhs) { + if (!::fidl::Equals(_lhs.__reserved, _rhs.__reserved)) { + return false; + } + return true; +} +WithErrorSyntax_ErrorAsPrimitive_Result::WithErrorSyntax_ErrorAsPrimitive_Result() : value_() {} + +WithErrorSyntax_ErrorAsPrimitive_Result::~WithErrorSyntax_ErrorAsPrimitive_Result() { +} + +WithErrorSyntax_ErrorAsPrimitive_Result::WithErrorSyntax_ErrorAsPrimitive_Result(WithErrorSyntax_ErrorAsPrimitive_Result&& other) : value_(std::move(other.value_)) { +} + +WithErrorSyntax_ErrorAsPrimitive_Result& WithErrorSyntax_ErrorAsPrimitive_Result::operator=(WithErrorSyntax_ErrorAsPrimitive_Result&& other) { + if (this != &other) { + value_ = std::move(other.value_); + } + return *this; +} + +void WithErrorSyntax_ErrorAsPrimitive_Result::Encode(::fidl::Encoder* _encoder, size_t _offset) { + fidl_union_tag_t _tag = static_cast<fidl_union_tag_t>(Which()); + ::fidl::Encode(_encoder, &_tag, _offset); + switch (_tag) { + case 0: + ::fidl::Encode(_encoder, &response(), _offset + 4); + break; + case 1: + ::fidl::Encode(_encoder, &err(), _offset + 4); + break; + default: + break; + } +} + +void WithErrorSyntax_ErrorAsPrimitive_Result::Decode(::fidl::Decoder* _decoder, WithErrorSyntax_ErrorAsPrimitive_Result* _value, size_t _offset) { + fidl_union_tag_t _tag; + ::fidl::Decode(_decoder, &_tag, _offset); + switch (_tag) { + case 0: + { + WithErrorSyntax_ErrorAsPrimitive_Response _member{}; + ::fidl::Decode(_decoder, &_member, _offset + 4); + _value->set_response(std::move(_member)); + break; + } + case 1: + { + uint32_t _member{}; + ::fidl::Decode(_decoder, &_member, _offset + 4); + _value->set_err(std::move(_member)); + break; + } + default: + _value->value_.emplace<0>(); + } +} + +zx_status_t WithErrorSyntax_ErrorAsPrimitive_Result::Clone(WithErrorSyntax_ErrorAsPrimitive_Result* _result) const { + zx_status_t _status = ZX_OK; + switch (Which()) { + case Tag::kResponse: + { + WithErrorSyntax_ErrorAsPrimitive_Response _member{}; + _status = ::fidl::Clone(response(), &_member); + if (_status == ZX_OK) { + _result->set_response(std::move(_member)); + } + } + break; + case Tag::kErr: + { + uint32_t _member{}; + _status = ::fidl::Clone(err(), &_member); + if (_status == ZX_OK) { + _result->set_err(std::move(_member)); + } + } + break; + case Tag::Invalid: + _result->value_.emplace<0>(); + break; + } + return _status; +} + +bool operator==(const WithErrorSyntax_ErrorAsPrimitive_Result& _lhs, const WithErrorSyntax_ErrorAsPrimitive_Result& _rhs) { + if (_lhs.Which() != _rhs.Which()) { + return false; + } + switch (_lhs.Which()) { + case WithErrorSyntax_ErrorAsPrimitive_Result::Tag::kResponse: + return ::fidl::Equals(_lhs.response(), _rhs.response()); + case WithErrorSyntax_ErrorAsPrimitive_Result::Tag::kErr: + return ::fidl::Equals(_lhs.err(), _rhs.err()); + case WithErrorSyntax_ErrorAsPrimitive_Result::Tag::Invalid: + return true; + default: + return false; + } +} + +void WithErrorSyntax_ErrorAsPrimitive_Result::set_response(WithErrorSyntax_ErrorAsPrimitive_Response value) { + value_.emplace<static_cast<size_t>(Tag::kResponse) + 1>(std::move(value)); +} + +void WithErrorSyntax_ErrorAsPrimitive_Result::set_err(uint32_t value) { + value_.emplace<static_cast<size_t>(Tag::kErr) + 1>(std::move(value)); +} +extern "C" const fidl_type_t test_name_WithErrorSyntax_ErrorAsEnum_ResponseTable; +const fidl_type_t* WithErrorSyntax_ErrorAsEnum_Response::FidlType = &test_name_WithErrorSyntax_ErrorAsEnum_ResponseTable; + +void WithErrorSyntax_ErrorAsEnum_Response::Encode(::fidl::Encoder* _encoder, size_t _offset) { + ::fidl::Encode(_encoder, &__reserved, _offset + 0); +} + +void WithErrorSyntax_ErrorAsEnum_Response::Decode(::fidl::Decoder* _decoder, WithErrorSyntax_ErrorAsEnum_Response* value, size_t _offset) { + ::fidl::Decode(_decoder, &value->__reserved, _offset + 0); +} + +zx_status_t WithErrorSyntax_ErrorAsEnum_Response::Clone(WithErrorSyntax_ErrorAsEnum_Response* _result) const { + zx_status_t _status = ::fidl::Clone(__reserved, &_result->__reserved); + if (_status != ZX_OK) + return _status; + return ZX_OK; +} + +bool operator==(const WithErrorSyntax_ErrorAsEnum_Response& _lhs, const WithErrorSyntax_ErrorAsEnum_Response& _rhs) { + if (!::fidl::Equals(_lhs.__reserved, _rhs.__reserved)) { + return false; + } + return true; +} #ifdef __Fuchsia__ namespace { @@ -1290,5 +1442,325 @@ zx_status_t WithAndWithoutRequestResponse_SyncProxy::WithRequestWithResponse(::s #endif // __Fuchsia__ +WithErrorSyntax_ErrorAsEnum_Result::WithErrorSyntax_ErrorAsEnum_Result() : value_() {} + +WithErrorSyntax_ErrorAsEnum_Result::~WithErrorSyntax_ErrorAsEnum_Result() { +} + +WithErrorSyntax_ErrorAsEnum_Result::WithErrorSyntax_ErrorAsEnum_Result(WithErrorSyntax_ErrorAsEnum_Result&& other) : value_(std::move(other.value_)) { +} + +WithErrorSyntax_ErrorAsEnum_Result& WithErrorSyntax_ErrorAsEnum_Result::operator=(WithErrorSyntax_ErrorAsEnum_Result&& other) { + if (this != &other) { + value_ = std::move(other.value_); + } + return *this; +} + +void WithErrorSyntax_ErrorAsEnum_Result::Encode(::fidl::Encoder* _encoder, size_t _offset) { + fidl_union_tag_t _tag = static_cast<fidl_union_tag_t>(Which()); + ::fidl::Encode(_encoder, &_tag, _offset); + switch (_tag) { + case 0: + ::fidl::Encode(_encoder, &response(), _offset + 4); + break; + case 1: + ::fidl::Encode(_encoder, &err(), _offset + 4); + break; + default: + break; + } +} + +void WithErrorSyntax_ErrorAsEnum_Result::Decode(::fidl::Decoder* _decoder, WithErrorSyntax_ErrorAsEnum_Result* _value, size_t _offset) { + fidl_union_tag_t _tag; + ::fidl::Decode(_decoder, &_tag, _offset); + switch (_tag) { + case 0: + { + WithErrorSyntax_ErrorAsEnum_Response _member{}; + ::fidl::Decode(_decoder, &_member, _offset + 4); + _value->set_response(std::move(_member)); + break; + } + case 1: + { + ErrorEnun _member{}; + ::fidl::Decode(_decoder, &_member, _offset + 4); + _value->set_err(std::move(_member)); + break; + } + default: + _value->value_.emplace<0>(); + } +} + +zx_status_t WithErrorSyntax_ErrorAsEnum_Result::Clone(WithErrorSyntax_ErrorAsEnum_Result* _result) const { + zx_status_t _status = ZX_OK; + switch (Which()) { + case Tag::kResponse: + { + WithErrorSyntax_ErrorAsEnum_Response _member{}; + _status = ::fidl::Clone(response(), &_member); + if (_status == ZX_OK) { + _result->set_response(std::move(_member)); + } + } + break; + case Tag::kErr: + { + ErrorEnun _member{}; + _status = ::fidl::Clone(err(), &_member); + if (_status == ZX_OK) { + _result->set_err(std::move(_member)); + } + } + break; + case Tag::Invalid: + _result->value_.emplace<0>(); + break; + } + return _status; +} + +bool operator==(const WithErrorSyntax_ErrorAsEnum_Result& _lhs, const WithErrorSyntax_ErrorAsEnum_Result& _rhs) { + if (_lhs.Which() != _rhs.Which()) { + return false; + } + switch (_lhs.Which()) { + case WithErrorSyntax_ErrorAsEnum_Result::Tag::kResponse: + return ::fidl::Equals(_lhs.response(), _rhs.response()); + case WithErrorSyntax_ErrorAsEnum_Result::Tag::kErr: + return ::fidl::Equals(_lhs.err(), _rhs.err()); + case WithErrorSyntax_ErrorAsEnum_Result::Tag::Invalid: + return true; + default: + return false; + } +} + +void WithErrorSyntax_ErrorAsEnum_Result::set_response(WithErrorSyntax_ErrorAsEnum_Response value) { + value_.emplace<static_cast<size_t>(Tag::kResponse) + 1>(std::move(value)); +} + +void WithErrorSyntax_ErrorAsEnum_Result::set_err(ErrorEnun value) { + value_.emplace<static_cast<size_t>(Tag::kErr) + 1>(std::move(value)); +} +#ifdef __Fuchsia__ +namespace { + +constexpr uint32_t kWithErrorSyntax_ErrorAsPrimitive_Ordinal = 2069369145u; +extern "C" const fidl_type_t test_name_WithErrorSyntaxErrorAsPrimitiveRequestTable; +extern "C" const fidl_type_t test_name_WithErrorSyntaxErrorAsPrimitiveResponseTable; + +constexpr uint32_t kWithErrorSyntax_ErrorAsEnum_Ordinal = 1284890143u; +extern "C" const fidl_type_t test_name_WithErrorSyntaxErrorAsEnumRequestTable; +extern "C" const fidl_type_t test_name_WithErrorSyntaxErrorAsEnumResponseTable; + +} // namespace + +WithErrorSyntax::~WithErrorSyntax() = default; + +WithErrorSyntax_EventSender::~WithErrorSyntax_EventSender() = default; + +WithErrorSyntax_Sync::~WithErrorSyntax_Sync() = default; + +WithErrorSyntax_Proxy::WithErrorSyntax_Proxy(::fidl::internal::ProxyController* controller) + : controller_(controller) { + (void)controller_; +} + +WithErrorSyntax_Proxy::~WithErrorSyntax_Proxy() = default; + +zx_status_t WithErrorSyntax_Proxy::Dispatch_(::fidl::Message message) { + zx_status_t status = ZX_OK; + switch (message.ordinal()) { + default: { + status = ZX_ERR_NOT_SUPPORTED; + break; + } + } + return status; +} + + +namespace { + +class WithErrorSyntax_ErrorAsPrimitive_ResponseHandler : public ::fidl::internal::MessageHandler { + public: + WithErrorSyntax_ErrorAsPrimitive_ResponseHandler(WithErrorSyntax::ErrorAsPrimitiveCallback callback) + : callback_(std::move(callback)) { + ZX_DEBUG_ASSERT_MSG(callback_, + "Callback must not be empty for WithErrorSyntax::ErrorAsPrimitive\n"); + } + + zx_status_t OnMessage(::fidl::Message message) override { + const char* error_msg = nullptr; + zx_status_t status = message.Decode(&test_name_WithErrorSyntaxErrorAsPrimitiveResponseTable, &error_msg); + if (status != ZX_OK) { + FIDL_REPORT_DECODING_ERROR(message, &test_name_WithErrorSyntaxErrorAsPrimitiveResponseTable, error_msg); + return status; + } + ::fidl::Decoder decoder(std::move(message)); + auto arg0 = ::fidl::DecodeAs<WithErrorSyntax_ErrorAsPrimitive_Result>(&decoder, 16); + callback_(std::move(arg0)); + return ZX_OK; + } + + private: + WithErrorSyntax::ErrorAsPrimitiveCallback callback_; + + WithErrorSyntax_ErrorAsPrimitive_ResponseHandler(const WithErrorSyntax_ErrorAsPrimitive_ResponseHandler&) = delete; + WithErrorSyntax_ErrorAsPrimitive_ResponseHandler& operator=(const WithErrorSyntax_ErrorAsPrimitive_ResponseHandler&) = delete; +}; + +} // namespace +void WithErrorSyntax_Proxy::ErrorAsPrimitive(ErrorAsPrimitiveCallback callback) { + ::fidl::Encoder _encoder(kWithErrorSyntax_ErrorAsPrimitive_Ordinal); + controller_->Send(&test_name_WithErrorSyntaxErrorAsPrimitiveRequestTable, _encoder.GetMessage(), std::make_unique<WithErrorSyntax_ErrorAsPrimitive_ResponseHandler>(std::move(callback))); +} +namespace { + +class WithErrorSyntax_ErrorAsEnum_ResponseHandler : public ::fidl::internal::MessageHandler { + public: + WithErrorSyntax_ErrorAsEnum_ResponseHandler(WithErrorSyntax::ErrorAsEnumCallback callback) + : callback_(std::move(callback)) { + ZX_DEBUG_ASSERT_MSG(callback_, + "Callback must not be empty for WithErrorSyntax::ErrorAsEnum\n"); + } + + zx_status_t OnMessage(::fidl::Message message) override { + const char* error_msg = nullptr; + zx_status_t status = message.Decode(&test_name_WithErrorSyntaxErrorAsEnumResponseTable, &error_msg); + if (status != ZX_OK) { + FIDL_REPORT_DECODING_ERROR(message, &test_name_WithErrorSyntaxErrorAsEnumResponseTable, error_msg); + return status; + } + ::fidl::Decoder decoder(std::move(message)); + auto arg0 = ::fidl::DecodeAs<WithErrorSyntax_ErrorAsEnum_Result>(&decoder, 16); + callback_(std::move(arg0)); + return ZX_OK; + } + + private: + WithErrorSyntax::ErrorAsEnumCallback callback_; + + WithErrorSyntax_ErrorAsEnum_ResponseHandler(const WithErrorSyntax_ErrorAsEnum_ResponseHandler&) = delete; + WithErrorSyntax_ErrorAsEnum_ResponseHandler& operator=(const WithErrorSyntax_ErrorAsEnum_ResponseHandler&) = delete; +}; + +} // namespace +void WithErrorSyntax_Proxy::ErrorAsEnum(ErrorAsEnumCallback callback) { + ::fidl::Encoder _encoder(kWithErrorSyntax_ErrorAsEnum_Ordinal); + controller_->Send(&test_name_WithErrorSyntaxErrorAsEnumRequestTable, _encoder.GetMessage(), std::make_unique<WithErrorSyntax_ErrorAsEnum_ResponseHandler>(std::move(callback))); +} + +WithErrorSyntax_Stub::WithErrorSyntax_Stub(WithErrorSyntax_clazz* impl) : impl_(impl) { + (void)impl_; +} + +WithErrorSyntax_Stub::~WithErrorSyntax_Stub() = default; + +namespace { + +class WithErrorSyntax_ErrorAsPrimitive_Responder { + public: + WithErrorSyntax_ErrorAsPrimitive_Responder(::fidl::internal::PendingResponse response, uint32_t ordinal) + : response_(std::move(response)), ordinal_(ordinal) {} + + void operator()(WithErrorSyntax_ErrorAsPrimitive_Result result) { + ::fidl::Encoder _encoder(ordinal_); + _encoder.Alloc(24 - sizeof(fidl_message_header_t)); + ::fidl::Encode(&_encoder, &result, 16); + response_.Send(&test_name_WithErrorSyntaxErrorAsPrimitiveResponseTable, _encoder.GetMessage()); + } + + private: + ::fidl::internal::PendingResponse response_; + uint32_t ordinal_; +}; + +class WithErrorSyntax_ErrorAsEnum_Responder { + public: + WithErrorSyntax_ErrorAsEnum_Responder(::fidl::internal::PendingResponse response, uint32_t ordinal) + : response_(std::move(response)), ordinal_(ordinal) {} + + void operator()(WithErrorSyntax_ErrorAsEnum_Result result) { + ::fidl::Encoder _encoder(ordinal_); + _encoder.Alloc(24 - sizeof(fidl_message_header_t)); + ::fidl::Encode(&_encoder, &result, 16); + response_.Send(&test_name_WithErrorSyntaxErrorAsEnumResponseTable, _encoder.GetMessage()); + } + + private: + ::fidl::internal::PendingResponse response_; + uint32_t ordinal_; +}; + +} // namespace + +zx_status_t WithErrorSyntax_Stub::Dispatch_( + ::fidl::Message message, + ::fidl::internal::PendingResponse response) { + zx_status_t status = ZX_OK; + uint32_t ordinal = message.ordinal(); + switch (ordinal) { + case kWithErrorSyntax_ErrorAsPrimitive_Ordinal: { + const char* error_msg = nullptr; + status = message.Decode(&test_name_WithErrorSyntaxErrorAsPrimitiveRequestTable, &error_msg); + if (status != ZX_OK) { + FIDL_REPORT_DECODING_ERROR(message, &test_name_WithErrorSyntaxErrorAsPrimitiveRequestTable, error_msg); + break; + } + impl_->ErrorAsPrimitive(WithErrorSyntax_ErrorAsPrimitive_Responder(std::move(response), ordinal)); + break; + } + case kWithErrorSyntax_ErrorAsEnum_Ordinal: { + const char* error_msg = nullptr; + status = message.Decode(&test_name_WithErrorSyntaxErrorAsEnumRequestTable, &error_msg); + if (status != ZX_OK) { + FIDL_REPORT_DECODING_ERROR(message, &test_name_WithErrorSyntaxErrorAsEnumRequestTable, error_msg); + break; + } + impl_->ErrorAsEnum(WithErrorSyntax_ErrorAsEnum_Responder(std::move(response), ordinal)); + break; + } + default: { + status = ZX_ERR_NOT_SUPPORTED; + break; + } + } + return status; +} + +WithErrorSyntax_SyncProxy::WithErrorSyntax_SyncProxy(::zx::channel channel) + : proxy_(::std::move(channel)) {} + +WithErrorSyntax_SyncProxy::~WithErrorSyntax_SyncProxy() = default; +zx_status_t WithErrorSyntax_SyncProxy::ErrorAsPrimitive(WithErrorSyntax_ErrorAsPrimitive_Result* out_result) { + ::fidl::Encoder _encoder(kWithErrorSyntax_ErrorAsPrimitive_Ordinal); + ::fidl::MessageBuffer buffer_; + ::fidl::Message response_ = buffer_.CreateEmptyMessage(); + zx_status_t status_ = proxy_.Call(&test_name_WithErrorSyntaxErrorAsPrimitiveRequestTable, &test_name_WithErrorSyntaxErrorAsPrimitiveResponseTable, _encoder.GetMessage(), &response_); + if (status_ != ZX_OK) + return status_; + ::fidl::Decoder decoder_(std::move(response_)); + *out_result = ::fidl::DecodeAs<WithErrorSyntax_ErrorAsPrimitive_Result>(&decoder_, 16); + return ZX_OK; +} +zx_status_t WithErrorSyntax_SyncProxy::ErrorAsEnum(WithErrorSyntax_ErrorAsEnum_Result* out_result) { + ::fidl::Encoder _encoder(kWithErrorSyntax_ErrorAsEnum_Ordinal); + ::fidl::MessageBuffer buffer_; + ::fidl::Message response_ = buffer_.CreateEmptyMessage(); + zx_status_t status_ = proxy_.Call(&test_name_WithErrorSyntaxErrorAsEnumRequestTable, &test_name_WithErrorSyntaxErrorAsEnumResponseTable, _encoder.GetMessage(), &response_); + if (status_ != ZX_OK) + return status_; + ::fidl::Decoder decoder_(std::move(response_)); + *out_result = ::fidl::DecodeAs<WithErrorSyntax_ErrorAsEnum_Result>(&decoder_, 16); + return ZX_OK; +} + +#endif // __Fuchsia__ + } // namespace name } // namespace test diff --git a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.go.golden b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.go.golden index 3b36bfb3cf1..90ca9170627 100644 --- a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.go.golden +++ b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.go.golden @@ -11,6 +11,135 @@ import ( + +type ErrorEnun uint32 +const ( + ErrorEnunErrFoo ErrorEnun = 1 + ErrorEnunErrBar ErrorEnun = 2 +) +func (x ErrorEnun) String() string { + switch x { + case 1: + return "ErrFoo" + case 2: + return "ErrBar" + } + return "Unknown" +} + +type WithErrorSyntaxErrorAsPrimitiveResponse struct { + _ struct{} `fidl2:"s,1,1"` +} + +var _mWithErrorSyntaxErrorAsPrimitiveResponse = _bindings.CreateLazyMarshaler(WithErrorSyntaxErrorAsPrimitiveResponse{}) + +func (msg *WithErrorSyntaxErrorAsPrimitiveResponse) Marshaler() _bindings.Marshaler { + return _mWithErrorSyntaxErrorAsPrimitiveResponse +} + +// Implements Payload. +func (_ *WithErrorSyntaxErrorAsPrimitiveResponse) InlineAlignment() int { + return 1 +} + +// Implements Payload. +func (_ *WithErrorSyntaxErrorAsPrimitiveResponse) InlineSize() int { + return 1 +} + +type WithErrorSyntaxErrorAsEnumResponse struct { + _ struct{} `fidl2:"s,1,1"` +} + +var _mWithErrorSyntaxErrorAsEnumResponse = _bindings.CreateLazyMarshaler(WithErrorSyntaxErrorAsEnumResponse{}) + +func (msg *WithErrorSyntaxErrorAsEnumResponse) Marshaler() _bindings.Marshaler { + return _mWithErrorSyntaxErrorAsEnumResponse +} + +// Implements Payload. +func (_ *WithErrorSyntaxErrorAsEnumResponse) InlineAlignment() int { + return 1 +} + +// Implements Payload. +func (_ *WithErrorSyntaxErrorAsEnumResponse) InlineSize() int { + return 1 +} +type WithErrorSyntaxErrorAsPrimitiveResultTag uint32 +const ( + _ WithErrorSyntaxErrorAsPrimitiveResultTag = iota + WithErrorSyntaxErrorAsPrimitiveResultResponse + WithErrorSyntaxErrorAsPrimitiveResultErr +) + + +type WithErrorSyntaxErrorAsPrimitiveResult struct { + WithErrorSyntaxErrorAsPrimitiveResultTag `fidl:"tag" fidl2:"u,8,4"` + Response WithErrorSyntaxErrorAsPrimitiveResponse + Err uint32 +} + +// Implements Payload. +func (_ *WithErrorSyntaxErrorAsPrimitiveResult) InlineAlignment() int { + return 4 +} + +// Implements Payload. +func (_ *WithErrorSyntaxErrorAsPrimitiveResult) InlineSize() int { + return 8 +} + +func (u *WithErrorSyntaxErrorAsPrimitiveResult) Which() WithErrorSyntaxErrorAsPrimitiveResultTag { + return u.WithErrorSyntaxErrorAsPrimitiveResultTag +} + +func (u *WithErrorSyntaxErrorAsPrimitiveResult) SetResponse(response WithErrorSyntaxErrorAsPrimitiveResponse) { + u.WithErrorSyntaxErrorAsPrimitiveResultTag = WithErrorSyntaxErrorAsPrimitiveResultResponse + u.Response = response +} + +func (u *WithErrorSyntaxErrorAsPrimitiveResult) SetErr(err uint32) { + u.WithErrorSyntaxErrorAsPrimitiveResultTag = WithErrorSyntaxErrorAsPrimitiveResultErr + u.Err = err +} +type WithErrorSyntaxErrorAsEnumResultTag uint32 +const ( + _ WithErrorSyntaxErrorAsEnumResultTag = iota + WithErrorSyntaxErrorAsEnumResultResponse + WithErrorSyntaxErrorAsEnumResultErr +) + + +type WithErrorSyntaxErrorAsEnumResult struct { + WithErrorSyntaxErrorAsEnumResultTag `fidl:"tag" fidl2:"u,8,4"` + Response WithErrorSyntaxErrorAsEnumResponse + Err ErrorEnun +} + +// Implements Payload. +func (_ *WithErrorSyntaxErrorAsEnumResult) InlineAlignment() int { + return 4 +} + +// Implements Payload. +func (_ *WithErrorSyntaxErrorAsEnumResult) InlineSize() int { + return 8 +} + +func (u *WithErrorSyntaxErrorAsEnumResult) Which() WithErrorSyntaxErrorAsEnumResultTag { + return u.WithErrorSyntaxErrorAsEnumResultTag +} + +func (u *WithErrorSyntaxErrorAsEnumResult) SetResponse(response WithErrorSyntaxErrorAsEnumResponse) { + u.WithErrorSyntaxErrorAsEnumResultTag = WithErrorSyntaxErrorAsEnumResultResponse + u.Response = response +} + +func (u *WithErrorSyntaxErrorAsEnumResult) SetErr(err ErrorEnun) { + u.WithErrorSyntaxErrorAsEnumResultTag = WithErrorSyntaxErrorAsEnumResultErr + u.Err = err +} const ( WithAndWithoutRequestResponseNoRequestNoResponseOrdinal uint32 = 503576693 WithAndWithoutRequestResponseNoRequestNoResponseGenOrdinal uint32 = 503576693 @@ -30,129 +159,129 @@ const ( WithAndWithoutRequestResponseOnWithResponseGenOrdinal uint32 = 2051478023 ) -type WithAndWithoutRequestResponseNoRequestWithResponseResponse struct { +type withAndWithoutRequestResponseNoRequestWithResponseResponse struct { _ struct{} `fidl2:"s,16,0"` Ret string } -var _mWithAndWithoutRequestResponseNoRequestWithResponseResponse = _bindings.CreateLazyMarshaler(WithAndWithoutRequestResponseNoRequestWithResponseResponse{}) +var _mwithAndWithoutRequestResponseNoRequestWithResponseResponse = _bindings.CreateLazyMarshaler(withAndWithoutRequestResponseNoRequestWithResponseResponse{}) -func (msg *WithAndWithoutRequestResponseNoRequestWithResponseResponse) Marshaler() _bindings.Marshaler { - return _mWithAndWithoutRequestResponseNoRequestWithResponseResponse +func (msg *withAndWithoutRequestResponseNoRequestWithResponseResponse) Marshaler() _bindings.Marshaler { + return _mwithAndWithoutRequestResponseNoRequestWithResponseResponse } // Implements Payload. -func (_ *WithAndWithoutRequestResponseNoRequestWithResponseResponse) InlineAlignment() int { +func (_ *withAndWithoutRequestResponseNoRequestWithResponseResponse) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *WithAndWithoutRequestResponseNoRequestWithResponseResponse) InlineSize() int { +func (_ *withAndWithoutRequestResponseNoRequestWithResponseResponse) InlineSize() int { return 16 } -type WithAndWithoutRequestResponseWithRequestNoResponseRequest struct { +type withAndWithoutRequestResponseWithRequestNoResponseRequest struct { _ struct{} `fidl2:"s,16,0"` Arg string } -var _mWithAndWithoutRequestResponseWithRequestNoResponseRequest = _bindings.CreateLazyMarshaler(WithAndWithoutRequestResponseWithRequestNoResponseRequest{}) +var _mwithAndWithoutRequestResponseWithRequestNoResponseRequest = _bindings.CreateLazyMarshaler(withAndWithoutRequestResponseWithRequestNoResponseRequest{}) -func (msg *WithAndWithoutRequestResponseWithRequestNoResponseRequest) Marshaler() _bindings.Marshaler { - return _mWithAndWithoutRequestResponseWithRequestNoResponseRequest +func (msg *withAndWithoutRequestResponseWithRequestNoResponseRequest) Marshaler() _bindings.Marshaler { + return _mwithAndWithoutRequestResponseWithRequestNoResponseRequest } // Implements Payload. -func (_ *WithAndWithoutRequestResponseWithRequestNoResponseRequest) InlineAlignment() int { +func (_ *withAndWithoutRequestResponseWithRequestNoResponseRequest) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *WithAndWithoutRequestResponseWithRequestNoResponseRequest) InlineSize() int { +func (_ *withAndWithoutRequestResponseWithRequestNoResponseRequest) InlineSize() int { return 16 } -type WithAndWithoutRequestResponseWithRequestEmptyResponseRequest struct { +type withAndWithoutRequestResponseWithRequestEmptyResponseRequest struct { _ struct{} `fidl2:"s,16,0"` Arg string } -var _mWithAndWithoutRequestResponseWithRequestEmptyResponseRequest = _bindings.CreateLazyMarshaler(WithAndWithoutRequestResponseWithRequestEmptyResponseRequest{}) +var _mwithAndWithoutRequestResponseWithRequestEmptyResponseRequest = _bindings.CreateLazyMarshaler(withAndWithoutRequestResponseWithRequestEmptyResponseRequest{}) -func (msg *WithAndWithoutRequestResponseWithRequestEmptyResponseRequest) Marshaler() _bindings.Marshaler { - return _mWithAndWithoutRequestResponseWithRequestEmptyResponseRequest +func (msg *withAndWithoutRequestResponseWithRequestEmptyResponseRequest) Marshaler() _bindings.Marshaler { + return _mwithAndWithoutRequestResponseWithRequestEmptyResponseRequest } // Implements Payload. -func (_ *WithAndWithoutRequestResponseWithRequestEmptyResponseRequest) InlineAlignment() int { +func (_ *withAndWithoutRequestResponseWithRequestEmptyResponseRequest) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *WithAndWithoutRequestResponseWithRequestEmptyResponseRequest) InlineSize() int { +func (_ *withAndWithoutRequestResponseWithRequestEmptyResponseRequest) InlineSize() int { return 16 } -type WithAndWithoutRequestResponseWithRequestWithResponseRequest struct { +type withAndWithoutRequestResponseWithRequestWithResponseRequest struct { _ struct{} `fidl2:"s,16,0"` Arg string } -var _mWithAndWithoutRequestResponseWithRequestWithResponseRequest = _bindings.CreateLazyMarshaler(WithAndWithoutRequestResponseWithRequestWithResponseRequest{}) +var _mwithAndWithoutRequestResponseWithRequestWithResponseRequest = _bindings.CreateLazyMarshaler(withAndWithoutRequestResponseWithRequestWithResponseRequest{}) -func (msg *WithAndWithoutRequestResponseWithRequestWithResponseRequest) Marshaler() _bindings.Marshaler { - return _mWithAndWithoutRequestResponseWithRequestWithResponseRequest +func (msg *withAndWithoutRequestResponseWithRequestWithResponseRequest) Marshaler() _bindings.Marshaler { + return _mwithAndWithoutRequestResponseWithRequestWithResponseRequest } // Implements Payload. -func (_ *WithAndWithoutRequestResponseWithRequestWithResponseRequest) InlineAlignment() int { +func (_ *withAndWithoutRequestResponseWithRequestWithResponseRequest) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *WithAndWithoutRequestResponseWithRequestWithResponseRequest) InlineSize() int { +func (_ *withAndWithoutRequestResponseWithRequestWithResponseRequest) InlineSize() int { return 16 } -type WithAndWithoutRequestResponseWithRequestWithResponseResponse struct { +type withAndWithoutRequestResponseWithRequestWithResponseResponse struct { _ struct{} `fidl2:"s,16,0"` Ret string } -var _mWithAndWithoutRequestResponseWithRequestWithResponseResponse = _bindings.CreateLazyMarshaler(WithAndWithoutRequestResponseWithRequestWithResponseResponse{}) +var _mwithAndWithoutRequestResponseWithRequestWithResponseResponse = _bindings.CreateLazyMarshaler(withAndWithoutRequestResponseWithRequestWithResponseResponse{}) -func (msg *WithAndWithoutRequestResponseWithRequestWithResponseResponse) Marshaler() _bindings.Marshaler { - return _mWithAndWithoutRequestResponseWithRequestWithResponseResponse +func (msg *withAndWithoutRequestResponseWithRequestWithResponseResponse) Marshaler() _bindings.Marshaler { + return _mwithAndWithoutRequestResponseWithRequestWithResponseResponse } // Implements Payload. -func (_ *WithAndWithoutRequestResponseWithRequestWithResponseResponse) InlineAlignment() int { +func (_ *withAndWithoutRequestResponseWithRequestWithResponseResponse) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *WithAndWithoutRequestResponseWithRequestWithResponseResponse) InlineSize() int { +func (_ *withAndWithoutRequestResponseWithRequestWithResponseResponse) InlineSize() int { return 16 } -type WithAndWithoutRequestResponseOnWithResponseResponse struct { +type withAndWithoutRequestResponseOnWithResponseResponse struct { _ struct{} `fidl2:"s,16,0"` Ret string } -var _mWithAndWithoutRequestResponseOnWithResponseResponse = _bindings.CreateLazyMarshaler(WithAndWithoutRequestResponseOnWithResponseResponse{}) +var _mwithAndWithoutRequestResponseOnWithResponseResponse = _bindings.CreateLazyMarshaler(withAndWithoutRequestResponseOnWithResponseResponse{}) -func (msg *WithAndWithoutRequestResponseOnWithResponseResponse) Marshaler() _bindings.Marshaler { - return _mWithAndWithoutRequestResponseOnWithResponseResponse +func (msg *withAndWithoutRequestResponseOnWithResponseResponse) Marshaler() _bindings.Marshaler { + return _mwithAndWithoutRequestResponseOnWithResponseResponse } // Implements Payload. -func (_ *WithAndWithoutRequestResponseOnWithResponseResponse) InlineAlignment() int { +func (_ *withAndWithoutRequestResponseOnWithResponseResponse) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *WithAndWithoutRequestResponseOnWithResponseResponse) InlineSize() int { +func (_ *withAndWithoutRequestResponseOnWithResponseResponse) InlineSize() int { return 16 } @@ -174,13 +303,13 @@ func (p *WithAndWithoutRequestResponseInterface) NoRequestEmptyResponse() error func (p *WithAndWithoutRequestResponseInterface) NoRequestWithResponse() (string, error) { var req_ _bindings.Payload - resp_ := &WithAndWithoutRequestResponseNoRequestWithResponseResponse{} + resp_ := &withAndWithoutRequestResponseNoRequestWithResponseResponse{} err := ((*_bindings.ChannelProxy)(p)).Call(WithAndWithoutRequestResponseNoRequestWithResponseOrdinal, req_, resp_) return resp_.Ret, err } func (p *WithAndWithoutRequestResponseInterface) WithRequestNoResponse(arg string) error { - req_ := &WithAndWithoutRequestResponseWithRequestNoResponseRequest{ + req_ := &withAndWithoutRequestResponseWithRequestNoResponseRequest{ Arg: arg, } err := ((*_bindings.ChannelProxy)(p)).Send(WithAndWithoutRequestResponseWithRequestNoResponseOrdinal, req_) @@ -188,7 +317,7 @@ func (p *WithAndWithoutRequestResponseInterface) WithRequestNoResponse(arg strin } func (p *WithAndWithoutRequestResponseInterface) WithRequestEmptyResponse(arg string) error { - req_ := &WithAndWithoutRequestResponseWithRequestEmptyResponseRequest{ + req_ := &withAndWithoutRequestResponseWithRequestEmptyResponseRequest{ Arg: arg, } var resp_ _bindings.Payload @@ -197,10 +326,10 @@ func (p *WithAndWithoutRequestResponseInterface) WithRequestEmptyResponse(arg st } func (p *WithAndWithoutRequestResponseInterface) WithRequestWithResponse(arg string) (string, error) { - req_ := &WithAndWithoutRequestResponseWithRequestWithResponseRequest{ + req_ := &withAndWithoutRequestResponseWithRequestWithResponseRequest{ Arg: arg, } - resp_ := &WithAndWithoutRequestResponseWithRequestWithResponseResponse{} + resp_ := &withAndWithoutRequestResponseWithRequestWithResponseResponse{} err := ((*_bindings.ChannelProxy)(p)).Call(WithAndWithoutRequestResponseWithRequestWithResponseOrdinal, req_, resp_) return resp_.Ret, err } @@ -212,7 +341,7 @@ func (p *WithAndWithoutRequestResponseInterface) ExpectOnEmptyResponse() error { } func (p *WithAndWithoutRequestResponseInterface) ExpectOnWithResponse() (string, error) { - resp_ := &WithAndWithoutRequestResponseOnWithResponseResponse{} + resp_ := &withAndWithoutRequestResponseOnWithResponseResponse{} err := ((*_bindings.ChannelProxy)(p)).Recv(WithAndWithoutRequestResponseOnWithResponseOrdinal, resp_) return resp_.Ret, err } @@ -255,30 +384,30 @@ func (s *WithAndWithoutRequestResponseStub) DispatchNew(ord uint32, b_ []byte, h return nil, err_ case WithAndWithoutRequestResponseNoRequestWithResponseOrdinal: ret, err_ := s.Impl.NoRequestWithResponse() - out_ := WithAndWithoutRequestResponseNoRequestWithResponseResponse{} + out_ := withAndWithoutRequestResponseNoRequestWithResponseResponse{} out_.Ret = ret return &out_, err_ case WithAndWithoutRequestResponseWithRequestNoResponseOrdinal: - in_ := WithAndWithoutRequestResponseWithRequestNoResponseRequest{} + in_ := withAndWithoutRequestResponseWithRequestNoResponseRequest{} if err_ := _bindings.Unmarshal(b_, h_, &in_); err_ != nil { return nil, err_ } err_ := s.Impl.WithRequestNoResponse(in_.Arg) return nil, err_ case WithAndWithoutRequestResponseWithRequestEmptyResponseOrdinal: - in_ := WithAndWithoutRequestResponseWithRequestEmptyResponseRequest{} + in_ := withAndWithoutRequestResponseWithRequestEmptyResponseRequest{} if err_ := _bindings.Unmarshal(b_, h_, &in_); err_ != nil { return nil, err_ } err_ := s.Impl.WithRequestEmptyResponse(in_.Arg) return nil, err_ case WithAndWithoutRequestResponseWithRequestWithResponseOrdinal: - in_ := WithAndWithoutRequestResponseWithRequestWithResponseRequest{} + in_ := withAndWithoutRequestResponseWithRequestWithResponseRequest{} if err_ := _bindings.Unmarshal(b_, h_, &in_); err_ != nil { return nil, err_ } ret, err_ := s.Impl.WithRequestWithResponse(in_.Arg) - out_ := WithAndWithoutRequestResponseWithRequestWithResponseResponse{} + out_ := withAndWithoutRequestResponseWithRequestWithResponseResponse{} out_.Ret = ret return &out_, err_ } @@ -304,13 +433,135 @@ func (p *WithAndWithoutRequestResponseEventProxy) OnEmptyResponse() error { return ((*_bindings.ChannelProxy)(p)).Send(WithAndWithoutRequestResponseOnEmptyResponseOrdinal, event_) } func (p *WithAndWithoutRequestResponseEventProxy) OnWithResponse(ret string) error { - event_ := &WithAndWithoutRequestResponseOnWithResponseResponse{ + event_ := &withAndWithoutRequestResponseOnWithResponseResponse{ Ret: ret, } return ((*_bindings.ChannelProxy)(p)).Send(WithAndWithoutRequestResponseOnWithResponseOrdinal, event_) } +const ( + WithErrorSyntaxErrorAsPrimitiveOrdinal uint32 = 2069369145 + WithErrorSyntaxErrorAsPrimitiveGenOrdinal uint32 = 2069369145 + WithErrorSyntaxErrorAsEnumOrdinal uint32 = 1284890143 + WithErrorSyntaxErrorAsEnumGenOrdinal uint32 = 1284890143 +) + +type withErrorSyntaxErrorAsPrimitiveResponse struct { + _ struct{} `fidl2:"s,8,0"` + Result WithErrorSyntaxErrorAsPrimitiveResult +} + +var _mwithErrorSyntaxErrorAsPrimitiveResponse = _bindings.CreateLazyMarshaler(withErrorSyntaxErrorAsPrimitiveResponse{}) + +func (msg *withErrorSyntaxErrorAsPrimitiveResponse) Marshaler() _bindings.Marshaler { + return _mwithErrorSyntaxErrorAsPrimitiveResponse +} + +// Implements Payload. +func (_ *withErrorSyntaxErrorAsPrimitiveResponse) InlineAlignment() int { + return 0 +} + +// Implements Payload. +func (_ *withErrorSyntaxErrorAsPrimitiveResponse) InlineSize() int { + return 8 +} + +type withErrorSyntaxErrorAsEnumResponse struct { + _ struct{} `fidl2:"s,8,0"` + Result WithErrorSyntaxErrorAsEnumResult +} + +var _mwithErrorSyntaxErrorAsEnumResponse = _bindings.CreateLazyMarshaler(withErrorSyntaxErrorAsEnumResponse{}) + +func (msg *withErrorSyntaxErrorAsEnumResponse) Marshaler() _bindings.Marshaler { + return _mwithErrorSyntaxErrorAsEnumResponse +} + +// Implements Payload. +func (_ *withErrorSyntaxErrorAsEnumResponse) InlineAlignment() int { + return 0 +} + +// Implements Payload. +func (_ *withErrorSyntaxErrorAsEnumResponse) InlineSize() int { + return 8 +} + +type WithErrorSyntaxInterface _bindings.ChannelProxy + + +func (p *WithErrorSyntaxInterface) ErrorAsPrimitive() (WithErrorSyntaxErrorAsPrimitiveResult, error) { + var req_ _bindings.Payload + resp_ := &withErrorSyntaxErrorAsPrimitiveResponse{} + err := ((*_bindings.ChannelProxy)(p)).Call(WithErrorSyntaxErrorAsPrimitiveOrdinal, req_, resp_) + return resp_.Result, err +} + +func (p *WithErrorSyntaxInterface) ErrorAsEnum() (WithErrorSyntaxErrorAsEnumResult, error) { + var req_ _bindings.Payload + resp_ := &withErrorSyntaxErrorAsEnumResponse{} + err := ((*_bindings.ChannelProxy)(p)).Call(WithErrorSyntaxErrorAsEnumOrdinal, req_, resp_) + return resp_.Result, err +} + + +type WithErrorSyntax interface { + ErrorAsPrimitive() (WithErrorSyntaxErrorAsPrimitiveResult, error) + ErrorAsEnum() (WithErrorSyntaxErrorAsEnumResult, error) +} + +type WithErrorSyntaxTransitionalBase struct {} + + +type WithErrorSyntaxInterfaceRequest _bindings.InterfaceRequest + +func NewWithErrorSyntaxInterfaceRequest() (WithErrorSyntaxInterfaceRequest, *WithErrorSyntaxInterface, error) { + req, cli, err := _bindings.NewInterfaceRequest() + return WithErrorSyntaxInterfaceRequest(req), (*WithErrorSyntaxInterface)(cli), err +} + +type WithErrorSyntaxStub struct { + Impl WithErrorSyntax +} + +func (s *WithErrorSyntaxStub) Dispatch(ord uint32, b_ []byte, h_ []_zx.Handle) (_bindings.Payload, error) { + return s.DispatchNew(ord, b_, h_) +} + +func (s *WithErrorSyntaxStub) DispatchNew(ord uint32, b_ []byte, h_ []_zx.Handle) (_bindings.Message, error) { + switch ord { + case WithErrorSyntaxErrorAsPrimitiveOrdinal: + result, err_ := s.Impl.ErrorAsPrimitive() + out_ := withErrorSyntaxErrorAsPrimitiveResponse{} + out_.Result = result + return &out_, err_ + case WithErrorSyntaxErrorAsEnumOrdinal: + result, err_ := s.Impl.ErrorAsEnum() + out_ := withErrorSyntaxErrorAsEnumResponse{} + out_.Result = result + return &out_, err_ + } + return nil, _bindings.ErrUnknownOrdinal +} +type WithErrorSyntaxService struct { + _bindings.BindingSet +} + +func (s *WithErrorSyntaxService) Add(impl WithErrorSyntax, c _zx.Channel, onError func(error)) (_bindings.BindingKey, error) { + return s.BindingSet.Add(&WithErrorSyntaxStub{Impl: impl}, c, onError) +} + +func (s *WithErrorSyntaxService) EventProxyFor(key _bindings.BindingKey) (*WithErrorSyntaxEventProxy, bool) { + pxy, err := s.BindingSet.ProxyFor(key) + return (*WithErrorSyntaxEventProxy)(pxy), err +} + +type WithErrorSyntaxEventProxy _bindings.ChannelProxy + + + const ( OvernetInternalProtocolMethodAOrdinal uint32 = 1993818253 OvernetInternalProtocolMethodAGenOrdinal uint32 = 1993818253 @@ -320,90 +571,90 @@ const ( OvernetInternalProtocolMethodBGenOrdinal uint32 = 952134976 ) -type OvernetInternalProtocolMethodARequest struct { +type overnetInternalProtocolMethodARequest struct { _ struct{} `fidl2:"s,16,0"` A int64 B int64 } -var _mOvernetInternalProtocolMethodARequest = _bindings.CreateLazyMarshaler(OvernetInternalProtocolMethodARequest{}) +var _movernetInternalProtocolMethodARequest = _bindings.CreateLazyMarshaler(overnetInternalProtocolMethodARequest{}) -func (msg *OvernetInternalProtocolMethodARequest) Marshaler() _bindings.Marshaler { - return _mOvernetInternalProtocolMethodARequest +func (msg *overnetInternalProtocolMethodARequest) Marshaler() _bindings.Marshaler { + return _movernetInternalProtocolMethodARequest } // Implements Payload. -func (_ *OvernetInternalProtocolMethodARequest) InlineAlignment() int { +func (_ *overnetInternalProtocolMethodARequest) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *OvernetInternalProtocolMethodARequest) InlineSize() int { +func (_ *overnetInternalProtocolMethodARequest) InlineSize() int { return 16 } -type OvernetInternalProtocolEventAResponse struct { +type overnetInternalProtocolEventAResponse struct { _ struct{} `fidl2:"s,16,0"` A int64 B int64 } -var _mOvernetInternalProtocolEventAResponse = _bindings.CreateLazyMarshaler(OvernetInternalProtocolEventAResponse{}) +var _movernetInternalProtocolEventAResponse = _bindings.CreateLazyMarshaler(overnetInternalProtocolEventAResponse{}) -func (msg *OvernetInternalProtocolEventAResponse) Marshaler() _bindings.Marshaler { - return _mOvernetInternalProtocolEventAResponse +func (msg *overnetInternalProtocolEventAResponse) Marshaler() _bindings.Marshaler { + return _movernetInternalProtocolEventAResponse } // Implements Payload. -func (_ *OvernetInternalProtocolEventAResponse) InlineAlignment() int { +func (_ *overnetInternalProtocolEventAResponse) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *OvernetInternalProtocolEventAResponse) InlineSize() int { +func (_ *overnetInternalProtocolEventAResponse) InlineSize() int { return 16 } -type OvernetInternalProtocolMethodBRequest struct { +type overnetInternalProtocolMethodBRequest struct { _ struct{} `fidl2:"s,16,0"` A int64 B int64 } -var _mOvernetInternalProtocolMethodBRequest = _bindings.CreateLazyMarshaler(OvernetInternalProtocolMethodBRequest{}) +var _movernetInternalProtocolMethodBRequest = _bindings.CreateLazyMarshaler(overnetInternalProtocolMethodBRequest{}) -func (msg *OvernetInternalProtocolMethodBRequest) Marshaler() _bindings.Marshaler { - return _mOvernetInternalProtocolMethodBRequest +func (msg *overnetInternalProtocolMethodBRequest) Marshaler() _bindings.Marshaler { + return _movernetInternalProtocolMethodBRequest } // Implements Payload. -func (_ *OvernetInternalProtocolMethodBRequest) InlineAlignment() int { +func (_ *overnetInternalProtocolMethodBRequest) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *OvernetInternalProtocolMethodBRequest) InlineSize() int { +func (_ *overnetInternalProtocolMethodBRequest) InlineSize() int { return 16 } -type OvernetInternalProtocolMethodBResponse struct { +type overnetInternalProtocolMethodBResponse struct { _ struct{} `fidl2:"s,8,0"` Result int64 } -var _mOvernetInternalProtocolMethodBResponse = _bindings.CreateLazyMarshaler(OvernetInternalProtocolMethodBResponse{}) +var _movernetInternalProtocolMethodBResponse = _bindings.CreateLazyMarshaler(overnetInternalProtocolMethodBResponse{}) -func (msg *OvernetInternalProtocolMethodBResponse) Marshaler() _bindings.Marshaler { - return _mOvernetInternalProtocolMethodBResponse +func (msg *overnetInternalProtocolMethodBResponse) Marshaler() _bindings.Marshaler { + return _movernetInternalProtocolMethodBResponse } // Implements Payload. -func (_ *OvernetInternalProtocolMethodBResponse) InlineAlignment() int { +func (_ *overnetInternalProtocolMethodBResponse) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *OvernetInternalProtocolMethodBResponse) InlineSize() int { +func (_ *overnetInternalProtocolMethodBResponse) InlineSize() int { return 8 } @@ -411,7 +662,7 @@ type OvernetInternalProtocolInterface _bindings.ChannelProxy func (p *OvernetInternalProtocolInterface) MethodA(a int64,b int64) error { - req_ := &OvernetInternalProtocolMethodARequest{ + req_ := &overnetInternalProtocolMethodARequest{ A: a, B: b, } @@ -420,17 +671,17 @@ func (p *OvernetInternalProtocolInterface) MethodA(a int64,b int64) error { } func (p *OvernetInternalProtocolInterface) ExpectEventA() (int64, int64, error) { - resp_ := &OvernetInternalProtocolEventAResponse{} + resp_ := &overnetInternalProtocolEventAResponse{} err := ((*_bindings.ChannelProxy)(p)).Recv(OvernetInternalProtocolEventAOrdinal, resp_) return resp_.A, resp_.B, err } func (p *OvernetInternalProtocolInterface) MethodB(a int64,b int64) (int64, error) { - req_ := &OvernetInternalProtocolMethodBRequest{ + req_ := &overnetInternalProtocolMethodBRequest{ A: a, B: b, } - resp_ := &OvernetInternalProtocolMethodBResponse{} + resp_ := &overnetInternalProtocolMethodBResponse{} err := ((*_bindings.ChannelProxy)(p)).Call(OvernetInternalProtocolMethodBOrdinal, req_, resp_) return resp_.Result, err } @@ -462,19 +713,19 @@ func (s *OvernetInternalProtocolStub) Dispatch(ord uint32, b_ []byte, h_ []_zx.H func (s *OvernetInternalProtocolStub) DispatchNew(ord uint32, b_ []byte, h_ []_zx.Handle) (_bindings.Message, error) { switch ord { case OvernetInternalProtocolMethodAOrdinal: - in_ := OvernetInternalProtocolMethodARequest{} + in_ := overnetInternalProtocolMethodARequest{} if err_ := _bindings.Unmarshal(b_, h_, &in_); err_ != nil { return nil, err_ } err_ := s.Impl.MethodA(in_.A,in_.B) return nil, err_ case OvernetInternalProtocolMethodBOrdinal: - in_ := OvernetInternalProtocolMethodBRequest{} + in_ := overnetInternalProtocolMethodBRequest{} if err_ := _bindings.Unmarshal(b_, h_, &in_); err_ != nil { return nil, err_ } result, err_ := s.Impl.MethodB(in_.A,in_.B) - out_ := OvernetInternalProtocolMethodBResponse{} + out_ := overnetInternalProtocolMethodBResponse{} out_.Result = result return &out_, err_ } @@ -496,7 +747,7 @@ func (s *OvernetInternalProtocolService) EventProxyFor(key _bindings.BindingKey) type OvernetInternalProtocolEventProxy _bindings.ChannelProxy func (p *OvernetInternalProtocolEventProxy) EventA(a int64,b int64) error { - event_ := &OvernetInternalProtocolEventAResponse{ + event_ := &overnetInternalProtocolEventAResponse{ A: a, B: b, } @@ -513,90 +764,90 @@ const ( SocketControlProtocolMethodBGenOrdinal uint32 = 677342235 ) -type SocketControlProtocolMethodARequest struct { +type socketControlProtocolMethodARequest struct { _ struct{} `fidl2:"s,16,0"` A int64 B int64 } -var _mSocketControlProtocolMethodARequest = _bindings.CreateLazyMarshaler(SocketControlProtocolMethodARequest{}) +var _msocketControlProtocolMethodARequest = _bindings.CreateLazyMarshaler(socketControlProtocolMethodARequest{}) -func (msg *SocketControlProtocolMethodARequest) Marshaler() _bindings.Marshaler { - return _mSocketControlProtocolMethodARequest +func (msg *socketControlProtocolMethodARequest) Marshaler() _bindings.Marshaler { + return _msocketControlProtocolMethodARequest } // Implements Payload. -func (_ *SocketControlProtocolMethodARequest) InlineAlignment() int { +func (_ *socketControlProtocolMethodARequest) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *SocketControlProtocolMethodARequest) InlineSize() int { +func (_ *socketControlProtocolMethodARequest) InlineSize() int { return 16 } -type SocketControlProtocolEventAResponse struct { +type socketControlProtocolEventAResponse struct { _ struct{} `fidl2:"s,16,0"` A int64 B int64 } -var _mSocketControlProtocolEventAResponse = _bindings.CreateLazyMarshaler(SocketControlProtocolEventAResponse{}) +var _msocketControlProtocolEventAResponse = _bindings.CreateLazyMarshaler(socketControlProtocolEventAResponse{}) -func (msg *SocketControlProtocolEventAResponse) Marshaler() _bindings.Marshaler { - return _mSocketControlProtocolEventAResponse +func (msg *socketControlProtocolEventAResponse) Marshaler() _bindings.Marshaler { + return _msocketControlProtocolEventAResponse } // Implements Payload. -func (_ *SocketControlProtocolEventAResponse) InlineAlignment() int { +func (_ *socketControlProtocolEventAResponse) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *SocketControlProtocolEventAResponse) InlineSize() int { +func (_ *socketControlProtocolEventAResponse) InlineSize() int { return 16 } -type SocketControlProtocolMethodBRequest struct { +type socketControlProtocolMethodBRequest struct { _ struct{} `fidl2:"s,16,0"` A int64 B int64 } -var _mSocketControlProtocolMethodBRequest = _bindings.CreateLazyMarshaler(SocketControlProtocolMethodBRequest{}) +var _msocketControlProtocolMethodBRequest = _bindings.CreateLazyMarshaler(socketControlProtocolMethodBRequest{}) -func (msg *SocketControlProtocolMethodBRequest) Marshaler() _bindings.Marshaler { - return _mSocketControlProtocolMethodBRequest +func (msg *socketControlProtocolMethodBRequest) Marshaler() _bindings.Marshaler { + return _msocketControlProtocolMethodBRequest } // Implements Payload. -func (_ *SocketControlProtocolMethodBRequest) InlineAlignment() int { +func (_ *socketControlProtocolMethodBRequest) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *SocketControlProtocolMethodBRequest) InlineSize() int { +func (_ *socketControlProtocolMethodBRequest) InlineSize() int { return 16 } -type SocketControlProtocolMethodBResponse struct { +type socketControlProtocolMethodBResponse struct { _ struct{} `fidl2:"s,8,0"` Result int64 } -var _mSocketControlProtocolMethodBResponse = _bindings.CreateLazyMarshaler(SocketControlProtocolMethodBResponse{}) +var _msocketControlProtocolMethodBResponse = _bindings.CreateLazyMarshaler(socketControlProtocolMethodBResponse{}) -func (msg *SocketControlProtocolMethodBResponse) Marshaler() _bindings.Marshaler { - return _mSocketControlProtocolMethodBResponse +func (msg *socketControlProtocolMethodBResponse) Marshaler() _bindings.Marshaler { + return _msocketControlProtocolMethodBResponse } // Implements Payload. -func (_ *SocketControlProtocolMethodBResponse) InlineAlignment() int { +func (_ *socketControlProtocolMethodBResponse) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *SocketControlProtocolMethodBResponse) InlineSize() int { +func (_ *socketControlProtocolMethodBResponse) InlineSize() int { return 8 } @@ -604,7 +855,7 @@ type SocketControlProtocolInterface _bindings.SocketControlProxy func (p *SocketControlProtocolInterface) MethodA(a int64,b int64) error { - req_ := &SocketControlProtocolMethodARequest{ + req_ := &socketControlProtocolMethodARequest{ A: a, B: b, } @@ -613,17 +864,17 @@ func (p *SocketControlProtocolInterface) MethodA(a int64,b int64) error { } func (p *SocketControlProtocolInterface) ExpectEventA() (int64, int64, error) { - resp_ := &SocketControlProtocolEventAResponse{} + resp_ := &socketControlProtocolEventAResponse{} err := ((*_bindings.SocketControlProxy)(p)).Recv(SocketControlProtocolEventAOrdinal, resp_) return resp_.A, resp_.B, err } func (p *SocketControlProtocolInterface) MethodB(a int64,b int64) (int64, error) { - req_ := &SocketControlProtocolMethodBRequest{ + req_ := &socketControlProtocolMethodBRequest{ A: a, B: b, } - resp_ := &SocketControlProtocolMethodBResponse{} + resp_ := &socketControlProtocolMethodBResponse{} err := ((*_bindings.SocketControlProxy)(p)).Call(SocketControlProtocolMethodBOrdinal, req_, resp_) return resp_.Result, err } @@ -649,19 +900,19 @@ func (s *SocketControlProtocolStub) Dispatch(ord uint32, b_ []byte, h_ []_zx.Han func (s *SocketControlProtocolStub) DispatchNew(ord uint32, b_ []byte, h_ []_zx.Handle) (_bindings.Message, error) { switch ord { case SocketControlProtocolMethodAOrdinal: - in_ := SocketControlProtocolMethodARequest{} + in_ := socketControlProtocolMethodARequest{} if err_ := _bindings.Unmarshal(b_, h_, &in_); err_ != nil { return nil, err_ } err_ := s.Impl.MethodA(in_.A,in_.B) return nil, err_ case SocketControlProtocolMethodBOrdinal: - in_ := SocketControlProtocolMethodBRequest{} + in_ := socketControlProtocolMethodBRequest{} if err_ := _bindings.Unmarshal(b_, h_, &in_); err_ != nil { return nil, err_ } result, err_ := s.Impl.MethodB(in_.A,in_.B) - out_ := SocketControlProtocolMethodBResponse{} + out_ := socketControlProtocolMethodBResponse{} out_.Result = result return &out_, err_ } @@ -671,7 +922,7 @@ func (s *SocketControlProtocolStub) DispatchNew(ord uint32, b_ []byte, h_ []_zx. type SocketControlProtocolEventProxy _bindings.SocketControlProxy func (p *SocketControlProtocolEventProxy) EventA(a int64,b int64) error { - event_ := &SocketControlProtocolEventAResponse{ + event_ := &socketControlProtocolEventAResponse{ A: a, B: b, } @@ -688,90 +939,90 @@ const ( ChannelProtocolMethodBGenOrdinal uint32 = 180770075 ) -type ChannelProtocolMethodARequest struct { +type channelProtocolMethodARequest struct { _ struct{} `fidl2:"s,16,0"` A int64 B int64 } -var _mChannelProtocolMethodARequest = _bindings.CreateLazyMarshaler(ChannelProtocolMethodARequest{}) +var _mchannelProtocolMethodARequest = _bindings.CreateLazyMarshaler(channelProtocolMethodARequest{}) -func (msg *ChannelProtocolMethodARequest) Marshaler() _bindings.Marshaler { - return _mChannelProtocolMethodARequest +func (msg *channelProtocolMethodARequest) Marshaler() _bindings.Marshaler { + return _mchannelProtocolMethodARequest } // Implements Payload. -func (_ *ChannelProtocolMethodARequest) InlineAlignment() int { +func (_ *channelProtocolMethodARequest) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *ChannelProtocolMethodARequest) InlineSize() int { +func (_ *channelProtocolMethodARequest) InlineSize() int { return 16 } -type ChannelProtocolEventAResponse struct { +type channelProtocolEventAResponse struct { _ struct{} `fidl2:"s,16,0"` A int64 B int64 } -var _mChannelProtocolEventAResponse = _bindings.CreateLazyMarshaler(ChannelProtocolEventAResponse{}) +var _mchannelProtocolEventAResponse = _bindings.CreateLazyMarshaler(channelProtocolEventAResponse{}) -func (msg *ChannelProtocolEventAResponse) Marshaler() _bindings.Marshaler { - return _mChannelProtocolEventAResponse +func (msg *channelProtocolEventAResponse) Marshaler() _bindings.Marshaler { + return _mchannelProtocolEventAResponse } // Implements Payload. -func (_ *ChannelProtocolEventAResponse) InlineAlignment() int { +func (_ *channelProtocolEventAResponse) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *ChannelProtocolEventAResponse) InlineSize() int { +func (_ *channelProtocolEventAResponse) InlineSize() int { return 16 } -type ChannelProtocolMethodBRequest struct { +type channelProtocolMethodBRequest struct { _ struct{} `fidl2:"s,16,0"` A int64 B int64 } -var _mChannelProtocolMethodBRequest = _bindings.CreateLazyMarshaler(ChannelProtocolMethodBRequest{}) +var _mchannelProtocolMethodBRequest = _bindings.CreateLazyMarshaler(channelProtocolMethodBRequest{}) -func (msg *ChannelProtocolMethodBRequest) Marshaler() _bindings.Marshaler { - return _mChannelProtocolMethodBRequest +func (msg *channelProtocolMethodBRequest) Marshaler() _bindings.Marshaler { + return _mchannelProtocolMethodBRequest } // Implements Payload. -func (_ *ChannelProtocolMethodBRequest) InlineAlignment() int { +func (_ *channelProtocolMethodBRequest) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *ChannelProtocolMethodBRequest) InlineSize() int { +func (_ *channelProtocolMethodBRequest) InlineSize() int { return 16 } -type ChannelProtocolMethodBResponse struct { +type channelProtocolMethodBResponse struct { _ struct{} `fidl2:"s,8,0"` Result int64 } -var _mChannelProtocolMethodBResponse = _bindings.CreateLazyMarshaler(ChannelProtocolMethodBResponse{}) +var _mchannelProtocolMethodBResponse = _bindings.CreateLazyMarshaler(channelProtocolMethodBResponse{}) -func (msg *ChannelProtocolMethodBResponse) Marshaler() _bindings.Marshaler { - return _mChannelProtocolMethodBResponse +func (msg *channelProtocolMethodBResponse) Marshaler() _bindings.Marshaler { + return _mchannelProtocolMethodBResponse } // Implements Payload. -func (_ *ChannelProtocolMethodBResponse) InlineAlignment() int { +func (_ *channelProtocolMethodBResponse) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *ChannelProtocolMethodBResponse) InlineSize() int { +func (_ *channelProtocolMethodBResponse) InlineSize() int { return 8 } @@ -779,7 +1030,7 @@ type ChannelProtocolInterface _bindings.ChannelProxy func (p *ChannelProtocolInterface) MethodA(a int64,b int64) error { - req_ := &ChannelProtocolMethodARequest{ + req_ := &channelProtocolMethodARequest{ A: a, B: b, } @@ -788,17 +1039,17 @@ func (p *ChannelProtocolInterface) MethodA(a int64,b int64) error { } func (p *ChannelProtocolInterface) ExpectEventA() (int64, int64, error) { - resp_ := &ChannelProtocolEventAResponse{} + resp_ := &channelProtocolEventAResponse{} err := ((*_bindings.ChannelProxy)(p)).Recv(ChannelProtocolEventAOrdinal, resp_) return resp_.A, resp_.B, err } func (p *ChannelProtocolInterface) MethodB(a int64,b int64) (int64, error) { - req_ := &ChannelProtocolMethodBRequest{ + req_ := &channelProtocolMethodBRequest{ A: a, B: b, } - resp_ := &ChannelProtocolMethodBResponse{} + resp_ := &channelProtocolMethodBResponse{} err := ((*_bindings.ChannelProxy)(p)).Call(ChannelProtocolMethodBOrdinal, req_, resp_) return resp_.Result, err } @@ -830,19 +1081,19 @@ func (s *ChannelProtocolStub) Dispatch(ord uint32, b_ []byte, h_ []_zx.Handle) ( func (s *ChannelProtocolStub) DispatchNew(ord uint32, b_ []byte, h_ []_zx.Handle) (_bindings.Message, error) { switch ord { case ChannelProtocolMethodAOrdinal: - in_ := ChannelProtocolMethodARequest{} + in_ := channelProtocolMethodARequest{} if err_ := _bindings.Unmarshal(b_, h_, &in_); err_ != nil { return nil, err_ } err_ := s.Impl.MethodA(in_.A,in_.B) return nil, err_ case ChannelProtocolMethodBOrdinal: - in_ := ChannelProtocolMethodBRequest{} + in_ := channelProtocolMethodBRequest{} if err_ := _bindings.Unmarshal(b_, h_, &in_); err_ != nil { return nil, err_ } result, err_ := s.Impl.MethodB(in_.A,in_.B) - out_ := ChannelProtocolMethodBResponse{} + out_ := channelProtocolMethodBResponse{} out_.Result = result return &out_, err_ } @@ -864,7 +1115,7 @@ func (s *ChannelProtocolService) EventProxyFor(key _bindings.BindingKey) (*Chann type ChannelProtocolEventProxy _bindings.ChannelProxy func (p *ChannelProtocolEventProxy) EventA(a int64,b int64) error { - event_ := &ChannelProtocolEventAResponse{ + event_ := &channelProtocolEventAResponse{ A: a, B: b, } @@ -881,90 +1132,90 @@ const ( KitchenSinkMethodBGenOrdinal uint32 = 1999489700 ) -type KitchenSinkMethodARequest struct { +type kitchenSinkMethodARequest struct { _ struct{} `fidl2:"s,16,0"` A int64 B int64 } -var _mKitchenSinkMethodARequest = _bindings.CreateLazyMarshaler(KitchenSinkMethodARequest{}) +var _mkitchenSinkMethodARequest = _bindings.CreateLazyMarshaler(kitchenSinkMethodARequest{}) -func (msg *KitchenSinkMethodARequest) Marshaler() _bindings.Marshaler { - return _mKitchenSinkMethodARequest +func (msg *kitchenSinkMethodARequest) Marshaler() _bindings.Marshaler { + return _mkitchenSinkMethodARequest } // Implements Payload. -func (_ *KitchenSinkMethodARequest) InlineAlignment() int { +func (_ *kitchenSinkMethodARequest) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *KitchenSinkMethodARequest) InlineSize() int { +func (_ *kitchenSinkMethodARequest) InlineSize() int { return 16 } -type KitchenSinkEventAResponse struct { +type kitchenSinkEventAResponse struct { _ struct{} `fidl2:"s,16,0"` A int64 B int64 } -var _mKitchenSinkEventAResponse = _bindings.CreateLazyMarshaler(KitchenSinkEventAResponse{}) +var _mkitchenSinkEventAResponse = _bindings.CreateLazyMarshaler(kitchenSinkEventAResponse{}) -func (msg *KitchenSinkEventAResponse) Marshaler() _bindings.Marshaler { - return _mKitchenSinkEventAResponse +func (msg *kitchenSinkEventAResponse) Marshaler() _bindings.Marshaler { + return _mkitchenSinkEventAResponse } // Implements Payload. -func (_ *KitchenSinkEventAResponse) InlineAlignment() int { +func (_ *kitchenSinkEventAResponse) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *KitchenSinkEventAResponse) InlineSize() int { +func (_ *kitchenSinkEventAResponse) InlineSize() int { return 16 } -type KitchenSinkMethodBRequest struct { +type kitchenSinkMethodBRequest struct { _ struct{} `fidl2:"s,16,0"` A int64 B int64 } -var _mKitchenSinkMethodBRequest = _bindings.CreateLazyMarshaler(KitchenSinkMethodBRequest{}) +var _mkitchenSinkMethodBRequest = _bindings.CreateLazyMarshaler(kitchenSinkMethodBRequest{}) -func (msg *KitchenSinkMethodBRequest) Marshaler() _bindings.Marshaler { - return _mKitchenSinkMethodBRequest +func (msg *kitchenSinkMethodBRequest) Marshaler() _bindings.Marshaler { + return _mkitchenSinkMethodBRequest } // Implements Payload. -func (_ *KitchenSinkMethodBRequest) InlineAlignment() int { +func (_ *kitchenSinkMethodBRequest) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *KitchenSinkMethodBRequest) InlineSize() int { +func (_ *kitchenSinkMethodBRequest) InlineSize() int { return 16 } -type KitchenSinkMethodBResponse struct { +type kitchenSinkMethodBResponse struct { _ struct{} `fidl2:"s,8,0"` Result int64 } -var _mKitchenSinkMethodBResponse = _bindings.CreateLazyMarshaler(KitchenSinkMethodBResponse{}) +var _mkitchenSinkMethodBResponse = _bindings.CreateLazyMarshaler(kitchenSinkMethodBResponse{}) -func (msg *KitchenSinkMethodBResponse) Marshaler() _bindings.Marshaler { - return _mKitchenSinkMethodBResponse +func (msg *kitchenSinkMethodBResponse) Marshaler() _bindings.Marshaler { + return _mkitchenSinkMethodBResponse } // Implements Payload. -func (_ *KitchenSinkMethodBResponse) InlineAlignment() int { +func (_ *kitchenSinkMethodBResponse) InlineAlignment() int { return 0 } // Implements Payload. -func (_ *KitchenSinkMethodBResponse) InlineSize() int { +func (_ *kitchenSinkMethodBResponse) InlineSize() int { return 8 } @@ -972,7 +1223,7 @@ type KitchenSinkInterface _bindings.ChannelProxy func (p *KitchenSinkInterface) MethodA(a int64,b int64) error { - req_ := &KitchenSinkMethodARequest{ + req_ := &kitchenSinkMethodARequest{ A: a, B: b, } @@ -981,17 +1232,17 @@ func (p *KitchenSinkInterface) MethodA(a int64,b int64) error { } func (p *KitchenSinkInterface) ExpectEventA() (int64, int64, error) { - resp_ := &KitchenSinkEventAResponse{} + resp_ := &kitchenSinkEventAResponse{} err := ((*_bindings.ChannelProxy)(p)).Recv(KitchenSinkEventAOrdinal, resp_) return resp_.A, resp_.B, err } func (p *KitchenSinkInterface) MethodB(a int64,b int64) (int64, error) { - req_ := &KitchenSinkMethodBRequest{ + req_ := &kitchenSinkMethodBRequest{ A: a, B: b, } - resp_ := &KitchenSinkMethodBResponse{} + resp_ := &kitchenSinkMethodBResponse{} err := ((*_bindings.ChannelProxy)(p)).Call(KitchenSinkMethodBOrdinal, req_, resp_) return resp_.Result, err } @@ -1023,19 +1274,19 @@ func (s *KitchenSinkStub) Dispatch(ord uint32, b_ []byte, h_ []_zx.Handle) (_bin func (s *KitchenSinkStub) DispatchNew(ord uint32, b_ []byte, h_ []_zx.Handle) (_bindings.Message, error) { switch ord { case KitchenSinkMethodAOrdinal: - in_ := KitchenSinkMethodARequest{} + in_ := kitchenSinkMethodARequest{} if err_ := _bindings.Unmarshal(b_, h_, &in_); err_ != nil { return nil, err_ } err_ := s.Impl.MethodA(in_.A,in_.B) return nil, err_ case KitchenSinkMethodBOrdinal: - in_ := KitchenSinkMethodBRequest{} + in_ := kitchenSinkMethodBRequest{} if err_ := _bindings.Unmarshal(b_, h_, &in_); err_ != nil { return nil, err_ } result, err_ := s.Impl.MethodB(in_.A,in_.B) - out_ := KitchenSinkMethodBResponse{} + out_ := kitchenSinkMethodBResponse{} out_.Result = result return &out_, err_ } @@ -1057,7 +1308,7 @@ func (s *KitchenSinkService) EventProxyFor(key _bindings.BindingKey) (*KitchenSi type KitchenSinkEventProxy _bindings.ChannelProxy func (p *KitchenSinkEventProxy) EventA(a int64,b int64) error { - event_ := &KitchenSinkEventAResponse{ + event_ := &kitchenSinkEventAResponse{ A: a, B: b, } diff --git a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.h.golden b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.h.golden index e3acfabff8c..8e9724a17e2 100644 --- a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.h.golden +++ b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.h.golden @@ -8,6 +8,9 @@ namespace test { namespace name { +class WithErrorSyntax_ErrorAsPrimitive_Response; +class WithErrorSyntax_ErrorAsPrimitive_Result; +class WithErrorSyntax_ErrorAsEnum_Response; #ifdef __Fuchsia__ class KitchenSink; using KitchenSinkPtr = ::fidl::InterfacePtr<KitchenSink>; @@ -58,6 +61,152 @@ class WithAndWithoutRequestResponse_Sync; using WithAndWithoutRequestResponseSyncPtr = ::fidl::SynchronousInterfacePtr<WithAndWithoutRequestResponse>; class WithAndWithoutRequestResponse_SyncProxy; #endif // __Fuchsia__ +enum class ErrorEnun : uint32_t { + ERR_FOO = 1, + ERR_BAR = 2, +}; + +inline zx_status_t Clone(::test::name::ErrorEnun value, + ::test::name::ErrorEnun* result) { + *result = value; + return ZX_OK; +} + +class WithErrorSyntax_ErrorAsEnum_Result; +#ifdef __Fuchsia__ +class WithErrorSyntax; +using WithErrorSyntaxPtr = ::fidl::InterfacePtr<WithErrorSyntax>; +class WithErrorSyntax_Proxy; +class WithErrorSyntax_Stub; +class WithErrorSyntax_EventSender; +class WithErrorSyntax_Sync; +using WithErrorSyntaxSyncPtr = ::fidl::SynchronousInterfacePtr<WithErrorSyntax>; +class WithErrorSyntax_SyncProxy; +#endif // __Fuchsia__ + +class WithErrorSyntax_ErrorAsPrimitive_Response { + public: + static const fidl_type_t* FidlType; + + uint8_t __reserved = 0; + + static inline ::std::unique_ptr<WithErrorSyntax_ErrorAsPrimitive_Response> New() { return ::std::make_unique<WithErrorSyntax_ErrorAsPrimitive_Response>(); } + + void Encode(::fidl::Encoder* _encoder, size_t _offset); + static void Decode(::fidl::Decoder* _decoder, WithErrorSyntax_ErrorAsPrimitive_Response* value, size_t _offset); + zx_status_t Clone(WithErrorSyntax_ErrorAsPrimitive_Response* result) const; +}; + +bool operator==(const WithErrorSyntax_ErrorAsPrimitive_Response& _lhs, const WithErrorSyntax_ErrorAsPrimitive_Response& _rhs); +inline bool operator!=(const WithErrorSyntax_ErrorAsPrimitive_Response& _lhs, const WithErrorSyntax_ErrorAsPrimitive_Response& _rhs) { + return !(_lhs == _rhs); +} + +inline zx_status_t Clone(const ::test::name::WithErrorSyntax_ErrorAsPrimitive_Response& _value, + ::test::name::WithErrorSyntax_ErrorAsPrimitive_Response* _result) { + return _value.Clone(_result); +} + +using WithErrorSyntax_ErrorAsPrimitive_ResponsePtr = ::std::unique_ptr<WithErrorSyntax_ErrorAsPrimitive_Response>; + +class WithErrorSyntax_ErrorAsPrimitive_Result { + public: + WithErrorSyntax_ErrorAsPrimitive_Result(); + ~WithErrorSyntax_ErrorAsPrimitive_Result(); + + WithErrorSyntax_ErrorAsPrimitive_Result(WithErrorSyntax_ErrorAsPrimitive_Result&&); + WithErrorSyntax_ErrorAsPrimitive_Result& operator=(WithErrorSyntax_ErrorAsPrimitive_Result&&); + + enum class Tag : fidl_union_tag_t { + kResponse = 0, + kErr = 1, + Invalid = ::std::numeric_limits<::fidl_union_tag_t>::max(), + }; + + static inline ::std::unique_ptr<WithErrorSyntax_ErrorAsPrimitive_Result> New() { return ::std::make_unique<WithErrorSyntax_ErrorAsPrimitive_Result>(); } + + void Encode(::fidl::Encoder* _encoder, size_t _offset); + static void Decode(::fidl::Decoder* _decoder, WithErrorSyntax_ErrorAsPrimitive_Result* _value, size_t _offset); + zx_status_t Clone(WithErrorSyntax_ErrorAsPrimitive_Result* result) const; + + bool has_invalid_tag() const { return Which() == Tag::Invalid; } + + bool is_response() const { return Which() == Tag(0); } + + WithErrorSyntax_ErrorAsPrimitive_Response& response() { + if (!is_response()) { + value_.emplace<0 + 1>(); + } + return value_.template get<0 + 1>(); + } + + const WithErrorSyntax_ErrorAsPrimitive_Response& response() const { return value_.template get<0 + 1>(); } + void set_response(WithErrorSyntax_ErrorAsPrimitive_Response value); + + bool is_err() const { return Which() == Tag(1); } + + uint32_t& err() { + if (!is_err()) { + value_.emplace<1 + 1>(); + } + return value_.template get<1 + 1>(); + } + + const uint32_t& err() const { return value_.template get<1 + 1>(); } + void set_err(uint32_t value); + + Tag Which() const { + size_t index = value_.index(); + if (index == 0) { + return Tag::Invalid; + } else { + return Tag(index - 1); + } + } + + private: + friend bool operator==(const WithErrorSyntax_ErrorAsPrimitive_Result& _lhs, const WithErrorSyntax_ErrorAsPrimitive_Result& _rhs); + + using Variant = fit::internal::variant<fit::internal::monostate, WithErrorSyntax_ErrorAsPrimitive_Response, uint32_t>; + Variant value_; +}; + +bool operator==(const WithErrorSyntax_ErrorAsPrimitive_Result& _lhs, const WithErrorSyntax_ErrorAsPrimitive_Result& _rhs); +inline bool operator!=(const WithErrorSyntax_ErrorAsPrimitive_Result& _lhs, const WithErrorSyntax_ErrorAsPrimitive_Result& _rhs) { + return !(_lhs == _rhs); +} + +inline zx_status_t Clone(const ::test::name::WithErrorSyntax_ErrorAsPrimitive_Result& value, + ::test::name::WithErrorSyntax_ErrorAsPrimitive_Result* result) { + return value.Clone(result); +} + +using WithErrorSyntax_ErrorAsPrimitive_ResultPtr = ::std::unique_ptr<WithErrorSyntax_ErrorAsPrimitive_Result>; + +class WithErrorSyntax_ErrorAsEnum_Response { + public: + static const fidl_type_t* FidlType; + + uint8_t __reserved = 0; + + static inline ::std::unique_ptr<WithErrorSyntax_ErrorAsEnum_Response> New() { return ::std::make_unique<WithErrorSyntax_ErrorAsEnum_Response>(); } + + void Encode(::fidl::Encoder* _encoder, size_t _offset); + static void Decode(::fidl::Decoder* _decoder, WithErrorSyntax_ErrorAsEnum_Response* value, size_t _offset); + zx_status_t Clone(WithErrorSyntax_ErrorAsEnum_Response* result) const; +}; + +bool operator==(const WithErrorSyntax_ErrorAsEnum_Response& _lhs, const WithErrorSyntax_ErrorAsEnum_Response& _rhs); +inline bool operator!=(const WithErrorSyntax_ErrorAsEnum_Response& _lhs, const WithErrorSyntax_ErrorAsEnum_Response& _rhs) { + return !(_lhs == _rhs); +} + +inline zx_status_t Clone(const ::test::name::WithErrorSyntax_ErrorAsEnum_Response& _value, + ::test::name::WithErrorSyntax_ErrorAsEnum_Response* _result) { + return _value.Clone(_result); +} + +using WithErrorSyntax_ErrorAsEnum_ResponsePtr = ::std::unique_ptr<WithErrorSyntax_ErrorAsEnum_Response>; #ifdef __Fuchsia__ class KitchenSink { @@ -469,7 +618,204 @@ class WithAndWithoutRequestResponse_SyncProxy : public WithAndWithoutRequestResp friend class ::fidl::SynchronousInterfacePtr<WithAndWithoutRequestResponse>; }; #endif // __Fuchsia__ + +class WithErrorSyntax_ErrorAsEnum_Result { + public: + WithErrorSyntax_ErrorAsEnum_Result(); + ~WithErrorSyntax_ErrorAsEnum_Result(); + + WithErrorSyntax_ErrorAsEnum_Result(WithErrorSyntax_ErrorAsEnum_Result&&); + WithErrorSyntax_ErrorAsEnum_Result& operator=(WithErrorSyntax_ErrorAsEnum_Result&&); + + enum class Tag : fidl_union_tag_t { + kResponse = 0, + kErr = 1, + Invalid = ::std::numeric_limits<::fidl_union_tag_t>::max(), + }; + + static inline ::std::unique_ptr<WithErrorSyntax_ErrorAsEnum_Result> New() { return ::std::make_unique<WithErrorSyntax_ErrorAsEnum_Result>(); } + + void Encode(::fidl::Encoder* _encoder, size_t _offset); + static void Decode(::fidl::Decoder* _decoder, WithErrorSyntax_ErrorAsEnum_Result* _value, size_t _offset); + zx_status_t Clone(WithErrorSyntax_ErrorAsEnum_Result* result) const; + + bool has_invalid_tag() const { return Which() == Tag::Invalid; } + + bool is_response() const { return Which() == Tag(0); } + + WithErrorSyntax_ErrorAsEnum_Response& response() { + if (!is_response()) { + value_.emplace<0 + 1>(); + } + return value_.template get<0 + 1>(); + } + + const WithErrorSyntax_ErrorAsEnum_Response& response() const { return value_.template get<0 + 1>(); } + void set_response(WithErrorSyntax_ErrorAsEnum_Response value); + + bool is_err() const { return Which() == Tag(1); } + + ErrorEnun& err() { + if (!is_err()) { + value_.emplace<1 + 1>(); + } + return value_.template get<1 + 1>(); + } + + const ErrorEnun& err() const { return value_.template get<1 + 1>(); } + void set_err(ErrorEnun value); + + Tag Which() const { + size_t index = value_.index(); + if (index == 0) { + return Tag::Invalid; + } else { + return Tag(index - 1); + } + } + + private: + friend bool operator==(const WithErrorSyntax_ErrorAsEnum_Result& _lhs, const WithErrorSyntax_ErrorAsEnum_Result& _rhs); + + using Variant = fit::internal::variant<fit::internal::monostate, WithErrorSyntax_ErrorAsEnum_Response, ErrorEnun>; + Variant value_; +}; + +bool operator==(const WithErrorSyntax_ErrorAsEnum_Result& _lhs, const WithErrorSyntax_ErrorAsEnum_Result& _rhs); +inline bool operator!=(const WithErrorSyntax_ErrorAsEnum_Result& _lhs, const WithErrorSyntax_ErrorAsEnum_Result& _rhs) { + return !(_lhs == _rhs); +} + +inline zx_status_t Clone(const ::test::name::WithErrorSyntax_ErrorAsEnum_Result& value, + ::test::name::WithErrorSyntax_ErrorAsEnum_Result* result) { + return value.Clone(result); +} + +using WithErrorSyntax_ErrorAsEnum_ResultPtr = ::std::unique_ptr<WithErrorSyntax_ErrorAsEnum_Result>; +#ifdef __Fuchsia__ + +class WithErrorSyntax { + public: + using Proxy_ = WithErrorSyntax_Proxy; + using Stub_ = WithErrorSyntax_Stub; + using EventSender_ = WithErrorSyntax_EventSender; + using Sync_ = WithErrorSyntax_Sync; + virtual ~WithErrorSyntax(); + using ErrorAsPrimitiveCallback = + fit::function<void(WithErrorSyntax_ErrorAsPrimitive_Result)>; + + virtual void ErrorAsPrimitive(ErrorAsPrimitiveCallback callback) = 0; + using ErrorAsEnumCallback = + fit::function<void(WithErrorSyntax_ErrorAsEnum_Result)>; + + virtual void ErrorAsEnum(ErrorAsEnumCallback callback) = 0; +}; + +class WithErrorSyntax_EventSender { + public: + virtual ~WithErrorSyntax_EventSender(); +}; + +class WithErrorSyntax_Sync { + public: + using Proxy_ = WithErrorSyntax_SyncProxy; + virtual ~WithErrorSyntax_Sync(); + virtual zx_status_t ErrorAsPrimitive(WithErrorSyntax_ErrorAsPrimitive_Result* out_result) = 0; + virtual zx_status_t ErrorAsEnum(WithErrorSyntax_ErrorAsEnum_Result* out_result) = 0; +}; + +class WithErrorSyntax_Proxy : public ::fidl::internal::Proxy, public WithErrorSyntax { + public: + explicit WithErrorSyntax_Proxy(::fidl::internal::ProxyController* controller); + ~WithErrorSyntax_Proxy() override; + + zx_status_t Dispatch_(::fidl::Message message) override; + void ErrorAsPrimitive(ErrorAsPrimitiveCallback callback) override; + void ErrorAsEnum(ErrorAsEnumCallback callback) override; + + private: + WithErrorSyntax_Proxy(const WithErrorSyntax_Proxy&) = delete; + WithErrorSyntax_Proxy& operator=(const WithErrorSyntax_Proxy&) = delete; + + ::fidl::internal::ProxyController* controller_; +}; + +class WithErrorSyntax_Stub : public ::fidl::internal::Stub, public WithErrorSyntax_EventSender { + public: + typedef class ::test::name::WithErrorSyntax WithErrorSyntax_clazz; + explicit WithErrorSyntax_Stub(WithErrorSyntax_clazz* impl); + ~WithErrorSyntax_Stub() override; + + zx_status_t Dispatch_(::fidl::Message message, + ::fidl::internal::PendingResponse response) override; + + private: + WithErrorSyntax_clazz* impl_; +}; + +class WithErrorSyntax_SyncProxy : public WithErrorSyntax_Sync { + public: + explicit WithErrorSyntax_SyncProxy(::zx::channel channel); + ~WithErrorSyntax_SyncProxy() override; + zx_status_t ErrorAsPrimitive(WithErrorSyntax_ErrorAsPrimitive_Result* out_result) override; + zx_status_t ErrorAsEnum(WithErrorSyntax_ErrorAsEnum_Result* out_result) override; + + private: + ::fidl::internal::SynchronousProxy proxy_; + friend class ::fidl::SynchronousInterfacePtr<WithErrorSyntax>; +}; +#endif // __Fuchsia__ } // namespace name } // namespace test namespace fidl { -} // namespace fidl + +template <> +struct CodingTraits<::test::name::WithErrorSyntax_ErrorAsPrimitive_Response> + : public EncodableCodingTraits<::test::name::WithErrorSyntax_ErrorAsPrimitive_Response, 1> {}; + +inline zx_status_t Clone(const ::test::name::WithErrorSyntax_ErrorAsPrimitive_Response& value, + ::test::name::WithErrorSyntax_ErrorAsPrimitive_Response* result) { + return ::test::name::Clone(value, result); +} +template <> +struct CodingTraits<::test::name::WithErrorSyntax_ErrorAsPrimitive_Result> + : public EncodableCodingTraits<::test::name::WithErrorSyntax_ErrorAsPrimitive_Result, 8> {}; + +inline zx_status_t Clone(const ::test::name::WithErrorSyntax_ErrorAsPrimitive_Result& value, + ::test::name::WithErrorSyntax_ErrorAsPrimitive_Result* result) { + return ::test::name::Clone(value, result); +} +template <> +struct CodingTraits<::test::name::WithErrorSyntax_ErrorAsEnum_Response> + : public EncodableCodingTraits<::test::name::WithErrorSyntax_ErrorAsEnum_Response, 1> {}; + +inline zx_status_t Clone(const ::test::name::WithErrorSyntax_ErrorAsEnum_Response& value, + ::test::name::WithErrorSyntax_ErrorAsEnum_Response* result) { + return ::test::name::Clone(value, result); +} +template <> +struct CodingTraits<::test::name::ErrorEnun> { + static constexpr size_t encoded_size = sizeof(::test::name::ErrorEnun); + static void Encode(Encoder* encoder, ::test::name::ErrorEnun* value, size_t offset) { + uint32_t underlying = static_cast<uint32_t>(*value); + ::fidl::Encode(encoder, &underlying, offset); + } + static void Decode(Decoder* decoder, ::test::name::ErrorEnun* value, size_t offset) { + uint32_t underlying = {}; + ::fidl::Decode(decoder, &underlying, offset); + *value = static_cast<::test::name::ErrorEnun>(underlying); + } +}; + +inline zx_status_t Clone(::test::name::ErrorEnun value, + ::test::name::ErrorEnun* result) { + return ::test::name::Clone(value, result); +} +template <> +struct CodingTraits<::test::name::WithErrorSyntax_ErrorAsEnum_Result> + : public EncodableCodingTraits<::test::name::WithErrorSyntax_ErrorAsEnum_Result, 8> {}; + +inline zx_status_t Clone(const ::test::name::WithErrorSyntax_ErrorAsEnum_Result& value, + ::test::name::WithErrorSyntax_ErrorAsEnum_Result* result) { + return ::test::name::Clone(value, result); +}} // namespace fidl diff --git a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.llcpp.cc.golden b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.llcpp.cc.golden index 9fd5a73a1fc..6773e88b3a5 100644 --- a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.llcpp.cc.golden +++ b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.llcpp.cc.golden @@ -6,6 +6,30 @@ namespace test { namespace name { +::test::name::WithErrorSyntax_ErrorAsPrimitive_Result::WithErrorSyntax_ErrorAsPrimitive_Result() { + memset(this, 0, sizeof(WithErrorSyntax_ErrorAsPrimitive_Result)); + tag_ = Tag::Invalid; +} + +::test::name::WithErrorSyntax_ErrorAsPrimitive_Result::~WithErrorSyntax_ErrorAsPrimitive_Result() { + Destroy(); +} + +void ::test::name::WithErrorSyntax_ErrorAsPrimitive_Result::Destroy() { + switch (which()) { + case Tag::kResponse: + response_.~WithErrorSyntax_ErrorAsPrimitive_Response(); + default: + break; + } +} + +void ::test::name::WithErrorSyntax_ErrorAsPrimitive_Result::SizeAndOffsetAssertionHelper() { + static_assert(offsetof(::test::name::WithErrorSyntax_ErrorAsPrimitive_Result, response_) == 4); + static_assert(offsetof(::test::name::WithErrorSyntax_ErrorAsPrimitive_Result, err_) == 4); + static_assert(sizeof(::test::name::WithErrorSyntax_ErrorAsPrimitive_Result) == ::test::name::WithErrorSyntax_ErrorAsPrimitive_Result::PrimarySize); +} + namespace { [[maybe_unused]] @@ -1519,5 +1543,302 @@ zx_status_t WithAndWithoutRequestResponse::SendOnWithResponseEvent(::zx::unowned } +::test::name::WithErrorSyntax_ErrorAsEnum_Result::WithErrorSyntax_ErrorAsEnum_Result() { + memset(this, 0, sizeof(WithErrorSyntax_ErrorAsEnum_Result)); + tag_ = Tag::Invalid; +} + +::test::name::WithErrorSyntax_ErrorAsEnum_Result::~WithErrorSyntax_ErrorAsEnum_Result() { + Destroy(); +} + +void ::test::name::WithErrorSyntax_ErrorAsEnum_Result::Destroy() { + switch (which()) { + case Tag::kResponse: + response_.~WithErrorSyntax_ErrorAsEnum_Response(); + case Tag::kErr: + err_.~ErrorEnun(); + default: + break; + } +} + +void ::test::name::WithErrorSyntax_ErrorAsEnum_Result::SizeAndOffsetAssertionHelper() { + static_assert(offsetof(::test::name::WithErrorSyntax_ErrorAsEnum_Result, response_) == 4); + static_assert(offsetof(::test::name::WithErrorSyntax_ErrorAsEnum_Result, err_) == 4); + static_assert(sizeof(::test::name::WithErrorSyntax_ErrorAsEnum_Result) == ::test::name::WithErrorSyntax_ErrorAsEnum_Result::PrimarySize); +} + +namespace { + +[[maybe_unused]] +constexpr uint32_t kWithErrorSyntax_ErrorAsPrimitive_Ordinal = 2069369145u; +[[maybe_unused]] +constexpr uint32_t kWithErrorSyntax_ErrorAsEnum_Ordinal = 1284890143u; + +} // namespace + +zx_status_t WithErrorSyntax::SyncClient::ErrorAsPrimitive(WithErrorSyntax_ErrorAsPrimitive_Result* out_result) { + constexpr uint32_t _kWriteAllocSize = ::fidl::internal::ClampedMessageSize<ErrorAsPrimitiveRequest>(); + FIDL_ALIGNDECL uint8_t _write_bytes[_kWriteAllocSize] = {}; + auto& _request = *reinterpret_cast<ErrorAsPrimitiveRequest*>(_write_bytes); + _request._hdr.ordinal = kWithErrorSyntax_ErrorAsPrimitive_Ordinal; + ::fidl::BytePart _request_bytes(_write_bytes, _kWriteAllocSize, sizeof(ErrorAsPrimitiveRequest)); + ::fidl::DecodedMessage<ErrorAsPrimitiveRequest> _decoded_request(std::move(_request_bytes)); + auto _encode_request_result = ::fidl::Encode(std::move(_decoded_request)); + if (_encode_request_result.status != ZX_OK) { + return _encode_request_result.status; + } + + constexpr uint32_t _kReadAllocSize = ::fidl::internal::ClampedMessageSize<ErrorAsPrimitiveResponse>(); + FIDL_ALIGNDECL uint8_t _read_bytes[_kReadAllocSize]; + ::fidl::BytePart _response_bytes(_read_bytes, _kReadAllocSize); + auto _call_result = ::fidl::Call<ErrorAsPrimitiveRequest, ErrorAsPrimitiveResponse>( + this->channel_, std::move(_encode_request_result.message), std::move(_response_bytes)); + if (_call_result.status != ZX_OK) { + return _call_result.status; + } + auto _decode_result = ::fidl::Decode(std::move(_call_result.message)); + if (_decode_result.status != ZX_OK) { + return _decode_result.status; + } + auto& _response = *_decode_result.message.message(); + *out_result = std::move(_response.result); + return ZX_OK; +} + +zx_status_t WithErrorSyntax::SyncClient::ErrorAsPrimitive(::fidl::BytePart _response_buffer, WithErrorSyntax_ErrorAsPrimitive_Result* out_result) { + FIDL_ALIGNDECL uint8_t _write_bytes[sizeof(ErrorAsPrimitiveRequest)] = {}; + ::fidl::BytePart _request_buffer(_write_bytes, sizeof(_write_bytes)); + auto& _request = *reinterpret_cast<ErrorAsPrimitiveRequest*>(_request_buffer.data()); + _request._hdr.ordinal = kWithErrorSyntax_ErrorAsPrimitive_Ordinal; + _request_buffer.set_actual(sizeof(ErrorAsPrimitiveRequest)); + ::fidl::DecodedMessage<ErrorAsPrimitiveRequest> _decoded_request(std::move(_request_buffer)); + auto _encode_request_result = ::fidl::Encode(std::move(_decoded_request)); + if (_encode_request_result.status != ZX_OK) { + return _encode_request_result.status; + } + auto _call_result = ::fidl::Call<ErrorAsPrimitiveRequest, ErrorAsPrimitiveResponse>( + this->channel_, std::move(_encode_request_result.message), std::move(_response_buffer)); + if (_call_result.status != ZX_OK) { + return _call_result.status; + } + auto _decode_result = ::fidl::Decode(std::move(_call_result.message)); + if (_decode_result.status != ZX_OK) { + return _decode_result.status; + } + auto& _response = *_decode_result.message.message(); + *out_result = std::move(_response.result); + return ZX_OK; +} + +::fidl::DecodeResult<WithErrorSyntax::ErrorAsPrimitiveResponse> WithErrorSyntax::SyncClient::ErrorAsPrimitive(::fidl::BytePart response_buffer) { + FIDL_ALIGNDECL uint8_t _write_bytes[sizeof(ErrorAsPrimitiveRequest)] = {}; + constexpr uint32_t _write_num_bytes = sizeof(ErrorAsPrimitiveRequest); + ::fidl::BytePart _request_buffer(_write_bytes, sizeof(_write_bytes), _write_num_bytes); + ::fidl::DecodedMessage<ErrorAsPrimitiveRequest> params(std::move(_request_buffer)); + params.message()->_hdr = {}; + params.message()->_hdr.ordinal = kWithErrorSyntax_ErrorAsPrimitive_Ordinal; + auto _encode_request_result = ::fidl::Encode(std::move(params)); + if (_encode_request_result.status != ZX_OK) { + return ::fidl::DecodeResult<WithErrorSyntax::ErrorAsPrimitiveResponse>( + _encode_request_result.status, + _encode_request_result.error, + ::fidl::DecodedMessage<WithErrorSyntax::ErrorAsPrimitiveResponse>()); + } + auto _call_result = ::fidl::Call<ErrorAsPrimitiveRequest, ErrorAsPrimitiveResponse>( + this->channel_, std::move(_encode_request_result.message), std::move(response_buffer)); + if (_call_result.status != ZX_OK) { + return ::fidl::DecodeResult<WithErrorSyntax::ErrorAsPrimitiveResponse>( + _call_result.status, + _call_result.error, + ::fidl::DecodedMessage<WithErrorSyntax::ErrorAsPrimitiveResponse>()); + } + return ::fidl::Decode(std::move(_call_result.message)); +} + + +zx_status_t WithErrorSyntax::SyncClient::ErrorAsEnum(WithErrorSyntax_ErrorAsEnum_Result* out_result) { + constexpr uint32_t _kWriteAllocSize = ::fidl::internal::ClampedMessageSize<ErrorAsEnumRequest>(); + FIDL_ALIGNDECL uint8_t _write_bytes[_kWriteAllocSize] = {}; + auto& _request = *reinterpret_cast<ErrorAsEnumRequest*>(_write_bytes); + _request._hdr.ordinal = kWithErrorSyntax_ErrorAsEnum_Ordinal; + ::fidl::BytePart _request_bytes(_write_bytes, _kWriteAllocSize, sizeof(ErrorAsEnumRequest)); + ::fidl::DecodedMessage<ErrorAsEnumRequest> _decoded_request(std::move(_request_bytes)); + auto _encode_request_result = ::fidl::Encode(std::move(_decoded_request)); + if (_encode_request_result.status != ZX_OK) { + return _encode_request_result.status; + } + + constexpr uint32_t _kReadAllocSize = ::fidl::internal::ClampedMessageSize<ErrorAsEnumResponse>(); + FIDL_ALIGNDECL uint8_t _read_bytes[_kReadAllocSize]; + ::fidl::BytePart _response_bytes(_read_bytes, _kReadAllocSize); + auto _call_result = ::fidl::Call<ErrorAsEnumRequest, ErrorAsEnumResponse>( + this->channel_, std::move(_encode_request_result.message), std::move(_response_bytes)); + if (_call_result.status != ZX_OK) { + return _call_result.status; + } + auto _decode_result = ::fidl::Decode(std::move(_call_result.message)); + if (_decode_result.status != ZX_OK) { + return _decode_result.status; + } + auto& _response = *_decode_result.message.message(); + *out_result = std::move(_response.result); + return ZX_OK; +} + +zx_status_t WithErrorSyntax::SyncClient::ErrorAsEnum(::fidl::BytePart _response_buffer, WithErrorSyntax_ErrorAsEnum_Result* out_result) { + FIDL_ALIGNDECL uint8_t _write_bytes[sizeof(ErrorAsEnumRequest)] = {}; + ::fidl::BytePart _request_buffer(_write_bytes, sizeof(_write_bytes)); + auto& _request = *reinterpret_cast<ErrorAsEnumRequest*>(_request_buffer.data()); + _request._hdr.ordinal = kWithErrorSyntax_ErrorAsEnum_Ordinal; + _request_buffer.set_actual(sizeof(ErrorAsEnumRequest)); + ::fidl::DecodedMessage<ErrorAsEnumRequest> _decoded_request(std::move(_request_buffer)); + auto _encode_request_result = ::fidl::Encode(std::move(_decoded_request)); + if (_encode_request_result.status != ZX_OK) { + return _encode_request_result.status; + } + auto _call_result = ::fidl::Call<ErrorAsEnumRequest, ErrorAsEnumResponse>( + this->channel_, std::move(_encode_request_result.message), std::move(_response_buffer)); + if (_call_result.status != ZX_OK) { + return _call_result.status; + } + auto _decode_result = ::fidl::Decode(std::move(_call_result.message)); + if (_decode_result.status != ZX_OK) { + return _decode_result.status; + } + auto& _response = *_decode_result.message.message(); + *out_result = std::move(_response.result); + return ZX_OK; +} + +::fidl::DecodeResult<WithErrorSyntax::ErrorAsEnumResponse> WithErrorSyntax::SyncClient::ErrorAsEnum(::fidl::BytePart response_buffer) { + FIDL_ALIGNDECL uint8_t _write_bytes[sizeof(ErrorAsEnumRequest)] = {}; + constexpr uint32_t _write_num_bytes = sizeof(ErrorAsEnumRequest); + ::fidl::BytePart _request_buffer(_write_bytes, sizeof(_write_bytes), _write_num_bytes); + ::fidl::DecodedMessage<ErrorAsEnumRequest> params(std::move(_request_buffer)); + params.message()->_hdr = {}; + params.message()->_hdr.ordinal = kWithErrorSyntax_ErrorAsEnum_Ordinal; + auto _encode_request_result = ::fidl::Encode(std::move(params)); + if (_encode_request_result.status != ZX_OK) { + return ::fidl::DecodeResult<WithErrorSyntax::ErrorAsEnumResponse>( + _encode_request_result.status, + _encode_request_result.error, + ::fidl::DecodedMessage<WithErrorSyntax::ErrorAsEnumResponse>()); + } + auto _call_result = ::fidl::Call<ErrorAsEnumRequest, ErrorAsEnumResponse>( + this->channel_, std::move(_encode_request_result.message), std::move(response_buffer)); + if (_call_result.status != ZX_OK) { + return ::fidl::DecodeResult<WithErrorSyntax::ErrorAsEnumResponse>( + _call_result.status, + _call_result.error, + ::fidl::DecodedMessage<WithErrorSyntax::ErrorAsEnumResponse>()); + } + return ::fidl::Decode(std::move(_call_result.message)); +} + + +bool WithErrorSyntax::TryDispatch(Interface* impl, fidl_msg_t* msg, ::fidl::Transaction* txn) { + if (msg->num_bytes < sizeof(fidl_message_header_t)) { + zx_handle_close_many(msg->handles, msg->num_handles); + txn->Close(ZX_ERR_INVALID_ARGS); + return true; + } + fidl_message_header_t* hdr = reinterpret_cast<fidl_message_header_t*>(msg->bytes); + switch (hdr->ordinal) { + case kWithErrorSyntax_ErrorAsPrimitive_Ordinal: { + auto result = ::fidl::DecodeAs<ErrorAsPrimitiveRequest>(msg); + if (result.status != ZX_OK) { + txn->Close(ZX_ERR_INVALID_ARGS); + return true; + } + impl->ErrorAsPrimitive( + Interface::ErrorAsPrimitiveCompleter::Sync(txn)); + return true; + } + case kWithErrorSyntax_ErrorAsEnum_Ordinal: { + auto result = ::fidl::DecodeAs<ErrorAsEnumRequest>(msg); + if (result.status != ZX_OK) { + txn->Close(ZX_ERR_INVALID_ARGS); + return true; + } + impl->ErrorAsEnum( + Interface::ErrorAsEnumCompleter::Sync(txn)); + return true; + } + default: { + return false; + } + } +} + +bool WithErrorSyntax::Dispatch(Interface* impl, fidl_msg_t* msg, ::fidl::Transaction* txn) { + bool found = TryDispatch(impl, msg, txn); + if (!found) { + zx_handle_close_many(msg->handles, msg->num_handles); + txn->Close(ZX_ERR_NOT_SUPPORTED); + } + return found; +} + + +void WithErrorSyntax::Interface::ErrorAsPrimitiveCompleterBase::Reply(WithErrorSyntax_ErrorAsPrimitive_Result result) { + constexpr uint32_t _kWriteAllocSize = ::fidl::internal::ClampedMessageSize<ErrorAsPrimitiveResponse>(); + FIDL_ALIGNDECL uint8_t _write_bytes[_kWriteAllocSize] = {}; + auto& _response = *reinterpret_cast<ErrorAsPrimitiveResponse*>(_write_bytes); + _response._hdr.ordinal = kWithErrorSyntax_ErrorAsPrimitive_Ordinal; + _response.result = std::move(result); + ::fidl::BytePart _response_bytes(_write_bytes, _kWriteAllocSize, sizeof(ErrorAsPrimitiveResponse)); + CompleterBase::SendReply(::fidl::DecodedMessage<ErrorAsPrimitiveResponse>(std::move(_response_bytes))); +} + +void WithErrorSyntax::Interface::ErrorAsPrimitiveCompleterBase::Reply(::fidl::BytePart _buffer, WithErrorSyntax_ErrorAsPrimitive_Result result) { + if (_buffer.capacity() < ErrorAsPrimitiveResponse::PrimarySize) { + CompleterBase::Close(ZX_ERR_INTERNAL); + return; + } + auto& _response = *reinterpret_cast<ErrorAsPrimitiveResponse*>(_buffer.data()); + _response._hdr.ordinal = kWithErrorSyntax_ErrorAsPrimitive_Ordinal; + _response.result = std::move(result); + _buffer.set_actual(sizeof(ErrorAsPrimitiveResponse)); + CompleterBase::SendReply(::fidl::DecodedMessage<ErrorAsPrimitiveResponse>(std::move(_buffer))); +} + +void WithErrorSyntax::Interface::ErrorAsPrimitiveCompleterBase::Reply(::fidl::DecodedMessage<ErrorAsPrimitiveResponse> params) { + params.message()->_hdr = {}; + params.message()->_hdr.ordinal = kWithErrorSyntax_ErrorAsPrimitive_Ordinal; + CompleterBase::SendReply(std::move(params)); +} + + +void WithErrorSyntax::Interface::ErrorAsEnumCompleterBase::Reply(WithErrorSyntax_ErrorAsEnum_Result result) { + constexpr uint32_t _kWriteAllocSize = ::fidl::internal::ClampedMessageSize<ErrorAsEnumResponse>(); + FIDL_ALIGNDECL uint8_t _write_bytes[_kWriteAllocSize] = {}; + auto& _response = *reinterpret_cast<ErrorAsEnumResponse*>(_write_bytes); + _response._hdr.ordinal = kWithErrorSyntax_ErrorAsEnum_Ordinal; + _response.result = std::move(result); + ::fidl::BytePart _response_bytes(_write_bytes, _kWriteAllocSize, sizeof(ErrorAsEnumResponse)); + CompleterBase::SendReply(::fidl::DecodedMessage<ErrorAsEnumResponse>(std::move(_response_bytes))); +} + +void WithErrorSyntax::Interface::ErrorAsEnumCompleterBase::Reply(::fidl::BytePart _buffer, WithErrorSyntax_ErrorAsEnum_Result result) { + if (_buffer.capacity() < ErrorAsEnumResponse::PrimarySize) { + CompleterBase::Close(ZX_ERR_INTERNAL); + return; + } + auto& _response = *reinterpret_cast<ErrorAsEnumResponse*>(_buffer.data()); + _response._hdr.ordinal = kWithErrorSyntax_ErrorAsEnum_Ordinal; + _response.result = std::move(result); + _buffer.set_actual(sizeof(ErrorAsEnumResponse)); + CompleterBase::SendReply(::fidl::DecodedMessage<ErrorAsEnumResponse>(std::move(_buffer))); +} + +void WithErrorSyntax::Interface::ErrorAsEnumCompleterBase::Reply(::fidl::DecodedMessage<ErrorAsEnumResponse> params) { + params.message()->_hdr = {}; + params.message()->_hdr.ordinal = kWithErrorSyntax_ErrorAsEnum_Ordinal; + CompleterBase::SendReply(std::move(params)); +} + + } // namespace name } // namespace test diff --git a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.llcpp.h.golden b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.llcpp.h.golden index 1464b95ac1f..a915085ba5a 100644 --- a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.llcpp.h.golden +++ b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.llcpp.h.golden @@ -15,11 +15,110 @@ namespace test { namespace name { +struct WithErrorSyntax_ErrorAsPrimitive_Response; +struct WithErrorSyntax_ErrorAsPrimitive_Result; +struct WithErrorSyntax_ErrorAsEnum_Response; class KitchenSink; class ChannelProtocol; class SocketControlProtocol; class OvernetInternalProtocol; class WithAndWithoutRequestResponse; +enum class ErrorEnun : uint32_t { + ERR_FOO = 1, + ERR_BAR = 2, +}; + + +struct WithErrorSyntax_ErrorAsEnum_Result; +class WithErrorSyntax; + + + +struct WithErrorSyntax_ErrorAsPrimitive_Response { + static constexpr const fidl_type_t* Type = nullptr; + static constexpr uint32_t MaxNumHandles = 0; + static constexpr uint32_t PrimarySize = 1; + [[maybe_unused]] + static constexpr uint32_t MaxOutOfLine = 0; + + uint8_t __reserved = 0; +}; + +extern "C" const fidl_type_t test_name_WithErrorSyntax_ErrorAsPrimitive_ResultTable; + +struct WithErrorSyntax_ErrorAsPrimitive_Result { + enum class Tag : fidl_union_tag_t { + kResponse = 0, + kErr = 1, + Invalid = ::std::numeric_limits<::fidl_union_tag_t>::max(), + }; + + WithErrorSyntax_ErrorAsPrimitive_Result(); + ~WithErrorSyntax_ErrorAsPrimitive_Result(); + + bool has_invalid_tag() const { return tag_ == Tag::Invalid; } + + bool is_response() const { return tag_ == Tag::kResponse; } + + WithErrorSyntax_ErrorAsPrimitive_Response& mutable_response() { + if (which() != Tag::kResponse) { + Destroy(); + } + tag_ = Tag::kResponse; + return response_; + } + + void set_response(WithErrorSyntax_ErrorAsPrimitive_Response const & v) { + mutable_response() = v; + } + + WithErrorSyntax_ErrorAsPrimitive_Response const & response() const { return response_; } + + bool is_err() const { return tag_ == Tag::kErr; } + + uint32_t& mutable_err() { + if (which() != Tag::kErr) { + Destroy(); + } + tag_ = Tag::kErr; + return err_; + } + + void set_err(uint32_t const & v) { + mutable_err() = v; + } + + uint32_t const & err() const { return err_; } + + Tag which() const { return tag_; } + + static constexpr const fidl_type_t* Type = &test_name_WithErrorSyntax_ErrorAsPrimitive_ResultTable; + static constexpr uint32_t MaxNumHandles = 0; + static constexpr uint32_t PrimarySize = 8; + [[maybe_unused]] + static constexpr uint32_t MaxOutOfLine = 0; + + private: + void Destroy(); + static void SizeAndOffsetAssertionHelper(); + Tag tag_; + union { + WithErrorSyntax_ErrorAsPrimitive_Response response_; + uint32_t err_; + }; +}; + + + +struct WithErrorSyntax_ErrorAsEnum_Response { + static constexpr const fidl_type_t* Type = nullptr; + static constexpr uint32_t MaxNumHandles = 0; + static constexpr uint32_t PrimarySize = 1; + [[maybe_unused]] + static constexpr uint32_t MaxOutOfLine = 0; + + uint8_t __reserved = 0; +}; class KitchenSink final { @@ -781,11 +880,204 @@ class WithAndWithoutRequestResponse final { }; +extern "C" const fidl_type_t test_name_WithErrorSyntax_ErrorAsEnum_ResultTable; + +struct WithErrorSyntax_ErrorAsEnum_Result { + enum class Tag : fidl_union_tag_t { + kResponse = 0, + kErr = 1, + Invalid = ::std::numeric_limits<::fidl_union_tag_t>::max(), + }; + + WithErrorSyntax_ErrorAsEnum_Result(); + ~WithErrorSyntax_ErrorAsEnum_Result(); + + bool has_invalid_tag() const { return tag_ == Tag::Invalid; } + + bool is_response() const { return tag_ == Tag::kResponse; } + + WithErrorSyntax_ErrorAsEnum_Response& mutable_response() { + if (which() != Tag::kResponse) { + Destroy(); + } + tag_ = Tag::kResponse; + return response_; + } + + void set_response(WithErrorSyntax_ErrorAsEnum_Response const & v) { + mutable_response() = v; + } + + WithErrorSyntax_ErrorAsEnum_Response const & response() const { return response_; } + + bool is_err() const { return tag_ == Tag::kErr; } + + ErrorEnun& mutable_err() { + if (which() != Tag::kErr) { + Destroy(); + } + tag_ = Tag::kErr; + return err_; + } + + void set_err(ErrorEnun const & v) { + mutable_err() = v; + } + + ErrorEnun const & err() const { return err_; } + + Tag which() const { return tag_; } + + static constexpr const fidl_type_t* Type = &test_name_WithErrorSyntax_ErrorAsEnum_ResultTable; + static constexpr uint32_t MaxNumHandles = 0; + static constexpr uint32_t PrimarySize = 8; + [[maybe_unused]] + static constexpr uint32_t MaxOutOfLine = 0; + + private: + void Destroy(); + static void SizeAndOffsetAssertionHelper(); + Tag tag_; + union { + WithErrorSyntax_ErrorAsEnum_Response response_; + ErrorEnun err_; + }; +}; + + +class WithErrorSyntax final { + public: + + struct ErrorAsPrimitiveResponse { + FIDL_ALIGNDECL + fidl_message_header_t _hdr; + WithErrorSyntax_ErrorAsPrimitive_Result result; + + static constexpr const fidl_type_t* Type = nullptr; + static constexpr uint32_t MaxNumHandles = 0; + static constexpr uint32_t PrimarySize = 24; + static constexpr uint32_t MaxOutOfLine = 0; + }; + using ErrorAsPrimitiveRequest = ::fidl::AnyZeroArgMessage; + + struct ErrorAsEnumResponse { + FIDL_ALIGNDECL + fidl_message_header_t _hdr; + WithErrorSyntax_ErrorAsEnum_Result result; + + static constexpr const fidl_type_t* Type = nullptr; + static constexpr uint32_t MaxNumHandles = 0; + static constexpr uint32_t PrimarySize = 24; + static constexpr uint32_t MaxOutOfLine = 0; + }; + using ErrorAsEnumRequest = ::fidl::AnyZeroArgMessage; + + + class SyncClient final { + public: + SyncClient(::zx::channel channel) : channel_(std::move(channel)) {} + + ~SyncClient() {} + + zx_status_t ErrorAsPrimitive(WithErrorSyntax_ErrorAsPrimitive_Result* out_result); + + // Caller provides the backing storage for FIDL message via request and response buffers. + zx_status_t ErrorAsPrimitive(::fidl::BytePart _response_buffer, WithErrorSyntax_ErrorAsPrimitive_Result* out_result); + + // Messages are encoded and decoded in-place. + ::fidl::DecodeResult<ErrorAsPrimitiveResponse> ErrorAsPrimitive(::fidl::BytePart response_buffer); + + zx_status_t ErrorAsEnum(WithErrorSyntax_ErrorAsEnum_Result* out_result); + + // Caller provides the backing storage for FIDL message via request and response buffers. + zx_status_t ErrorAsEnum(::fidl::BytePart _response_buffer, WithErrorSyntax_ErrorAsEnum_Result* out_result); + + // Messages are encoded and decoded in-place. + ::fidl::DecodeResult<ErrorAsEnumResponse> ErrorAsEnum(::fidl::BytePart response_buffer); + + private: + ::zx::channel channel_; + }; + + // Pure-virtual interface to be implemented by a server. + class Interface { + public: + Interface() = default; + virtual ~Interface() = default; + using _Outer = WithErrorSyntax; + using _Base = ::fidl::CompleterBase; + + class ErrorAsPrimitiveCompleterBase : public _Base { + public: + void Reply(WithErrorSyntax_ErrorAsPrimitive_Result result); + void Reply(::fidl::BytePart _buffer, WithErrorSyntax_ErrorAsPrimitive_Result result); + void Reply(::fidl::DecodedMessage<ErrorAsPrimitiveResponse> params); + + protected: + using ::fidl::CompleterBase::CompleterBase; + }; + + using ErrorAsPrimitiveCompleter = ::fidl::Completer<ErrorAsPrimitiveCompleterBase>; + + virtual void ErrorAsPrimitive(ErrorAsPrimitiveCompleter::Sync _completer) = 0; + + class ErrorAsEnumCompleterBase : public _Base { + public: + void Reply(WithErrorSyntax_ErrorAsEnum_Result result); + void Reply(::fidl::BytePart _buffer, WithErrorSyntax_ErrorAsEnum_Result result); + void Reply(::fidl::DecodedMessage<ErrorAsEnumResponse> params); + + protected: + using ::fidl::CompleterBase::CompleterBase; + }; + + using ErrorAsEnumCompleter = ::fidl::Completer<ErrorAsEnumCompleterBase>; + + virtual void ErrorAsEnum(ErrorAsEnumCompleter::Sync _completer) = 0; + + }; + + // Attempts to dispatch the incoming message to a handler function in the server implementation. + // If there is no matching handler, it returns false, leaving the message and transaction intact. + // In all other cases, it consumes the message and returns true. + // It is possible to chain multiple TryDispatch functions in this manner. + static bool TryDispatch(Interface* impl, fidl_msg_t* msg, ::fidl::Transaction* txn); + + // Dispatches the incoming message to one of the handlers functions in the interface. + // If there is no matching handler, it closes all the handles in |msg| and closes the channel with + // a |ZX_ERR_NOT_SUPPORTED| epitaph, before returning false. The message should then be discarded. + static bool Dispatch(Interface* impl, fidl_msg_t* msg, ::fidl::Transaction* txn); + + // Same as |Dispatch|, but takes a |void*| instead of |Interface*|. Only used with |fidl::Bind| + // to reduce template expansion. + // Do not call this method manually. Use |Dispatch| instead. + static bool TypeErasedDispatch(void* impl, fidl_msg_t* msg, ::fidl::Transaction* txn) { + return Dispatch(static_cast<Interface*>(impl), msg, txn); + } + +}; + } // namespace name } // namespace test namespace fidl { +template <> +struct IsFidlType<::test::name::WithErrorSyntax_ErrorAsPrimitive_Response> : public std::true_type {}; +static_assert(std::is_standard_layout_v<::test::name::WithErrorSyntax_ErrorAsPrimitive_Response>); +static_assert(offsetof(::test::name::WithErrorSyntax_ErrorAsPrimitive_Response, __reserved) == 0); +static_assert(sizeof(::test::name::WithErrorSyntax_ErrorAsPrimitive_Response) == ::test::name::WithErrorSyntax_ErrorAsPrimitive_Response::PrimarySize); + +template <> +struct IsFidlType<::test::name::WithErrorSyntax_ErrorAsPrimitive_Result> : public std::true_type {}; +static_assert(std::is_standard_layout_v<::test::name::WithErrorSyntax_ErrorAsPrimitive_Result>); + +template <> +struct IsFidlType<::test::name::WithErrorSyntax_ErrorAsEnum_Response> : public std::true_type {}; +static_assert(std::is_standard_layout_v<::test::name::WithErrorSyntax_ErrorAsEnum_Response>); +static_assert(offsetof(::test::name::WithErrorSyntax_ErrorAsEnum_Response, __reserved) == 0); +static_assert(sizeof(::test::name::WithErrorSyntax_ErrorAsEnum_Response) == ::test::name::WithErrorSyntax_ErrorAsEnum_Response::PrimarySize); + template <> struct IsFidlType<::test::name::KitchenSink::MethodARequest> : public std::true_type {}; template <> @@ -974,4 +1266,24 @@ static_assert(sizeof(::test::name::WithAndWithoutRequestResponse::OnWithResponse == ::test::name::WithAndWithoutRequestResponse::OnWithResponseResponse::PrimarySize); static_assert(offsetof(::test::name::WithAndWithoutRequestResponse::OnWithResponseResponse, ret) == 16); +template <> +struct IsFidlType<::test::name::WithErrorSyntax_ErrorAsEnum_Result> : public std::true_type {}; +static_assert(std::is_standard_layout_v<::test::name::WithErrorSyntax_ErrorAsEnum_Result>); + +template <> +struct IsFidlType<::test::name::WithErrorSyntax::ErrorAsPrimitiveResponse> : public std::true_type {}; +template <> +struct IsFidlMessage<::test::name::WithErrorSyntax::ErrorAsPrimitiveResponse> : public std::true_type {}; +static_assert(sizeof(::test::name::WithErrorSyntax::ErrorAsPrimitiveResponse) + == ::test::name::WithErrorSyntax::ErrorAsPrimitiveResponse::PrimarySize); +static_assert(offsetof(::test::name::WithErrorSyntax::ErrorAsPrimitiveResponse, result) == 16); + +template <> +struct IsFidlType<::test::name::WithErrorSyntax::ErrorAsEnumResponse> : public std::true_type {}; +template <> +struct IsFidlMessage<::test::name::WithErrorSyntax::ErrorAsEnumResponse> : public std::true_type {}; +static_assert(sizeof(::test::name::WithErrorSyntax::ErrorAsEnumResponse) + == ::test::name::WithErrorSyntax::ErrorAsEnumResponse::PrimarySize); +static_assert(offsetof(::test::name::WithErrorSyntax::ErrorAsEnumResponse, result) == 16); + } // namespace fidl diff --git a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.overnet_internal.cc.golden b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.overnet_internal.cc.golden index fb9b26c2b45..7c8279bd599 100644 --- a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.overnet_internal.cc.golden +++ b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.overnet_internal.cc.golden @@ -4,6 +4,9 @@ namespace test { namespace name { + + + namespace { @@ -264,5 +267,9 @@ void OvernetInternalProtocol_Stub::EventA(int64_t a, int64_t b) { + + + + } // namespace name } // namespace test \ No newline at end of file diff --git a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.overnet_internal.h.golden b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.overnet_internal.h.golden index d98f9f21c56..87d5c98a5d7 100644 --- a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.overnet_internal.h.golden +++ b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.overnet_internal.h.golden @@ -5,6 +5,9 @@ namespace test { namespace name { + + + class KitchenSink; @@ -26,6 +29,13 @@ class OvernetInternalProtocol_Stub; + + + + + + + @@ -117,6 +127,13 @@ class OvernetInternalProtocol_Stub : public ::overnet::FidlStream, public Overne + + + + + + + @@ -128,6 +145,10 @@ class OvernetInternalProtocol_Stub : public ::overnet::FidlStream, public Overne + + + + diff --git a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.rs.golden b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.rs.golden index 95d0930616e..d86201adbce 100644 --- a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.rs.golden +++ b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json.rs.golden @@ -22,6 +22,30 @@ use fidl::{ }; +fidl_enum! { + ErrorEnun(u32) { + ErrFoo = 1, + ErrBar = 2, + } +} + + +type WithErrorSyntaxErrorAsPrimitiveResult = std::result::Result< WithErrorSyntaxErrorAsPrimitiveResponse , u32 >; + + +type WithErrorSyntaxErrorAsEnumResult = std::result::Result< WithErrorSyntaxErrorAsEnumResponse , ErrorEnun >; + + + +fidl_empty_struct!( + WithErrorSyntaxErrorAsPrimitiveResponse +); + + +fidl_empty_struct!( + WithErrorSyntaxErrorAsEnumResponse +); + #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct WithAndWithoutRequestResponseMarker; @@ -1431,6 +1455,748 @@ impl WithAndWithoutRequestResponseWithRequestWithResponseResponder { } +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] +pub struct WithErrorSyntaxMarker; + +impl fidl::endpoints::ServiceMarker for WithErrorSyntaxMarker { + type Proxy = WithErrorSyntaxProxy; + type RequestStream = WithErrorSyntaxRequestStream; + const NAME: &'static str = ""; +} + +pub trait WithErrorSyntaxProxyInterface: Send + Sync { + type ErrorAsPrimitiveResponseFut: futures::Future<Output = Result<(WithErrorSyntaxErrorAsPrimitiveResult), fidl::Error>> + Send; + fn error_as_primitive(&self, + )-> Self::ErrorAsPrimitiveResponseFut; + type ErrorAsEnumResponseFut: futures::Future<Output = Result<(WithErrorSyntaxErrorAsEnumResult), fidl::Error>> + Send; + fn error_as_enum(&self, + )-> Self::ErrorAsEnumResponseFut; +} + +#[derive(Debug)] +pub struct WithErrorSyntaxSynchronousProxy { + client: fidl::client::sync::Client, +} + +impl WithErrorSyntaxSynchronousProxy { + pub fn new(channel: zx::Channel) -> Self { + Self { client: fidl::client::sync::Client::new(channel) } + } + + pub fn into_channel(self) -> zx::Channel { + self.client.into_channel() + } + pub fn error_as_primitive(&mut self,___deadline: zx::Time,) -> Result<(WithErrorSyntaxErrorAsPrimitiveResult), fidl::Error> {self.client.send_query(&mut (), + 2069369145, + ___deadline, + )} + pub fn error_as_enum(&mut self,___deadline: zx::Time,) -> Result<(WithErrorSyntaxErrorAsEnumResult), fidl::Error> {self.client.send_query(&mut (), + 1284890143, + ___deadline, + )} +} + +#[derive(Debug, Clone)] +pub struct WithErrorSyntaxProxy { + client: fidl::client::Client, +} + +impl fidl::endpoints::Proxy for WithErrorSyntaxProxy { + type Service = WithErrorSyntaxMarker; + fn from_channel(inner: ::fuchsia_async::Channel) -> Self { + Self::new(inner) + } +} + +impl ::std::ops::Deref for WithErrorSyntaxProxy { + type Target = fidl::client::Client; + + fn deref(&self) -> &Self::Target { + &self.client + } +} + +/// Proxy object for communicating with interface WithErrorSyntax +impl WithErrorSyntaxProxy { + /// Create a new Proxy for WithErrorSyntax + pub fn new(channel: ::fuchsia_async::Channel) -> Self { + Self { client: fidl::client::Client::new(channel) } + } + + /// Attempt to convert the Proxy back into a channel. + /// + /// This will only succeed if there are no active clones of this Proxy + /// and no currently-alive EventStream or response futures that came from + /// this Proxy. + pub fn into_channel(self) -> Result<::fuchsia_async::Channel, Self> { + self.client.into_channel().map_err(|client| Self { client }) + } + + /// Get a Stream of events from the remote end of the WithErrorSyntax interface + pub fn take_event_stream(&self) -> WithErrorSyntaxEventStream { + WithErrorSyntaxEventStream { + event_receiver: self.client.take_event_receiver(), + } + } + pub fn error_as_primitive(&self, + )-> fidl::client::QueryResponseFut<(WithErrorSyntaxErrorAsPrimitiveResult)> { + WithErrorSyntaxProxyInterface::error_as_primitive(self, + ) + } + pub fn error_as_enum(&self, + )-> fidl::client::QueryResponseFut<(WithErrorSyntaxErrorAsEnumResult)> { + WithErrorSyntaxProxyInterface::error_as_enum(self, + ) + } +} + +impl WithErrorSyntaxProxyInterface for WithErrorSyntaxProxy { + type ErrorAsPrimitiveResponseFut = fidl::client::QueryResponseFut<(WithErrorSyntaxErrorAsPrimitiveResult)>; + fn error_as_primitive(&self, + )-> Self::ErrorAsPrimitiveResponseFut { + self.client.send_query(&mut (), 2069369145) + } + type ErrorAsEnumResponseFut = fidl::client::QueryResponseFut<(WithErrorSyntaxErrorAsEnumResult)>; + fn error_as_enum(&self, + )-> Self::ErrorAsEnumResponseFut { + self.client.send_query(&mut (), 1284890143) + }} + +pub struct WithErrorSyntaxEventStream { + event_receiver: fidl::client::EventReceiver, +} + +impl ::std::marker::Unpin for WithErrorSyntaxEventStream {} + +impl futures::stream::FusedStream for WithErrorSyntaxEventStream { + fn is_terminated(&self) -> bool { + self.event_receiver.is_terminated() + } +} + +impl futures::Stream for WithErrorSyntaxEventStream { + type Item = Result<WithErrorSyntaxEvent, fidl::Error>; + + fn poll_next(mut self: ::std::pin::Pin<&mut Self>, lw: &futures::task::Waker) + -> futures::Poll<Option<Self::Item>> + { + let mut buf = match futures::ready!( + futures::stream::StreamExt::poll_next_unpin(&mut self.event_receiver, lw)? + ) { + Some(buf) => buf, + None => return futures::Poll::Ready(None), + }; + let (bytes, _handles) = buf.split_mut(); + let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?; + + #[allow(unreachable_patterns)] // GenOrdinal and Ordinal can overlap + futures::Poll::Ready(Some(match tx_header.ordinal { + _ => Err(fidl::Error::UnknownOrdinal { + ordinal: tx_header.ordinal, + service_name: <WithErrorSyntaxMarker as fidl::endpoints::ServiceMarker>::NAME, + }) + })) + } +} + +#[derive(Debug)] +pub enum WithErrorSyntaxEvent { + + + } + +pub struct WithErrorSyntaxEventSender<'a> { + // Some protocols don't define events which would render this channel unused. + #[allow(unused)] + channel: zx::Unowned<'a, zx::Channel>, +} +impl <'a> WithErrorSyntaxEventSender<'a> { + pub fn new(channel: zx::Unowned<'a, zx::Channel>) -> Self { + Self { channel } + } +} + +#[deprecated(note = "use WithErrorSyntaxRequestStream instead")] +pub trait WithErrorSyntax { + type OnOpenFut: futures::Future<Output = ()> + Send; + fn on_open(&mut self, control_handle: WithErrorSyntaxControlHandle) -> Self::OnOpenFut; + type ErrorAsPrimitiveFut: futures::Future<Output = ()> + Send; + fn error_as_primitive (&mut self, + response_chan: WithErrorSyntaxErrorAsPrimitiveResponder, + ) -> Self::ErrorAsPrimitiveFut; + + type ErrorAsEnumFut: futures::Future<Output = ()> + Send; + fn error_as_enum (&mut self, + response_chan: WithErrorSyntaxErrorAsEnumResponder, + ) -> Self::ErrorAsEnumFut; + + + fn serve(mut self, channel: ::fuchsia_async::Channel) + -> WithErrorSyntaxServer<Self> + where Self: Sized + { + let inner = ::std::sync::Arc::new(fidl::ServeInner::new(channel)); + let on_open_fut = self.on_open( + WithErrorSyntaxControlHandle { + inner: inner.clone(), + } + ); + WithErrorSyntaxServer { + server: self, + inner: inner.clone(), + on_open_fut: Some(on_open_fut),error_as_primitive_futures: futures::stream::FuturesUnordered::new(),error_as_enum_futures: futures::stream::FuturesUnordered::new(), + } + } +} + +pub struct WithErrorSyntaxServer<T: WithErrorSyntax> { + #[allow(dead_code)] // not used if no methods are present + server: T, + inner: ::std::sync::Arc<fidl::ServeInner>, + on_open_fut: Option<T::OnOpenFut>,error_as_primitive_futures: futures::stream::FuturesUnordered<T::ErrorAsPrimitiveFut>,error_as_enum_futures: futures::stream::FuturesUnordered<T::ErrorAsEnumFut>, +} + +// Safety: only the OnOpen fut is held directly, so it's the only one that +// is projected to, so it's the only one that needs to be Unpin for the Impl +// struct to be Unpin. +impl<T: WithErrorSyntax> ::std::marker::Unpin for WithErrorSyntaxServer<T> +where T::OnOpenFut: ::std::marker::Unpin, +{} + +impl<T: WithErrorSyntax> WithErrorSyntaxServer<T> { + pub fn control_handle(&self) -> WithErrorSyntaxControlHandle { + WithErrorSyntaxControlHandle { + inner: self.inner.clone(), + } + } +} + +impl<T: WithErrorSyntax> futures::Future for WithErrorSyntaxServer<T> { + type Output = Result<(), fidl::Error>; + + fn poll( + mut self: ::std::pin::Pin<&mut Self>, + lw: &futures::task::Waker, + ) -> futures::Poll<Self::Output> { + // safety: the only potentially !Unpin field is on_open_fut, which we make sure + // isn't moved below + let this = unsafe { ::std::pin::Pin::get_unchecked_mut(self) }; + loop { + let mut made_progress_this_loop_iter = false; + + if this.inner.poll_shutdown(lw) { + return futures::Poll::Ready(Ok(())); + } + + unsafe { + // Safety: ensure that on_open isn't moved + let completed_on_open = if let Some(on_open_fut) = &mut this.on_open_fut { + match futures::Future::poll(::std::pin::Pin::new_unchecked(on_open_fut), lw) { + futures::Poll::Ready(()) => true, + futures::Poll::Pending => false, + } + } else { + false + }; + + if completed_on_open { + made_progress_this_loop_iter = true; + this.on_open_fut = None; + } + }match futures::stream::StreamExt::poll_next_unpin( + &mut this.error_as_primitive_futures, lw + ) { + futures::Poll::Ready(Some(())) => made_progress_this_loop_iter = true, + _ => {}, + }match futures::stream::StreamExt::poll_next_unpin( + &mut this.error_as_enum_futures, lw + ) { + futures::Poll::Ready(Some(())) => made_progress_this_loop_iter = true, + _ => {}, + } + + let poll_done = ::fidl::encoding::with_tls_coding_bufs(|bytes, handles| { + match ::futures::ready!(this.inner.channel().read(bytes, handles, lw)) { + Ok(()) => {}, + Err(zx::Status::PEER_CLOSED) => return futures::Poll::Ready(Ok(true)), + Err(e) => return futures::Poll::Ready(Err(fidl::Error::ServerRequestRead(e))), + } + + { + // A message has been received from the channel + let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?; + + #[allow(unreachable_patterns)] // GenOrdinal and Ordinal can overlap + match header.ordinal { + 2069369145 | 2069369145 => { + let mut req: () = fidl::encoding::Decodable::new_empty(); + fidl::encoding::Decoder::decode_into(_body_bytes, handles, &mut req)?; + let control_handle = WithErrorSyntaxControlHandle { + inner: this.inner.clone(), + }; + this.error_as_primitive_futures.push( + this.server.error_as_primitive(WithErrorSyntaxErrorAsPrimitiveResponder { + control_handle: ::std::mem::ManuallyDrop::new(control_handle), + tx_id: header.tx_id, + ordinal: header.ordinal, + }) + ); + ::futures::Poll::Ready(Ok(false)) + } + 1284890143 | 1284890143 => { + let mut req: () = fidl::encoding::Decodable::new_empty(); + fidl::encoding::Decoder::decode_into(_body_bytes, handles, &mut req)?; + let control_handle = WithErrorSyntaxControlHandle { + inner: this.inner.clone(), + }; + this.error_as_enum_futures.push( + this.server.error_as_enum(WithErrorSyntaxErrorAsEnumResponder { + control_handle: ::std::mem::ManuallyDrop::new(control_handle), + tx_id: header.tx_id, + ordinal: header.ordinal, + }) + ); + ::futures::Poll::Ready(Ok(false)) + } + // TODO(cramertj) handle control/fileio messages + _ => return futures::Poll::Ready(Err(fidl::Error::UnknownOrdinal { + ordinal: header.ordinal, + service_name: "unknown fidl", // TODO(cramertj) + })), + } + } + })?; + + match poll_done { + ::futures::Poll::Ready(true) => return ::futures::Poll::Ready(Ok(())), + ::futures::Poll::Ready(false) => {}, + ::futures::Poll::Pending if made_progress_this_loop_iter => {}, // continue + ::futures::Poll::Pending => return ::futures::Poll::Pending, + } + }} +} + +/// A Stream of incoming requests for WithErrorSyntax +pub struct WithErrorSyntaxRequestStream { + inner: ::std::sync::Arc<fidl::ServeInner>, + is_terminated: bool, +} + +impl ::std::marker::Unpin for WithErrorSyntaxRequestStream {} + +impl futures::stream::FusedStream for WithErrorSyntaxRequestStream { + fn is_terminated(&self) -> bool { + self.is_terminated + } +} + +impl fidl::endpoints::RequestStream for WithErrorSyntaxRequestStream { + type Service = WithErrorSyntaxMarker; + + /// Consume a channel to make a WithErrorSyntaxRequestStream + fn from_channel(channel: ::fuchsia_async::Channel) -> Self { + Self { + inner: ::std::sync::Arc::new(fidl::ServeInner::new(channel)), + is_terminated: false, + } + } + + /// ControlHandle for the remote connection + type ControlHandle = WithErrorSyntaxControlHandle; + + /// ControlHandle for the remote connection + fn control_handle(&self) -> Self::ControlHandle { + WithErrorSyntaxControlHandle { inner: self.inner.clone() } + } + + fn into_inner(self) -> (::std::sync::Arc<fidl::ServeInner>, bool) { + (self.inner, self.is_terminated) + } + + fn from_inner(inner: ::std::sync::Arc<fidl::ServeInner>, is_terminated: bool) + -> Self + { + Self { inner, is_terminated } + } +} + +impl futures::Stream for WithErrorSyntaxRequestStream { + type Item = Result<WithErrorSyntaxRequest, fidl::Error>; + + fn poll_next(mut self: ::std::pin::Pin<&mut Self>, lw: &futures::task::Waker) + -> futures::Poll<Option<Self::Item>> + { + let this = &mut *self; + if this.inner.poll_shutdown(lw) { + this.is_terminated = true; + return futures::Poll::Ready(None); + } + if this.is_terminated { + panic!("polled WithErrorSyntaxRequestStream after completion"); + } + ::fidl::encoding::with_tls_coding_bufs(|bytes, handles| { + match this.inner.channel().read(bytes, handles, lw) { + futures::Poll::Ready(Ok(())) => {}, + futures::Poll::Pending => return futures::Poll::Pending, + futures::Poll::Ready(Err(zx::Status::PEER_CLOSED)) => { + this.is_terminated = true; + return futures::Poll::Ready(None) + }, + futures::Poll::Ready(Err(e)) => + return futures::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(e)))), + } + + // A message has been received from the channel + let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?; + + #[allow(unreachable_patterns)] // GenOrdinal and Ordinal can overlap + futures::Poll::Ready(Some(match header.ordinal { + 2069369145 | 2069369145 => { + let mut req: () = fidl::encoding::Decodable::new_empty(); + fidl::encoding::Decoder::decode_into(_body_bytes, handles, &mut req)?; + let control_handle = WithErrorSyntaxControlHandle { + inner: this.inner.clone(), + }; + + Ok(WithErrorSyntaxRequest::ErrorAsPrimitive {responder:WithErrorSyntaxErrorAsPrimitiveResponder { + control_handle: ::std::mem::ManuallyDrop::new(control_handle), + tx_id: header.tx_id, + ordinal: header.ordinal, + },}) + } + 1284890143 | 1284890143 => { + let mut req: () = fidl::encoding::Decodable::new_empty(); + fidl::encoding::Decoder::decode_into(_body_bytes, handles, &mut req)?; + let control_handle = WithErrorSyntaxControlHandle { + inner: this.inner.clone(), + }; + + Ok(WithErrorSyntaxRequest::ErrorAsEnum {responder:WithErrorSyntaxErrorAsEnumResponder { + control_handle: ::std::mem::ManuallyDrop::new(control_handle), + tx_id: header.tx_id, + ordinal: header.ordinal, + },}) + } + _ => Err(fidl::Error::UnknownOrdinal { + ordinal: header.ordinal, + service_name: <WithErrorSyntaxMarker as fidl::endpoints::ServiceMarker>::NAME, + }), + })) + }) + } +} +pub enum WithErrorSyntaxRequest { + ErrorAsPrimitive { + responder: WithErrorSyntaxErrorAsPrimitiveResponder,}, + ErrorAsEnum { + responder: WithErrorSyntaxErrorAsEnumResponder,}, +} + +pub struct WithErrorSyntaxEncoder; +impl WithErrorSyntaxEncoder { + pub fn encode_error_as_primitive_request<'a>( + out_bytes: &'a mut Vec<u8>, + out_handles: &'a mut Vec<zx::Handle>, + tx_id: u32,) -> Result<(), fidl::Error> { + let header = fidl::encoding::TransactionHeader { + tx_id,flags: 0, + ordinal: 2069369145, + }; + let mut body = (); + let mut msg = fidl::encoding::TransactionMessage { header, body: &mut body }; + fidl::encoding::Encoder::encode(out_bytes, out_handles, &mut msg)?; + Ok(()) + } + pub fn encode_error_as_primitive_response<'a>( + out_bytes: &'a mut Vec<u8>, + out_handles: &'a mut Vec<zx::Handle>, + tx_id: u32,mut in_result: &mut WithErrorSyntaxErrorAsPrimitiveResult,) -> Result<(), fidl::Error> { + let header = fidl::encoding::TransactionHeader { + tx_id,flags: 0, + ordinal: 2069369145, + }; + let mut body = (in_result,); + let mut msg = fidl::encoding::TransactionMessage { header, body: &mut body }; + fidl::encoding::Encoder::encode(out_bytes, out_handles, &mut msg)?; + Ok(()) + } + pub fn encode_error_as_enum_request<'a>( + out_bytes: &'a mut Vec<u8>, + out_handles: &'a mut Vec<zx::Handle>, + tx_id: u32,) -> Result<(), fidl::Error> { + let header = fidl::encoding::TransactionHeader { + tx_id,flags: 0, + ordinal: 1284890143, + }; + let mut body = (); + let mut msg = fidl::encoding::TransactionMessage { header, body: &mut body }; + fidl::encoding::Encoder::encode(out_bytes, out_handles, &mut msg)?; + Ok(()) + } + pub fn encode_error_as_enum_response<'a>( + out_bytes: &'a mut Vec<u8>, + out_handles: &'a mut Vec<zx::Handle>, + tx_id: u32,mut in_result: &mut WithErrorSyntaxErrorAsEnumResult,) -> Result<(), fidl::Error> { + let header = fidl::encoding::TransactionHeader { + tx_id,flags: 0, + ordinal: 1284890143, + }; + let mut body = (in_result,); + let mut msg = fidl::encoding::TransactionMessage { header, body: &mut body }; + fidl::encoding::Encoder::encode(out_bytes, out_handles, &mut msg)?; + Ok(()) + }} + +#[deprecated(note = "use WithErrorSyntaxRequestStream instead")] +pub struct WithErrorSyntaxImpl< + State, +OnOpen: FnMut(&mut State, WithErrorSyntaxControlHandle) -> OnOpenFut, +OnOpenFut: futures::Future<Output = ()> + Send, + ErrorAsPrimitive: FnMut(&mut State,WithErrorSyntaxErrorAsPrimitiveResponder) -> ErrorAsPrimitiveFut, + ErrorAsPrimitiveFut: futures::Future<Output = ()> + Send, + ErrorAsEnum: FnMut(&mut State,WithErrorSyntaxErrorAsEnumResponder) -> ErrorAsEnumFut, + ErrorAsEnumFut: futures::Future<Output = ()> + Send, +> { + pub state: State, + pub on_open: OnOpen, + pub error_as_primitive: ErrorAsPrimitive, + pub error_as_enum: ErrorAsEnum, +} + +// Unpin is never projected for the Impl struct +impl< + State, +OnOpen: FnMut(&mut State, WithErrorSyntaxControlHandle) -> OnOpenFut, +OnOpenFut: futures::Future<Output = ()> + Send, + ErrorAsPrimitive: FnMut(&mut State,WithErrorSyntaxErrorAsPrimitiveResponder) -> ErrorAsPrimitiveFut, + ErrorAsPrimitiveFut: futures::Future<Output = ()> + Send, + ErrorAsEnum: FnMut(&mut State,WithErrorSyntaxErrorAsEnumResponder) -> ErrorAsEnumFut, + ErrorAsEnumFut: futures::Future<Output = ()> + Send, +> ::std::marker::Unpin for WithErrorSyntaxImpl<State, OnOpen, OnOpenFut, + ErrorAsPrimitive, + ErrorAsPrimitiveFut, + ErrorAsEnum, + ErrorAsEnumFut, +> +{} + +impl< + State, +OnOpen: FnMut(&mut State, WithErrorSyntaxControlHandle) -> OnOpenFut, +OnOpenFut: futures::Future<Output = ()> + Send, + ErrorAsPrimitive: FnMut(&mut State,WithErrorSyntaxErrorAsPrimitiveResponder) -> ErrorAsPrimitiveFut, + ErrorAsPrimitiveFut: futures::Future<Output = ()> + Send, + ErrorAsEnum: FnMut(&mut State,WithErrorSyntaxErrorAsEnumResponder) -> ErrorAsEnumFut, + ErrorAsEnumFut: futures::Future<Output = ()> + Send, +> WithErrorSyntax for WithErrorSyntaxImpl<State, OnOpen, OnOpenFut, + ErrorAsPrimitive, + ErrorAsPrimitiveFut, + ErrorAsEnum, + ErrorAsEnumFut, +> +{ + type OnOpenFut = OnOpenFut; + fn on_open(&mut self, response_chan: WithErrorSyntaxControlHandle) -> Self::OnOpenFut { + (self.on_open)(&mut self.state, response_chan) + } + type ErrorAsPrimitiveFut = ErrorAsPrimitiveFut; + fn error_as_primitive (&mut self, + response_chan: WithErrorSyntaxErrorAsPrimitiveResponder + ) -> Self::ErrorAsPrimitiveFut + { + (self.error_as_primitive)( + &mut self.state, + response_chan + ) + } + + type ErrorAsEnumFut = ErrorAsEnumFut; + fn error_as_enum (&mut self, + response_chan: WithErrorSyntaxErrorAsEnumResponder + ) -> Self::ErrorAsEnumFut + { + (self.error_as_enum)( + &mut self.state, + response_chan + ) + } + +} + +#[derive(Clone)] +pub struct WithErrorSyntaxControlHandle { + inner: ::std::sync::Arc<fidl::ServeInner>, +} + +impl ::std::ops::Deref for WithErrorSyntaxControlHandle { + type Target = ::std::sync::Arc<fidl::ServeInner>; + + fn deref(&self) -> &Self::Target { + &self.inner + } +} + + +impl WithErrorSyntaxControlHandle { + pub fn shutdown(&self) { + self.inner.shutdown() + }} + +/* beginning of response types */ +#[must_use = "FIDL methods require a response to be sent"] +pub struct WithErrorSyntaxErrorAsPrimitiveResponder { + control_handle: ::std::mem::ManuallyDrop<WithErrorSyntaxControlHandle>, + tx_id: u32, + ordinal: u32, +} + +impl ::std::ops::Drop for WithErrorSyntaxErrorAsPrimitiveResponder { + fn drop(&mut self) { + // Shutdown the channel if the responder is dropped without sending a response + // so that the client doesn't hang. To prevent this behavior, some methods + // call "drop_without_shutdown" + self.control_handle.shutdown(); + // Safety: drops once, never accessed again + unsafe { ::std::mem::ManuallyDrop::drop(&mut self.control_handle) }; + } +} + +impl WithErrorSyntaxErrorAsPrimitiveResponder { + pub fn control_handle(&self) -> &WithErrorSyntaxControlHandle { + &self.control_handle + } + + /// Drop the Responder without setting the channel to shutdown. + /// + /// This method shouldn't normally be used-- instead, send a response + /// to prevent the channel from shutting down. + pub fn drop_without_shutdown(mut self) { + // Safety: drops once, never accessed again due to mem::forget + unsafe { ::std::mem::ManuallyDrop::drop(&mut self.control_handle) }; + // Prevent Drop from running (which would shut down the channel) + ::std::mem::forget(self); + } + + /// Sends a response to the FIDL transaction. + /// + /// Sets the channel to shutdown if an error occurs. + pub fn send(self,mut result: &mut WithErrorSyntaxErrorAsPrimitiveResult,) -> Result<(), fidl::Error> { + let r = self.send_raw(result,); + if r.is_err() { + self.control_handle.shutdown(); + } + self.drop_without_shutdown(); + r + } + + /// Similar to "send" but does not shutdown the channel if + /// an error occurs. + pub fn send_no_shutdown_on_err(self,mut result: &mut WithErrorSyntaxErrorAsPrimitiveResult,) -> Result<(), fidl::Error> { + let r = self.send_raw(result,); + self.drop_without_shutdown(); + r + } + + fn send_raw(&self,mut result: &mut WithErrorSyntaxErrorAsPrimitiveResult,) -> Result<(), fidl::Error> { + let header = fidl::encoding::TransactionHeader { + tx_id: self.tx_id, + flags: 0, + ordinal: self.ordinal, + }; + + let mut response = (result); + + let mut msg = fidl::encoding::TransactionMessage { + header, + body: &mut response, + }; + + ::fidl::encoding::with_tls_coding_bufs(|bytes, handles| { + ::fidl::encoding::Encoder::encode(bytes, handles, &mut msg)?; + self.control_handle.inner.channel().write(&*bytes, &mut *handles) + .map_err(fidl::Error::ServerResponseWrite)?; + Ok(()) + }) + } +} +#[must_use = "FIDL methods require a response to be sent"] +pub struct WithErrorSyntaxErrorAsEnumResponder { + control_handle: ::std::mem::ManuallyDrop<WithErrorSyntaxControlHandle>, + tx_id: u32, + ordinal: u32, +} + +impl ::std::ops::Drop for WithErrorSyntaxErrorAsEnumResponder { + fn drop(&mut self) { + // Shutdown the channel if the responder is dropped without sending a response + // so that the client doesn't hang. To prevent this behavior, some methods + // call "drop_without_shutdown" + self.control_handle.shutdown(); + // Safety: drops once, never accessed again + unsafe { ::std::mem::ManuallyDrop::drop(&mut self.control_handle) }; + } +} + +impl WithErrorSyntaxErrorAsEnumResponder { + pub fn control_handle(&self) -> &WithErrorSyntaxControlHandle { + &self.control_handle + } + + /// Drop the Responder without setting the channel to shutdown. + /// + /// This method shouldn't normally be used-- instead, send a response + /// to prevent the channel from shutting down. + pub fn drop_without_shutdown(mut self) { + // Safety: drops once, never accessed again due to mem::forget + unsafe { ::std::mem::ManuallyDrop::drop(&mut self.control_handle) }; + // Prevent Drop from running (which would shut down the channel) + ::std::mem::forget(self); + } + + /// Sends a response to the FIDL transaction. + /// + /// Sets the channel to shutdown if an error occurs. + pub fn send(self,mut result: &mut WithErrorSyntaxErrorAsEnumResult,) -> Result<(), fidl::Error> { + let r = self.send_raw(result,); + if r.is_err() { + self.control_handle.shutdown(); + } + self.drop_without_shutdown(); + r + } + + /// Similar to "send" but does not shutdown the channel if + /// an error occurs. + pub fn send_no_shutdown_on_err(self,mut result: &mut WithErrorSyntaxErrorAsEnumResult,) -> Result<(), fidl::Error> { + let r = self.send_raw(result,); + self.drop_without_shutdown(); + r + } + + fn send_raw(&self,mut result: &mut WithErrorSyntaxErrorAsEnumResult,) -> Result<(), fidl::Error> { + let header = fidl::encoding::TransactionHeader { + tx_id: self.tx_id, + flags: 0, + ordinal: self.ordinal, + }; + + let mut response = (result); + + let mut msg = fidl::encoding::TransactionMessage { + header, + body: &mut response, + }; + + ::fidl::encoding::with_tls_coding_bufs(|bytes, handles| { + ::fidl::encoding::Encoder::encode(bytes, handles, &mut msg)?; + self.control_handle.inner.channel().write(&*bytes, &mut *handles) + .map_err(fidl::Error::ServerResponseWrite)?; + Ok(()) + }) + } +} + + #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct OvernetInternalProtocolMarker; diff --git a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json_test_base.h.golden b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json_test_base.h.golden index ecdef0664c7..e85ad056fb9 100644 --- a/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json_test_base.h.golden +++ b/garnet/go/src/fidl/compiler/backend/goldens/protocols.test.fidl.json_test_base.h.golden @@ -82,6 +82,19 @@ class WithAndWithoutRequestResponse_TestBase : public WithAndWithoutRequestRespo NotImplemented_("WithRequestWithResponse"); } +}; + +class WithErrorSyntax_TestBase : public WithErrorSyntax { + public: + virtual ~WithErrorSyntax_TestBase() { } + virtual void NotImplemented_(const std::string& name) = 0; + void ErrorAsPrimitive(ErrorAsPrimitiveCallback callback) override { + NotImplemented_("ErrorAsPrimitive"); + } + void ErrorAsEnum(ErrorAsEnumCallback callback) override { + NotImplemented_("ErrorAsEnum"); + } + }; } // namespace testing } // namespace name diff --git a/garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl b/garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl index 9fea07204f0..63578a635b6 100644 --- a/garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl +++ b/garnet/go/src/fidl/compiler/backend/typestest/protocols.test.fidl @@ -11,6 +11,16 @@ protocol WithAndWithoutRequestResponse { -> OnWithResponse(string ret); }; +enum ErrorEnun { + ERR_FOO = 1; + ERR_BAR = 2; +}; + +protocol WithErrorSyntax { + ErrorAsPrimitive() -> () error uint32; + ErrorAsEnum() -> () error ErrorEnun; +}; + [Transport="OvernetInternal"] protocol OvernetInternalProtocol { MethodA(int64 a, int64 b); -- GitLab