| {{/* | |
| // Copyright 2021 The Fuchsia Authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| */}} | |
| {{- define "Method:Response:WireMessagingHeader" }} | |
| {{- EnsureNamespace "" }} | |
| {{- if .HasResponsePayload }} | |
| template<> | |
| struct {{ .WireResponse }} final {{- if .HasResponsePayload }} : public {{ .ResponsePayload }}{{ end }} { | |
| {{- range .ResponseAnonymousChildren }} | |
| using {{ .ScopedName }} = {{ .FlattenedName }}; | |
| {{- end }} | |
| {{ if (and .ResponseFlattened .HasResponsePayload) }} | |
| explicit {{ .WireResponse.Self }}({{ .ResponsePayload }} base); | |
| {{- end }} | |
| {{- if .ResponseArgs }} | |
| explicit {{ .WireResponse.Self }}({{ RenderParams .ResponseArgs }}); | |
| {{- end }} | |
| {{ .WireResponse.Self }}() = default; | |
| }; | |
| {{- end }} | |
| {{ if .HasResponsePayload }} | |
| template <bool IsRecursive> | |
| struct ::fidl::internal::WireCodingTraits<{{ .WireResponse }}, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive> | |
| : public WireStructCodingTraitsBase<{{ .WireResponse }}, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive> { | |
| static constexpr size_t kInlineSize = {{ .Response.TypeShapeV2.InlineSize }}; | |
| static void Encode( | |
| internal::WireEncoder* encoder, {{ .WireResponse }}* value, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth); | |
| static void Decode( | |
| internal::WireDecoder* decoder, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth); | |
| }; | |
| {{- end }} | |
| template<> | |
| struct {{ .WireTransactionalResponse }} final { | |
| FIDL_ALIGNDECL | |
| fidl_message_header_t header; | |
| {{ if .ResponseArgs }} | |
| {{ .WireResponse }} body; | |
| explicit {{ .WireTransactionalResponse.Self }}({{ RenderParams .ResponseArgs }}); | |
| {{- end }} | |
| {{ .WireTransactionalResponse.Self }}(); | |
| {{- if .Response.IsResource }} | |
| void _CloseHandles(); | |
| {{- end }} | |
| }; | |
| template <bool IsRecursive> | |
| struct ::fidl::internal::WireCodingTraits<{{ .WireTransactionalResponse }}, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive> | |
| : public WireStructCodingTraitsBase<{{ .WireTransactionalResponse }}, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive> { | |
| static constexpr size_t kInlineSize = {{ .Response.TypeShapeV2.InlineSize }} + sizeof(fidl_message_header_t); | |
| static void Encode(internal::WireEncoder* encoder, {{ .WireTransactionalResponse }}* value, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth); | |
| static void Decode(internal::WireDecoder* decoder, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth); | |
| }; | |
| {{- end }} | |
| {{- define "Method:Response:WireMessagingSource" }} | |
| {{- EnsureNamespace "" }} | |
| {{ if (and .ResponseFlattened .HasResponsePayload) }} | |
| {{ .WireResponse }}::{{ .WireResponse.Self }}({{ .ResponsePayload }} base) : {{ .ResponsePayload }}(std::move(base)) {} | |
| {{- end }} | |
| {{- if .ResponseArgs }} | |
| {{ .WireResponse }}::{{ .WireResponse.Self }}({{ RenderParams .ResponseArgs }}) : {{ .ResponsePayload }} | |
| {{- if .ResponseFlattened -}} | |
| {{- "{ " }}{{ RenderForwardStructParams .ResponseArgs }}} | |
| {{- else -}} | |
| ({{ RenderForwardParams .ResponseArgs }}) | |
| {{- end -}} | |
| {} | |
| {{- end }} | |
| {{ if .ResponseArgs }} | |
| {{ .WireTransactionalResponse }}::{{ .WireTransactionalResponse.Self }}({{ RenderParams .ResponseArgs }}) | |
| : body({{ .WireResponse }}({{ RenderForwardParams .ResponseArgs }})) { | |
| ::fidl::InitTxnHeader(&header, 0, {{ .OrdinalName }}, {{ .DynamicFlagsName }}); | |
| } | |
| {{- end }} | |
| {{ .WireTransactionalResponse }}::{{ .WireTransactionalResponse.Self }}() { | |
| ::fidl::InitTxnHeader(&header, 0, {{ .OrdinalName }}, {{ .DynamicFlagsName }}); | |
| } | |
| {{- if .Response.IsResource }} | |
| void {{ .WireTransactionalResponse }}::_CloseHandles() { | |
| {{- if .ResponseArgs }} | |
| body._CloseHandles(); | |
| {{- end }} | |
| } | |
| {{- end }} | |
| {{ if .HasResponsePayload }} | |
| template <bool IsRecursive> | |
| void ::fidl::internal::WireCodingTraits<{{ .WireResponse }}, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive>::Encode( | |
| internal::WireEncoder* encoder, {{ .WireResponse }}* value, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth) { | |
| fidl::internal::WireCodingTraits<{{ .ResponsePayload }}, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive>::Encode( | |
| encoder, value, position, recursion_depth); | |
| } | |
| template <bool IsRecursive> | |
| void ::fidl::internal::WireCodingTraits<{{ .WireResponse }}, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive>::Decode( | |
| internal::WireDecoder* decoder, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth) { | |
| fidl::internal::WireCodingTraits<{{ .ResponsePayload }}, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive>::Decode( | |
| decoder, position, recursion_depth); | |
| } | |
| template | |
| struct ::fidl::internal::WireCodingTraits<{{ .WireResponse }}, ::fidl::internal::WireCodingConstraintEmpty, true>; | |
| template | |
| struct ::fidl::internal::WireCodingTraits<{{ .WireResponse }}, ::fidl::internal::WireCodingConstraintEmpty, false>; | |
| {{- end }} | |
| template <bool IsRecursive> | |
| void ::fidl::internal::WireCodingTraits<{{ .WireTransactionalResponse }}, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive>::Encode(internal::WireEncoder* encoder, | |
| {{ .WireTransactionalResponse }}* value, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth) { | |
| *position.As<fidl_message_header_t>() = value->header; | |
| {{- if .HasResponsePayload }} | |
| WireCodingTraits<{{ .WireResponse }}, WireCodingConstraintEmpty, IsRecursive>::Encode( | |
| encoder, &value->body, position + sizeof(fidl_message_header_t), recursion_depth); | |
| {{- end }} | |
| } | |
| template <bool IsRecursive> | |
| void ::fidl::internal::WireCodingTraits<{{ .WireTransactionalResponse }}, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive>::Decode( | |
| internal::WireDecoder* decoder, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth) { | |
| {{- if .HasResponsePayload }} | |
| WireCodingTraits<{{ .WireResponse }}, WireCodingConstraintEmpty, IsRecursive>::Decode( | |
| decoder, position + sizeof(fidl_message_header_t), recursion_depth); | |
| {{- end }} | |
| } | |
| template | |
| struct ::fidl::internal::WireCodingTraits<{{ .WireTransactionalResponse }}, ::fidl::internal::WireCodingConstraintEmpty, true>; | |
| template | |
| struct ::fidl::internal::WireCodingTraits<{{ .WireTransactionalResponse }}, ::fidl::internal::WireCodingConstraintEmpty, false>; | |
| {{- end }} | |
| {{- define "Method:Response:NaturalMessagingHeader" }} | |
| {{- EnsureNamespace "" }} | |
| template <> | |
| class {{ .NaturalResponse }} final | |
| {{- if .ResponseMessageBase }} : public {{ .ResponseMessageBase }} {{ end }} { | |
| public: | |
| {{- if .HasResponsePayload }} | |
| {{- if .Result }} | |
| {{- if .Result.HasError }} | |
| using {{ .ResponseMessageBase }}::result; | |
| {{ .NaturalResponse.Self }}({{ .ResponseMessageBase }} v); | |
| {{ .NaturalResponse.Self }}() = delete; | |
| {{- else if .Result.ValueParameters }} | |
| using {{ .Result.ValueTypeDecl }}::{{ .Result.ValueTypeDecl.Self }}; | |
| {{ .NaturalResponse.Self }}({{ .ResponseMessageBase }} v); | |
| {{- end }} | |
| {{- else }} | |
| using {{ .ResponsePayload }}::{{ .ResponsePayload.Self }}; | |
| {{ .NaturalResponse.Self }}({{ .ResponseMessageBase }} v); | |
| {{- end }} | |
| {{- end }} | |
| }; | |
| {{- if .Result }} | |
| template <> | |
| class {{ .NaturalResponseConverter }} { | |
| using DomainObject = {{ .ResponsePayload }}; | |
| public: | |
| static DomainObject IntoDomainObject({{ .NaturalResponseArg "m" }}); | |
| }; | |
| {{- end }} | |
| {{- end }} | |
| {{- define "Method:Response:NaturalMessagingSource" }} | |
| {{- EnsureNamespace "" }} | |
| {{- if .HasResponsePayload }} | |
| {{- if .Result }} | |
| {{- if .Result.HasError }} | |
| {{ .NaturalResponse}}::{{ .NaturalResponse.Self }}({{ .ResponseMessageBase }} v) : result(std::move(v)) {} | |
| {{- else if .Result.ValueParameters }} | |
| {{ .NaturalResponse}}::{{ .NaturalResponse.Self }}({{ .ResponseMessageBase }} v) : {{ .Result.ValueTypeDecl.Self }}(std::move(v)) {} | |
| {{- end }} | |
| {{- else }} | |
| {{ .NaturalResponse}}::{{ .NaturalResponse.Self }}({{ .ResponseMessageBase }} v) : {{ .ResponsePayload.Self }}(std::move(v)) {} | |
| {{- end }} | |
| {{- end }} | |
| {{- if .Result }} | |
| {{ .ResponsePayload }} {{ .NaturalResponseConverter.NoLeading }}::IntoDomainObject({{ .NaturalResponseArg "m" }}) { | |
| {{ if .Result.HasError -}} | |
| if (m.is_error()) { | |
| return DomainObject::WithErr(m.error_value()); | |
| } else { | |
| {{- if .Result.ValueParameters }} | |
| return DomainObject::WithResponse(std::move(m.value())); | |
| {{- else }} | |
| return DomainObject::WithResponse({}); | |
| {{- end }} | |
| } | |
| {{- else -}} | |
| {{- if .Result.ValueParameters }} | |
| return DomainObject::WithResponse(std::move(m)); | |
| {{- else }} | |
| return DomainObject::WithResponse({}); | |
| {{- end }} | |
| {{- end }} | |
| } | |
| {{- end }} | |
| {{- end }} | |
| {{- define "Method:Response:Traits:TypeConversionsHeader" }} | |
| {{- if .HasResponsePayload }} | |
| {{- if not .HasFrameworkError }} | |
| template <> | |
| struct WireNaturalConversionTraits<{{ .WireResponse }}, {{ .NaturalResponse }}> { | |
| static {{ .NaturalResponse }} ToNatural({{ .WireResponse }} src); | |
| static {{ .WireResponse }} ToWire(fidl::AnyArena& arena, {{ .NaturalResponse }} src); | |
| }; | |
| template <> | |
| struct NaturalTypeForWireType<{{ .WireResponse }}> { | |
| using type = {{ .NaturalResponse }}; | |
| }; | |
| template <> | |
| struct WireTypeForNaturalType<{{ .NaturalResponse }}> { | |
| using type = {{ .WireResponse }}; | |
| }; | |
| {{- end }} | |
| {{- end }} | |
| {{- end }} | |
| {{- define "Method:Response:Traits:TypeConversionsSource" }} | |
| {{- if .HasResponsePayload }} | |
| {{- if not .HasFrameworkError }} | |
| {{ .NaturalResponse }} WireNaturalConversionTraits<{{ .WireResponse }}, {{ .NaturalResponse }}>::ToNatural({{ .WireResponse }} src) { | |
| {{- if and .HasResponsePayload .ResponseMessageBase }} | |
| return {{ .NaturalResponse }}( | |
| WireNaturalConversionTraits<{{ .ResponsePayload.Wire }}, {{ .ResponseMessageBase }}>::ToNatural(std::move(src))); | |
| {{- else }} | |
| return {{ .NaturalResponse }}(); | |
| {{- end }} | |
| } | |
| {{ .WireResponse }} WireNaturalConversionTraits<{{ .WireResponse }}, {{ .NaturalResponse }}>::ToWire(fidl::AnyArena& arena, {{ .NaturalResponse }} src) { | |
| {{- if and .HasResponsePayload .ResponseMessageBase }} | |
| return {{ .WireResponse }}( | |
| WireNaturalConversionTraits<{{ .ResponsePayload.Wire }}, {{ .ResponseMessageBase }}>::ToWire(arena, std::move(src))); | |
| {{- else }} | |
| return {{ .WireResponse }}(); | |
| {{- end }} | |
| } | |
| {{- end }} | |
| {{- end }} | |
| {{- end }} |