atilaneves / cerealed

Powerful binary serialisation library for D
BSD 3-Clause "New" or "Revised" License
92 stars 3 forks source link

Added grain case for enums. #2

Closed ColdenCullen closed 10 years ago

atilaneves commented 10 years ago

It'd be nice to have a test case to go along with it. What code doesn't compile as it is now, exactly?

ColdenCullen commented 10 years ago

I'd be happy to write a unittest or two. I'll push them as soon as I can.

The issue I was having was with code like this:

enum Foo { Bar, Baz }

auto decereal = new Decerealizer( /* data */ );
auto foo = decereal.value!Foo;

auto foo = decereal.value!Foo; throws an error, saying grain does not match any function template declaration. Adding my case for enums, the build succeeds.

atilaneves commented 10 years ago

Really? With which compiler? I just wrote this unit test and it passes without your pull request:

import unit_threaded;
import cerealed;

private enum MyEnum { Foo, Bar, Baz };

void testEnum() {
    auto enc = new Cerealiser;
    enc ~= MyEnum.Bar;
    enc ~= MyEnum.Baz;
    enc ~= MyEnum.Foo;
    checkEqual(enc.bytes, [0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 0]);

    auto dec = new Decerealizer(enc.bytes);
    checkEqual(dec.value!MyEnum, MyEnum.Bar);
    checkEqual(dec.value!MyEnum, MyEnum.Baz);
    checkEqual(dec.value!MyEnum, MyEnum.Foo);
}
ColdenCullen commented 10 years ago

I'm on DMD 2.064.2 on OSX.

A simpler solution, if it is just a platform issue, would be to add enum as an acceptable case to an existing implementation of grain.

atilaneves commented 10 years ago

Not a platform issue, just tried your test case and it fails to compile as you said. Merging it in. Thanks!

ColdenCullen commented 10 years ago

Thanks for the help resolving this!

atilaneves commented 10 years ago

Your commit broke things a bit (one test failed and my new test didn't even compile) but I just fixed it. Once again, thanks.