Formatting cleanup for WireCmd.cpp template.
- Uses do blocks instead of {{}} for Jinja helpers.
- Fixes whitespacing formatting.
Change-Id: I13a9f0fd87f8227e1a9594a40625e2dd88b49e9e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/136623
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Loko Kung <lokokung@google.com>
diff --git a/generator/templates/dawn/wire/WireCmd.cpp b/generator/templates/dawn/wire/WireCmd.cpp
index 26f235a..84b519b 100644
--- a/generator/templates/dawn/wire/WireCmd.cpp
+++ b/generator/templates/dawn/wire/WireCmd.cpp
@@ -32,16 +32,16 @@
//* Helper macros so that the main [de]serialization functions can be written in a generic manner.
//* Outputs an rvalue that's the number of elements a pointer member points to.
-{% macro member_length(member, record_accessor) -%}
+{%- macro member_length(member, record_accessor) -%}
{%- if member.length == "constant" -%}
{{member.constant_length}}u
{%- else -%}
{{record_accessor}}{{as_varName(member.length.name)}}
{%- endif -%}
-{%- endmacro %}
+{%- endmacro -%}
//* Outputs the type that will be used on the wire for the member
-{% macro member_transfer_type(member) -%}
+{%- macro member_transfer_type(member) -%}
{%- if member.type.category == "object" -%}
ObjectId
{%- elif member.type.category == "structure" -%}
@@ -51,18 +51,18 @@
{%- elif as_cType(member.type.name) == "size_t" -%}
{{as_cType(types["uint64_t"].name)}}
{%- else -%}
- {{ assert(member.type.is_wire_transparent) }}
+ {%- do assert(member.type.is_wire_transparent) -%}
{{as_cType(member.type.name)}}
{%- endif -%}
-{%- endmacro %}
+{%- endmacro -%}
//* Outputs the size of one element of the type that will be used on the wire for the member
-{% macro member_transfer_sizeof(member) -%}
+{%- macro member_transfer_sizeof(member) -%}
sizeof({{member_transfer_type(member)}})
-{%- endmacro %}
+{%- endmacro -%}
//* Outputs the serialization code to put `in` in `out`
-{% macro serialize_member(member, in, out) %}
+{%- macro serialize_member(member, in, out) -%}
{%- if member.type.category == "object" -%}
{%- set Optional = "Optional" if member.optional else "" -%}
WIRE_TRY(provider.Get{{Optional}}Id({{in}}, &{{out}}));
@@ -77,47 +77,45 @@
{%- else -%}
{{out}} = {{in}};
{%- endif -%}
-{% endmacro %}
+{%- endmacro -%}
//* Outputs the deserialization code to put `in` in `out`
-{% macro deserialize_member(member, in, out) %}
+{%- macro deserialize_member(member, in, out) -%}
{%- if member.type.category == "object" -%}
{%- set Optional = "Optional" if member.optional else "" -%}
WIRE_TRY(resolver.Get{{Optional}}FromId({{in}}, &{{out}}));
- {%- elif member.type.category == "structure" -%}
- {%- if member.type.is_wire_transparent -%}
+ {%- elif member.type.category == "structure" %}
+ {% if member.type.is_wire_transparent %}
static_assert(sizeof({{out}}) == sizeof({{in}}), "Deserialize memcpy size must match.");
- memcpy(&{{out}}, const_cast<const {{member_transfer_type(member)}}*>(&{{in}}), {{member_transfer_sizeof(member)}});
- {%- else -%}
+ memcpy(&{{out}}, const_cast<const {{member_transfer_type(member)}}*>(&{{in}}), {{member_transfer_sizeof(member)}});
+ {%- else %}
WIRE_TRY({{as_cType(member.type.name)}}Deserialize(&{{out}}, &{{in}}, deserializeBuffer, allocator
{%- if member.type.may_have_dawn_object -%}
, resolver
{%- endif -%}
));
{%- endif -%}
- {%- elif member.type.category == "function pointer" or member.type.name.get() == "void *" -%}
+ {%- elif member.type.category == "function pointer" or member.type.name.get() == "void *" %}
//* Function pointers and explicit "void *" types (i.e. userdata) cannot be deserialized.
{{out}} = nullptr;
{%- elif member.type.name.get() == "size_t" -%}
- // Deserializing into size_t requires check that the uint64_t used on the wire won't narrow.
- if ({{in}} > std::numeric_limits<size_t>::max()) {
- return WireResult::FatalError;
- }
- {{out}} = checked_cast<size_t>({{in}});
+ //* Deserializing into size_t requires check that the uint64_t used on the wire won't narrow.
+ if ({{in}} > std::numeric_limits<size_t>::max()) return WireResult::FatalError;
+ {{out}} = checked_cast<size_t>({{in}});
{%- else -%}
static_assert(sizeof({{out}}) >= sizeof({{in}}), "Deserialize assignment may not narrow.");
- {{out}} = {{in}};
+ {{out}} = {{in}};
{%- endif -%}
-{% endmacro %}
+{%- endmacro -%}
//* The main [de]serialization macro
//* Methods are very similar to structures that have one member corresponding to each arguments.
//* This macro takes advantage of the similarity to output [de]serialization code for a record
//* that is either a structure or a method, with some special cases for each.
-{% macro write_record_serialization_helpers(record, name, members, is_cmd=False, is_return_command=False) %}
- {% set Return = "Return" if is_return_command else "" %}
- {% set Cmd = "Cmd" if is_cmd else "" %}
- {% set Inherits = " : CmdHeader" if is_cmd else "" %}
+{%- macro write_record_serialization_helpers(record, name, members, is_cmd=False, is_return_command=False) -%}
+ {%- set Return = "Return" if is_return_command else "" -%}
+ {%- set Cmd = "Cmd" if is_cmd else "" -%}
+ {%- set Inherits = " : CmdHeader" if is_cmd else "" %}
//* Structure for the wire format of each of the records. Members that are values
//* are embedded directly in the structure. Other members are assumed to be in the
@@ -158,7 +156,7 @@
{% if is_cmd %}
static_assert(offsetof({{Return}}{{name}}Transfer, commandSize) == 0);
static_assert(offsetof({{Return}}{{name}}Transfer, commandId) == sizeof(CmdHeader));
- {% endif %}
+ {% endif -%}
{% if record.chained %}
static_assert(offsetof({{Return}}{{name}}Transfer, chain) == 0);
@@ -167,7 +165,6 @@
//* Returns the required transfer size for `record` in addition to the transfer structure.
DAWN_DECLARE_UNUSED size_t {{Return}}{{name}}GetExtraRequiredSize(const {{Return}}{{name}}{{Cmd}}& record) {
DAWN_UNUSED(record);
-
size_t result = 0;
//* Gather how much space will be needed for the extension chain.
@@ -238,7 +235,6 @@
{%- endif -%}
) {
DAWN_UNUSED(buffer);
-
//* Handle special transfer members of methods.
{% if is_cmd %}
transfer->commandId = {{Return}}WireCmd::{{name}};
@@ -252,7 +248,6 @@
transfer->hasNextInChain = false;
}
{% endif %}
-
{% if record.chained %}
//* Should be set by the root descriptor's call to SerializeChainedStruct.
ASSERT(transfer->chain.sType == {{as_cEnum(types["s type"].name, record.name)}});
@@ -340,7 +335,6 @@
{% if is_cmd %}
ASSERT(transfer->commandId == {{Return}}WireCmd::{{name}});
{% endif %}
-
{% if record.derived_method %}
record->selfId = transfer->self;
{% endif %}
@@ -461,13 +455,12 @@
return WireResult::Success;
}
DAWN_UNUSED_FUNC({{Return}}{{name}}Deserialize);
-{% endmacro %}
+{%- endmacro -%}
-{% macro write_command_serialization_methods(command, is_return) %}
+{%- macro write_command_serialization_methods(command, is_return) -%}
{% set Return = "Return" if is_return else "" %}
{% set Name = Return + command.name.CamelCase() %}
{% set Cmd = Name + "Cmd" %}
-
size_t {{Cmd}}::GetRequiredSize() const {
return WireAlignSizeof<{{Name}}Transfer>() + {{Name}}GetExtraRequiredSize(*this);
}
@@ -476,8 +469,7 @@
WireResult {{Cmd}}::Serialize(
size_t commandSize,
SerializeBuffer* serializeBuffer,
- const ObjectIdProvider& provider
- ) const {
+ const ObjectIdProvider& provider) const {
{{Name}}Transfer* transfer;
WIRE_TRY(serializeBuffer->Next(&transfer));
transfer->commandSize = commandSize;
@@ -491,8 +483,7 @@
WireResult {{Cmd}}::Deserialize(
DeserializeBuffer* deserializeBuffer,
DeserializeAllocator* allocator,
- const ObjectIdResolver& resolver
- ) {
+ const ObjectIdResolver& resolver) {
const volatile {{Name}}Transfer* transfer;
WIRE_TRY(deserializeBuffer->Read(&transfer));
return {{Name}}Deserialize(this, transfer, deserializeBuffer, allocator, resolver);
@@ -511,8 +502,7 @@
WireResult {{Cmd}}::Serialize(
size_t commandSize,
SerializeBuffer* serializeBuffer,
- const ObjectIdProvider&
- ) const {
+ const ObjectIdProvider&) const {
return Serialize(commandSize, serializeBuffer);
}
@@ -524,283 +514,281 @@
WireResult {{Cmd}}::Deserialize(
DeserializeBuffer* deserializeBuffer,
DeserializeAllocator* allocator,
- const ObjectIdResolver&
- ) {
+ const ObjectIdResolver&) {
return Deserialize(deserializeBuffer, allocator);
}
{% endif %}
-{% endmacro %}
+{%- endmacro -%}
-{% macro make_chained_struct_serialization_helpers(out=None) %}
- {% set ChainedStructPtr = "WGPUChainedStructOut*" if out else "const WGPUChainedStruct*" %}
- {% set ChainedStruct = "WGPUChainedStructOut" if out else "WGPUChainedStruct" %}
- //* Generate the list of sTypes that we need to handle.
- {% set sTypes = [] %}
- {% for sType in types["s type"].values %}
- {% if not sType.valid %}
- {% continue %}
- {% elif sType.name.CamelCase() in client_side_structures %}
- {% continue %}
- {% elif types[sType.name.get()].output != out %}
- {% continue %}
- {% endif %}
- {% do sTypes.append(sType) %}
- {% endfor %}
- size_t GetChainedStructExtraRequiredSize({{ChainedStructPtr}} chainedStruct) {
- ASSERT(chainedStruct != nullptr);
- size_t result = 0;
- while (chainedStruct != nullptr) {
- switch (chainedStruct->sType) {
- {% for sType in sTypes %}
- case {{as_cEnum(types["s type"].name, sType.name)}}: {
- const auto& typedStruct = *reinterpret_cast<{{as_cType(sType.name)}} const *>(chainedStruct);
- result += WireAlignSizeof<{{as_cType(sType.name)}}Transfer>();
- result += {{as_cType(sType.name)}}GetExtraRequiredSize(typedStruct);
- chainedStruct = typedStruct.chain.next;
- break;
- }
- {% endfor %}
- // Explicitly list the Invalid enum. MSVC complains about no case labels.
- case WGPUSType_Invalid:
- default:
- // Invalid enum. Reserve space just for the transfer header (sType and hasNext).
- result += WireAlignSizeof<WGPUChainedStructTransfer>();
- chainedStruct = chainedStruct->next;
- break;
- }
- }
- return result;
- }
+{%- macro make_chained_struct_serialization_helpers(out=None) %}
+ {% set ChainedStructPtr = "WGPUChainedStructOut*" if out else "const WGPUChainedStruct*" %}
+ {% set ChainedStruct = "WGPUChainedStructOut" if out else "WGPUChainedStruct" %}
+ //* Generate the list of sTypes that we need to handle.
+ {% set sTypes = [] %}
+ {% for sType in types["s type"].values %}
+ {% if not sType.valid %}
+ {% continue %}
+ {% elif sType.name.CamelCase() in client_side_structures %}
+ {% continue %}
+ {% elif types[sType.name.get()].output != out %}
+ {% continue %}
+ {% endif %}
+ {% do sTypes.append(sType) %}
+ {% endfor %}
- [[nodiscard]] WireResult SerializeChainedStruct({{ChainedStructPtr}} chainedStruct,
- SerializeBuffer* buffer,
- const ObjectIdProvider& provider) {
- ASSERT(chainedStruct != nullptr);
- ASSERT(buffer != nullptr);
- do {
- switch (chainedStruct->sType) {
- {% for sType in sTypes %}
- {% set CType = as_cType(sType.name) %}
- case {{as_cEnum(types["s type"].name, sType.name)}}: {
-
- {{CType}}Transfer* transfer;
- WIRE_TRY(buffer->Next(&transfer));
- transfer->chain.sType = chainedStruct->sType;
- transfer->chain.hasNext = chainedStruct->next != nullptr;
-
- WIRE_TRY({{CType}}Serialize(*reinterpret_cast<{{CType}} const*>(chainedStruct), transfer, buffer
- {%- if types[sType.name.get()].may_have_dawn_object -%}
- , provider
- {%- endif -%}
- ));
-
- chainedStruct = chainedStruct->next;
- } break;
- {% endfor %}
- // Explicitly list the Invalid enum. MSVC complains about no case labels.
- case WGPUSType_Invalid:
- default: {
- // Invalid enum. Serialize just the transfer header with Invalid as the sType.
- // TODO(crbug.com/dawn/369): Unknown sTypes are silently discarded.
- if (chainedStruct->sType != WGPUSType_Invalid) {
- dawn::WarningLog() << "Unknown sType " << chainedStruct->sType << " discarded.";
- }
-
- WGPUChainedStructTransfer* transfer;
- WIRE_TRY(buffer->Next(&transfer));
- transfer->sType = WGPUSType_Invalid;
- transfer->hasNext = chainedStruct->next != nullptr;
-
- // Still move on in case there are valid structs after this.
- chainedStruct = chainedStruct->next;
+ size_t GetChainedStructExtraRequiredSize({{ChainedStructPtr}} chainedStruct) {
+ ASSERT(chainedStruct != nullptr);
+ size_t result = 0;
+ while (chainedStruct != nullptr) {
+ switch (chainedStruct->sType) {
+ {% for sType in sTypes %}
+ case {{as_cEnum(types["s type"].name, sType.name)}}: {
+ const auto& typedStruct = *reinterpret_cast<{{as_cType(sType.name)}} const *>(chainedStruct);
+ result += WireAlignSizeof<{{as_cType(sType.name)}}Transfer>();
+ result += {{as_cType(sType.name)}}GetExtraRequiredSize(typedStruct);
+ chainedStruct = typedStruct.chain.next;
break;
}
- }
- } while (chainedStruct != nullptr);
- return WireResult::Success;
+ {% endfor %}
+ // Explicitly list the Invalid enum. MSVC complains about no case labels.
+ case WGPUSType_Invalid:
+ default:
+ // Invalid enum. Reserve space just for the transfer header (sType and hasNext).
+ result += WireAlignSizeof<WGPUChainedStructTransfer>();
+ chainedStruct = chainedStruct->next;
+ break;
+ }
}
+ return result;
+ }
- WireResult DeserializeChainedStruct({{ChainedStructPtr}}* outChainNext,
- DeserializeBuffer* deserializeBuffer,
- DeserializeAllocator* allocator,
- const ObjectIdResolver& resolver) {
- bool hasNext;
- do {
- const volatile WGPUChainedStructTransfer* header;
- WIRE_TRY(deserializeBuffer->Peek(&header));
- WGPUSType sType = header->sType;
- switch (sType) {
- {% for sType in sTypes %}
- {% set CType = as_cType(sType.name) %}
- case {{as_cEnum(types["s type"].name, sType.name)}}: {
- const volatile {{CType}}Transfer* transfer;
- WIRE_TRY(deserializeBuffer->Read(&transfer));
+ [[nodiscard]] WireResult SerializeChainedStruct({{ChainedStructPtr}} chainedStruct,
+ SerializeBuffer* buffer,
+ const ObjectIdProvider& provider) {
+ ASSERT(chainedStruct != nullptr);
+ ASSERT(buffer != nullptr);
+ do {
+ switch (chainedStruct->sType) {
+ {% for sType in sTypes %}
+ {% set CType = as_cType(sType.name) %}
+ case {{as_cEnum(types["s type"].name, sType.name)}}: {
+ {{CType}}Transfer* transfer;
+ WIRE_TRY(buffer->Next(&transfer));
+ transfer->chain.sType = chainedStruct->sType;
+ transfer->chain.hasNext = chainedStruct->next != nullptr;
- {{CType}}* outStruct;
- WIRE_TRY(GetSpace(allocator, 1u, &outStruct));
- outStruct->chain.sType = sType;
- outStruct->chain.next = nullptr;
+ WIRE_TRY({{CType}}Serialize(*reinterpret_cast<{{CType}} const*>(chainedStruct), transfer, buffer
+ {%- if types[sType.name.get()].may_have_dawn_object -%}
+ , provider
+ {%- endif -%}
+ ));
- *outChainNext = &outStruct->chain;
- outChainNext = &outStruct->chain.next;
+ chainedStruct = chainedStruct->next;
+ } break;
+ {% endfor %}
+ // Explicitly list the Invalid enum. MSVC complains about no case labels.
+ case WGPUSType_Invalid:
+ default: {
+ // Invalid enum. Serialize just the transfer header with Invalid as the sType.
+ // TODO(crbug.com/dawn/369): Unknown sTypes are silently discarded.
+ if (chainedStruct->sType != WGPUSType_Invalid) {
+ dawn::WarningLog() << "Unknown sType " << chainedStruct->sType << " discarded.";
+ }
- WIRE_TRY({{CType}}Deserialize(outStruct, transfer, deserializeBuffer, allocator
- {%- if types[sType.name.get()].may_have_dawn_object -%}
- , resolver
- {%- endif -%}
- ));
+ WGPUChainedStructTransfer* transfer;
+ WIRE_TRY(buffer->Next(&transfer));
+ transfer->sType = WGPUSType_Invalid;
+ transfer->hasNext = chainedStruct->next != nullptr;
- hasNext = transfer->chain.hasNext;
- } break;
- {% endfor %}
- // Explicitly list the Invalid enum. MSVC complains about no case labels.
- case WGPUSType_Invalid:
- default: {
- // Invalid enum. Deserialize just the transfer header with Invalid as the sType.
- // TODO(crbug.com/dawn/369): Unknown sTypes are silently discarded.
- if (sType != WGPUSType_Invalid) {
- dawn::WarningLog() << "Unknown sType " << sType << " discarded.";
- }
+ // Still move on in case there are valid structs after this.
+ chainedStruct = chainedStruct->next;
+ break;
+ }
+ }
+ } while (chainedStruct != nullptr);
+ return WireResult::Success;
+ }
- const volatile WGPUChainedStructTransfer* transfer;
+ WireResult DeserializeChainedStruct({{ChainedStructPtr}}* outChainNext,
+ DeserializeBuffer* deserializeBuffer,
+ DeserializeAllocator* allocator,
+ const ObjectIdResolver& resolver) {
+ bool hasNext;
+ do {
+ const volatile WGPUChainedStructTransfer* header;
+ WIRE_TRY(deserializeBuffer->Peek(&header));
+ WGPUSType sType = header->sType;
+ switch (sType) {
+ {% for sType in sTypes %}
+ {% set CType = as_cType(sType.name) %}
+ case {{as_cEnum(types["s type"].name, sType.name)}}: {
+ const volatile {{CType}}Transfer* transfer;
WIRE_TRY(deserializeBuffer->Read(&transfer));
- {{ChainedStruct}}* outStruct;
+ {{CType}}* outStruct;
WIRE_TRY(GetSpace(allocator, 1u, &outStruct));
- outStruct->sType = WGPUSType_Invalid;
- outStruct->next = nullptr;
+ outStruct->chain.sType = sType;
+ outStruct->chain.next = nullptr;
- // Still move on in case there are valid structs after this.
- *outChainNext = outStruct;
- outChainNext = &outStruct->next;
- hasNext = transfer->hasNext;
- break;
+ *outChainNext = &outStruct->chain;
+ outChainNext = &outStruct->chain.next;
+
+ WIRE_TRY({{CType}}Deserialize(outStruct, transfer, deserializeBuffer, allocator
+ {%- if types[sType.name.get()].may_have_dawn_object -%}
+ , resolver
+ {%- endif -%}
+ ));
+
+ hasNext = transfer->chain.hasNext;
+ } break;
+ {% endfor %}
+ // Explicitly list the Invalid enum. MSVC complains about no case labels.
+ case WGPUSType_Invalid:
+ default: {
+ // Invalid enum. Deserialize just the transfer header with Invalid as the sType.
+ // TODO(crbug.com/dawn/369): Unknown sTypes are silently discarded.
+ if (sType != WGPUSType_Invalid) {
+ dawn::WarningLog() << "Unknown sType " << sType << " discarded.";
}
- }
- } while (hasNext);
- return WireResult::Success;
- }
+ const volatile WGPUChainedStructTransfer* transfer;
+ WIRE_TRY(deserializeBuffer->Read(&transfer));
+
+ {{ChainedStruct}}* outStruct;
+ WIRE_TRY(GetSpace(allocator, 1u, &outStruct));
+ outStruct->sType = WGPUSType_Invalid;
+ outStruct->next = nullptr;
+
+ // Still move on in case there are valid structs after this.
+ *outChainNext = outStruct;
+ outChainNext = &outStruct->next;
+ hasNext = transfer->hasNext;
+ break;
+ }
+ }
+ } while (hasNext);
+ return WireResult::Success;
+ }
{% endmacro %}
+
namespace dawn::wire {
+namespace {
- namespace {
- // Allocates enough space from allocator to countain T[count] and return it in out.
- // Return FatalError if the allocator couldn't allocate the memory.
- // Always writes to |out| on success.
- template <typename T, typename N>
- WireResult GetSpace(DeserializeAllocator* allocator, N count, T** out) {
- // Because we use this function extensively when `count` == 1, we can optimize the
- // size computations a bit more for those cases via constexpr version of the
- // alignment computation.
- constexpr size_t kSizeofT = WireAlignSizeof<T>();
- size_t size = 0;
- if (count == 1) {
- size = kSizeofT;
- } else {
- auto sizeN = WireAlignSizeofN<T>(count);
- // A size of 0 indicates an overflow, so return an error.
- if (!sizeN) {
- return WireResult::FatalError;
- }
- size = *sizeN;
- }
+// Allocates enough space from allocator to countain T[count] and return it in out.
+// Return FatalError if the allocator couldn't allocate the memory.
+// Always writes to |out| on success.
+template <typename T, typename N>
+WireResult GetSpace(DeserializeAllocator* allocator, N count, T** out) {
+ // Because we use this function extensively when `count` == 1, we can optimize the
+ // size computations a bit more for those cases via constexpr version of the
+ // alignment computation.
+ constexpr size_t kSizeofT = WireAlignSizeof<T>();
+ size_t size = 0;
+ if (count == 1) {
+ size = kSizeofT;
+ } else {
+ auto sizeN = WireAlignSizeofN<T>(count);
+ // A size of 0 indicates an overflow, so return an error.
+ if (!sizeN) {
+ return WireResult::FatalError;
+ }
+ size = *sizeN;
+ }
- *out = static_cast<T*>(allocator->GetSpace(size));
- if (*out == nullptr) {
- return WireResult::FatalError;
- }
+ *out = static_cast<T*>(allocator->GetSpace(size));
+ if (*out == nullptr) {
+ return WireResult::FatalError;
+ }
- return WireResult::Success;
- }
+ return WireResult::Success;
+}
- struct WGPUChainedStructTransfer {
- WGPUSType sType;
- bool hasNext;
- };
+struct WGPUChainedStructTransfer {
+ WGPUSType sType;
+ bool hasNext;
+};
- size_t GetChainedStructExtraRequiredSize(const WGPUChainedStruct* chainedStruct);
- [[nodiscard]] WireResult SerializeChainedStruct(const WGPUChainedStruct* chainedStruct,
- SerializeBuffer* buffer,
- const ObjectIdProvider& provider);
- WireResult DeserializeChainedStruct(const WGPUChainedStruct** outChainNext,
- DeserializeBuffer* deserializeBuffer,
- DeserializeAllocator* allocator,
- const ObjectIdResolver& resolver);
+size_t GetChainedStructExtraRequiredSize(const WGPUChainedStruct* chainedStruct);
+[[nodiscard]] WireResult SerializeChainedStruct(const WGPUChainedStruct* chainedStruct,
+ SerializeBuffer* buffer,
+ const ObjectIdProvider& provider);
+WireResult DeserializeChainedStruct(const WGPUChainedStruct** outChainNext,
+ DeserializeBuffer* deserializeBuffer,
+ DeserializeAllocator* allocator,
+ const ObjectIdResolver& resolver);
- size_t GetChainedStructExtraRequiredSize(WGPUChainedStructOut* chainedStruct);
- [[nodiscard]] WireResult SerializeChainedStruct(WGPUChainedStructOut* chainedStruct,
- SerializeBuffer* buffer,
- const ObjectIdProvider& provider);
- WireResult DeserializeChainedStruct(WGPUChainedStructOut** outChainNext,
- DeserializeBuffer* deserializeBuffer,
- DeserializeAllocator* allocator,
- const ObjectIdResolver& resolver);
+size_t GetChainedStructExtraRequiredSize(WGPUChainedStructOut* chainedStruct);
+[[nodiscard]] WireResult SerializeChainedStruct(WGPUChainedStructOut* chainedStruct,
+ SerializeBuffer* buffer,
+ const ObjectIdProvider& provider);
+WireResult DeserializeChainedStruct(WGPUChainedStructOut** outChainNext,
+ DeserializeBuffer* deserializeBuffer,
+ DeserializeAllocator* allocator,
+ const ObjectIdResolver& resolver);
- //* Output structure [de]serialization first because it is used by commands.
- {% for type in by_category["structure"] %}
- {% set name = as_cType(type.name) %}
- {% if type.name.CamelCase() not in client_side_structures %}
- {{write_record_serialization_helpers(type, name, type.members, is_cmd=False)}}
- {% endif %}
- {% endfor %}
+//* Output structure [de]serialization first because it is used by commands.
+{% for type in by_category["structure"] %}
+ {%- set name = as_cType(type.name) -%}
+ {% if type.name.CamelCase() not in client_side_structures -%}
+ {{write_record_serialization_helpers(type, name, type.members, is_cmd=False)}}
+ {% endif %}
+{% endfor %}
+{{make_chained_struct_serialization_helpers(out=False)}}
+{{make_chained_struct_serialization_helpers(out=True)}}
- {{ make_chained_struct_serialization_helpers(out=False) }}
- {{ make_chained_struct_serialization_helpers(out=True) }}
+//* Output [de]serialization helpers for commands
+{% for command in cmd_records["command"] %}
+ {%- set name = command.name.CamelCase() -%}
+ {{write_record_serialization_helpers(command, name, command.members, is_cmd=True)}}
+{% endfor %}
- //* Output [de]serialization helpers for commands
- {% for command in cmd_records["command"] %}
- {% set name = command.name.CamelCase() %}
- {{write_record_serialization_helpers(command, name, command.members, is_cmd=True)}}
- {% endfor %}
+//* Output [de]serialization helpers for return commands
+{% for command in cmd_records["return command"] %}
+ {%- set name = command.name.CamelCase() -%}
+ {{write_record_serialization_helpers(command, name, command.members,
+ is_cmd=True, is_return_command=True)}}
+{% endfor %}
- //* Output [de]serialization helpers for return commands
- {% for command in cmd_records["return command"] %}
- {% set name = command.name.CamelCase() %}
- {{write_record_serialization_helpers(command, name, command.members,
- is_cmd=True, is_return_command=True)}}
- {% endfor %}
-
- // Implementation of ObjectIdResolver that always errors.
- // Used when the generator adds a provider argument because of a chained
- // struct, but in practice, a chained struct in that location is invalid.
- class ErrorObjectIdResolver final : public ObjectIdResolver {
- public:
- {% for type in by_category["object"] %}
- WireResult GetFromId(ObjectId id, {{as_cType(type.name)}}* out) const override {
- return WireResult::FatalError;
- }
- WireResult GetOptionalFromId(ObjectId id, {{as_cType(type.name)}}* out) const override {
- return WireResult::FatalError;
- }
- {% endfor %}
- };
-
- // Implementation of ObjectIdProvider that always errors.
- // Used when the generator adds a provider argument because of a chained
- // struct, but in practice, a chained struct in that location is invalid.
- class ErrorObjectIdProvider final : public ObjectIdProvider {
- public:
- {% for type in by_category["object"] %}
- WireResult GetId({{as_cType(type.name)}} object, ObjectId* out) const override {
- return WireResult::FatalError;
- }
- WireResult GetOptionalId({{as_cType(type.name)}} object, ObjectId* out) const override {
- return WireResult::FatalError;
- }
- {% endfor %}
- };
-
- } // anonymous namespace
-
- {% for command in cmd_records["command"] %}
- {{ write_command_serialization_methods(command, False) }}
+// Implementation of ObjectIdResolver that always errors.
+// Used when the generator adds a provider argument because of a chained
+// struct, but in practice, a chained struct in that location is invalid.
+class ErrorObjectIdResolver final : public ObjectIdResolver {
+ public:
+ {% for type in by_category["object"] %}
+ WireResult GetFromId(ObjectId id, {{as_cType(type.name)}}* out) const override {
+ return WireResult::FatalError;
+ }
+ WireResult GetOptionalFromId(ObjectId id, {{as_cType(type.name)}}* out) const override {
+ return WireResult::FatalError;
+ }
{% endfor %}
+};
- {% for command in cmd_records["return command"] %}
- {{ write_command_serialization_methods(command, True) }}
+// Implementation of ObjectIdProvider that always errors.
+// Used when the generator adds a provider argument because of a chained
+// struct, but in practice, a chained struct in that location is invalid.
+class ErrorObjectIdProvider final : public ObjectIdProvider {
+ public:
+ {% for type in by_category["object"] %}
+ WireResult GetId({{as_cType(type.name)}} object, ObjectId* out) const override {
+ return WireResult::FatalError;
+ }
+ WireResult GetOptionalId({{as_cType(type.name)}} object, ObjectId* out) const override {
+ return WireResult::FatalError;
+ }
{% endfor %}
+};
+
+} // anonymous namespace
+
+{% for command in cmd_records["command"] -%}
+ {{write_command_serialization_methods(command, False)}}
+{% endfor %}
+
+{% for command in cmd_records["return command"] -%}
+ {{write_command_serialization_methods(command, True)}}
+{% endfor %}
} // namespace dawn::wire