[docs] Add a note to the StructTraits example about DataView usage.
Before this change it was somewhat easy to gloss over that the StructTraits example requires the DataView version of the mojom type to successfully serialize the types since it doesn't mention that in the preamble to the example. After this change we add a note to explicitly call this out. Bug: N/A Change-Id: I5784d09127968c697e0cbea0281148f4c9977389 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6346439 Commit-Queue: Justin Lulejian <jlulejian@chromium.org> Reviewed-by: Fred Shih <ffred@chromium.org> Cr-Commit-Position: refs/heads/main@{#1431689}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
a654959fb4
commit
7008189bd7
@ -1437,17 +1437,26 @@ methods:
|
||||
|
||||
In order to define the mapping for `gfx::Rect`, we want the following
|
||||
`StructTraits` specialization, which we'll define in
|
||||
`//ui/gfx/geometry/mojo/geometry_mojom_traits.h`:
|
||||
`//ui/gfx/geometry/mojo/geometry_mojom_traits.h`.
|
||||
|
||||
``` cpp
|
||||
*** note
|
||||
**NOTE**: whereas in other usages of the mojom type in C++ we might directly
|
||||
use the mojom type `gfx::mojom::Rect`, our `StructTraits` template must use the
|
||||
[DataView](#using-generated-dataview-types) version (e.g.
|
||||
`gfx::mojom::RectDataView`), which exposes a direct view of the serialized Mojom
|
||||
structure within an incoming message's contents which we need in order to
|
||||
perform the serialization.
|
||||
***
|
||||
|
||||
<pre><code>
|
||||
#include "mojo/public/cpp/bindings/mojom_traits.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "ui/gfx/geometry/mojo/geometry.mojom.h"
|
||||
|
||||
namespace mojo {
|
||||
|
||||
template <>
|
||||
class StructTraits<gfx::mojom::RectDataView, gfx::Rect> {
|
||||
template <>
|
||||
class StructTraits<gfx::mojom::Rect<b>DataView</b>, gfx::Rect> {
|
||||
public:
|
||||
static int32_t x(const gfx::Rect& r) { return r.x(); }
|
||||
static int32_t y(const gfx::Rect& r) { return r.y(); }
|
||||
@ -1458,7 +1467,7 @@ class StructTraits<gfx::mojom::RectDataView, gfx::Rect> {
|
||||
};
|
||||
|
||||
} // namespace mojo
|
||||
```
|
||||
</code></pre>
|
||||
|
||||
And in `//ui/gfx/geometry/mojo/geometry_mojom_traits.cc`:
|
||||
|
||||
|
Reference in New Issue
Block a user