Commit 4d74e349 authored by Kenton Varda's avatar Kenton Varda

Tweak slides.

parent 7c66aa5f
...@@ -336,16 +336,16 @@ Header parsing is zero-copy. ...@@ -336,16 +336,16 @@ Header parsing is zero-copy.
<section markdown="1" data-title="Designated Initializers"> <section markdown="1" data-title="Designated Initializers">
Old and busted: Ugly imperative code:
{% highlight c++ %} {% highlight c++ %}
capnp::MallocMessageBuilder message; capnp::MallocMessageBuilder message;
auto root = message.initRoot<MyStruct>(); auto root = message.initRoot<MyStruct>();
root.setInt32Field(123); root.setFoo(123);
root.setTextField("foo"); root.setBar("foo");
auto inner = root.initStructField(); auto inner = root.initBaz();
inner.setBoolField(true); inner.setQux(true);
capnp::writeMessageToFd(fd, message); capnp::writeMessageToFd(fd, message);
{% endhighlight %} {% endhighlight %}
...@@ -356,17 +356,17 @@ capnp::writeMessageToFd(fd, message); ...@@ -356,17 +356,17 @@ capnp::writeMessageToFd(fd, message);
<section markdown="1" data-title="Designated Initializers"> <section markdown="1" data-title="Designated Initializers">
New hotness: Nice declarative code:
{% highlight c++ %} {% highlight c++ %}
using namespace capnp::init; using namespace capnp::init;
capnp::MallocMessageBuilder message; capnp::MallocMessageBuilder message;
message.initRoot<MyStruct>( message.initRoot<MyStruct>(
$int32Field = 123, $foo = 123,
$textField = "foo", $bar = "foo",
$structField( $baz(
$boolField = true $qux = true
) )
); );
capnp::writeMessageToFd(fd, message); capnp::writeMessageToFd(fd, message);
...@@ -384,10 +384,10 @@ Even better: ...@@ -384,10 +384,10 @@ Even better:
using namespace capnp::init; using namespace capnp::init;
capnp::writeMessageToFd<MyStruct>(fd, capnp::writeMessageToFd<MyStruct>(fd,
$int32Field = 123, $foo = 123,
$textField = "foo", $bar = "foo",
$structField( $baz(
$boolField = true $qux = true
) )
); );
{% endhighlight %} {% endhighlight %}
...@@ -404,7 +404,7 @@ struct { ...@@ -404,7 +404,7 @@ struct {
struct Setter { struct Setter {
T value; T value;
template <typename U> void operator()(U& target) { template <typename U> void operator()(U& target) {
target.setInt32Field(kj::fwd<T>(value)); target.setFoo(kj::fwd<T>(value));
} }
}; };
...@@ -412,7 +412,7 @@ struct { ...@@ -412,7 +412,7 @@ struct {
Setter<T> operator=(T&& value) { Setter<T> operator=(T&& value) {
return { kj::fwd<T>(value) }; return { kj::fwd<T>(value) };
} }
} $int32Field; } $foo;
{% endhighlight %} {% endhighlight %}
</section> </section>
...@@ -421,16 +421,16 @@ struct { ...@@ -421,16 +421,16 @@ struct {
<section markdown="1" data-title="POCS"> <section markdown="1" data-title="POCS">
Kind of painful: Not idiomatic:
{% highlight c++ %} {% highlight c++ %}
capnp::MallocMessageBuilder message; capnp::MallocMessageBuilder message;
MyStruct::Builder root = message.initRoot<MyStruct>(); MyStruct::Builder root = message.initRoot<MyStruct>();
root.setInt32Field(123); root.setFoo(123);
root.setTextField("foo"); root.setBar("foo");
InnerStruct::Builder inner = root.initStructField(); InnerStruct::Builder inner = root.initBaz();
inner.setBoolField(true); inner.setQux(true);
capnp::writeMessageToFd(fd, message); capnp::writeMessageToFd(fd, message);
{% endhighlight %} {% endhighlight %}
...@@ -445,11 +445,11 @@ Plain Old C++ Structs? ...@@ -445,11 +445,11 @@ Plain Old C++ Structs?
{% highlight c++ %} {% highlight c++ %}
MyStruct root; MyStruct root;
root.int32Field = 123; root.foo = 123;
root.textField = "foo"; root.bar = "foo";
InnerStruct inner; InnerStruct inner;
inner.boolField = true; inner.qux = true;
root.structField = kj::mv(inner); root.baz = kj::mv(inner);
capnp::writeMessageToFd(fd, message); capnp::writeMessageToFd(fd, message);
{% endhighlight %} {% endhighlight %}
...@@ -578,87 +578,3 @@ interface AddressBookService { ...@@ -578,87 +578,3 @@ interface AddressBookService {
Questions? Questions?
</section> </section>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment