Skip to content

Commit

Permalink
Merge pull request #57 from cporter/feature/knowable-message-ids
Browse files Browse the repository at this point in the history
Feature request: make the tag ids of message members knowable
  • Loading branch information
msoucy committed Oct 20, 2015
2 parents 99eaf68 + 57c3631 commit 0ce8f89
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions import/dproto/buffers.d
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import dproto.exception;
* defaultValue = The default value for the internal storage
*/
struct OptionalBuffer(ulong id, string TypeString, RealType, bool isDeprecated=false, alias defaultValue=RealType.init) {
public enum TagID = id;
private {
alias ValueType = RealType;
static if(is(ValueType == enum)) {
Expand Down Expand Up @@ -163,6 +164,7 @@ struct OptionalBuffer(ulong id, string TypeString, RealType, bool isDeprecated=f
* isDeprecated = Deprecates the accessors if true
*/
struct RequiredBuffer(ulong id, string TypeString, RealType, bool isDeprecated=false) {
public enum TagID = id;
private {
alias ValueType = RealType;
static if(is(ValueType == enum)) {
Expand Down Expand Up @@ -266,6 +268,7 @@ struct RequiredBuffer(ulong id, string TypeString, RealType, bool isDeprecated=f
* packed = The default value for the internal storage
*/
struct RepeatedBuffer(ulong id, string TypeString, RealType, bool isDeprecated=false, bool packed=false) {
public enum TagID = id;
private {
alias ValueType = RealType;
static if(is(ValueType == enum)) {
Expand Down Expand Up @@ -420,6 +423,15 @@ struct RepeatedBuffer(ulong id, string TypeString, RealType, bool isDeprecated=f
}
}

unittest {
alias optional_string = OptionalBuffer!(1, "string", BuffType!"string", false, (BuffType!"string").init);
assert(optional_string.TagID == 1);
alias required_string = RequiredBuffer!(2, "string", BuffType!"string");
assert(required_string.TagID == 2);
alias repeated_string = RepeatedBuffer!(3, "string", BuffType!"string");
assert(repeated_string.TagID == 3);
}

private struct CntRange
{
@nogc:
Expand Down

0 comments on commit 0ce8f89

Please sign in to comment.