Skip to content

Commit

Permalink
Merge pull request #88 from msoucy/modern-dmd-dub
Browse files Browse the repository at this point in the history
Update for modern DMDFE and dub features
  • Loading branch information
msoucy authored Jul 18, 2016
2 parents 2be155c + c9076d5 commit 3119577
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 51 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ sudo: false
language: d
d:
- dmd
- dmd-2.067.0
- dmd-2.071.1
- dmd-2.066.1
- gdc
- gdc-4.9.3
- ldc
- ldc-0.15.1
- ldc-1.0.0
- ldc-0.17.1
before_install:
- dub fetch doveralls
script:
Expand Down
File renamed without changes.
19 changes: 10 additions & 9 deletions examples/simple/source/app.d → examples/simple.d
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/*******************************************************************************
* An simple example for dproto
*
* Authors: Bjarne Leif Bruhn
* Date: Nov 24, 2013
* Version: 1.0.0
*/
#!/usr/bin/env dub
/+ dub.sdl:
name "dproto_simple"
description "A simple dproto example"
dependency "dproto" path=".."
author "Bjarne Leif Bruhn"
author "Matt Soucy"
+/

import std.stdio;
import dproto.dproto;
Expand All @@ -29,15 +30,15 @@ mixin ProtocolBufferFromString!"
repeated PhoneNumber phone = 4;
}
";


int main()
{
Person person;
person.name = "John Doe";
person.id = 1234;
person.email = "jdoe@example.com";

ubyte[] serializedObject = person.serialize();

Person person2 = Person(serializedObject);
Expand Down
12 changes: 0 additions & 12 deletions examples/simple/dub.json

This file was deleted.

14 changes: 12 additions & 2 deletions examples/simple_file/source/app.d → examples/simple_file.d
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#!/usr/bin/env dub
/+ dub.sdl:
name "dproto_simple"
description "A simple dproto example with proto file support"
dependency "dproto" path=".."
author "Bjarne Leif Bruhn"
author "Matt Soucy"
stringImportPaths "proto"
+/

/*******************************************************************************
* An simple example for dproto
*
Expand All @@ -10,15 +20,15 @@ import std.stdio;
import dproto.dproto;

mixin ProtocolBuffer!"person.proto";


int main()
{
Person person;
person.name = "John Doe";
person.id = 1234;
person.email = "jdoe@example.com";

ubyte[] serializedObject = person.serialize();

Person person2 = Person(serializedObject);
Expand Down
15 changes: 0 additions & 15 deletions examples/simple_file/dub.json

This file was deleted.

9 changes: 6 additions & 3 deletions import/dproto/attributes.d
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ template ProtoAccessors()
void deserialize(R)(auto ref R __r)
if(isProtoInputRange!R)
{
import dproto.attributes : getAnnotation;
import std.traits;
import dproto.attributes;
import painlesstraits : getAnnotation;

while(!__r.empty()) {
auto __msgdata = __r.readVarint();
bool __matched = false;
Expand Down Expand Up @@ -106,11 +108,12 @@ template ProtoAccessors()

template ProtoFields(alias self)
{
import std.typetuple : Filter, TypeTuple;
import std.typetuple : Filter, TypeTuple, Erase;

alias Field(alias F) = Identity!(__traits(getMember, self, F));
alias HasProtoField(alias F) = hasValueAnnotation!(Field!F, ProtoField);
alias ProtoFields = Filter!(HasProtoField, TypeTuple!(__traits(allMembers, typeof(self))));
alias AllMembers = TypeTuple!(__traits(allMembers, typeof(self)));
alias ProtoFields = Filter!(HasProtoField, Erase!("dproto", AllMembers));
}

template protoDefault(T) {
Expand Down
10 changes: 4 additions & 6 deletions import/dproto/intermediate.d
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,14 @@ struct MessageType {
}
} else {
sink.formattedWrite("static struct %s {\n", name);

// Methods for serialization and deserialization.
sink("static import dproto.attributes;\n");
sink(`mixin dproto.attributes.ProtoAccessors;`);
}
foreach(et; enumTypes) et.toString(sink, fmt);
foreach(mt; messageTypes) mt.toString(sink, fmt);
foreach(field; fields) field.toString(sink, fmt);

// Methods for serialization and deserialization.
if(fmt.spec != 'p') {
sink(`static import dproto.attributes;`);
sink(`mixin dproto.attributes.ProtoAccessors;`);
}
sink("}\n");
}

Expand Down
4 changes: 2 additions & 2 deletions import/dproto/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module dproto.parse;

import dproto.exception;
import dproto.intermediate;
static import dproto.serialize;
import dproto.serialize : isBuiltinType;

import std.algorithm;
import std.array;
Expand Down Expand Up @@ -165,7 +165,7 @@ ProtoPackage ParseProtoSchema(const string name_, string data_) {
return;
} else {
static if( hasMember!(Context, "fields") ) {
if(dproto.serialize.isBuiltinType(label)) {
if(isBuiltinType(label)) {
context.fields ~= readField("optional", label);
return;
}
Expand Down

0 comments on commit 3119577

Please sign in to comment.