On Monday, 3 August 2015 at 11:43:15 UTC, Per Nordlöw wrote:
On Monday, 3 August 2015 at 09:21:50 UTC, Atila Neves wrote:
http://code.dlang.org/packages/cerealed
What's new?
* Performance improvements
* New UDAs for networking packets for even less required
boilerplate
The first new thing is self-explanatory. The second one is
explained briefly in this blog post:
https://www.reddit.com/r/programming/comments/3flnlt/cerealed_a_d_library_for_declarative_binary/
(also on HN but you know how that goes)
The summary is you can now write this:
struct UdpPacket {
static struct Header {
ushort srcPort;
ushort dstPort;
ushort length;
ushort checksum;
}
enum headerSize = unalignedSizeof!Header;
alias header this;
Header header;
@LengthInBytes("length - headerSize") ubyte[] data;
}
Code? Who needs code when the compiler can write it for you?
Atila
1. Are there any convenience functions similar to msgpack's
pack() and unpack() providing compactness and elegance as
import msgpack;
auto x = [1,2];
assert(x.pack.unpack!typeof(x) == x);
Yes. `cerealise` and `decerealise`. The former is slightly weird
for performance reasons. It takes a lambda that tells it what to
do with the resulting bytes.
import cerealed;
auto x = MyStruct();
x.cerealise!(bytes => writeln(bytes));
ubyte[] bytes = [...];
auto x = bytes.decerealise!MyStruct;
2. How does the Cereal performance compare to Msgpack after the
recent optimizations?
Close with LDC and DMD, faster with GDC:
http://forum.dlang.org/post/nkcelouzpjsgmqtvn...@forum.dlang.org
I haven't even tried optimising it myself though, I just merged a
contribution from someone else.
Atila