Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions dprotoc/src/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import std.stdio;
import std.string;
import dproto.parse;
import dproto.intermediate;
import std.format;

auto openFileComplex(string fn, string mode)
{
Expand All @@ -22,11 +23,13 @@ void main(string[] args)
{
string infile = "-";
string outfile = "-";
string fmt = "%d";
char syntx = 'd';
int servicetype = 1;
auto helpInformation = getopt(
args,
"out|o", "Output filename (default stdout)", &outfile,
"format|f", "Code generation format", &fmt,
"syntx|s", "code generation syntx. it should be : \n\t\t\td : dlang file; \n\t\t\ts : dlang code string;\n\t\t\tp : protobuf file.",&syntx,
"type|t", "what dlang file or code string will create service to. it should be :\n\t\t\t1 : interface N { R metond(P);}\n\t\t\t2 : interface N { void metond(const P, ref R);}\n\t\t\t3 : class N { R metond(P){R res;return res;}}",&servicetype
);
if (helpInformation.helpWanted)
{
Expand All @@ -45,5 +48,23 @@ void main(string[] args)
}
pack = ParseProtoSchema(infile, inf.byLine.join("\n").idup);
}
openFileComplex(outfile, "w").write(fmt.format(pack));
auto file = openFileComplex(outfile, "w");

ProtoConfig fmt;
fmt.rpc = servicetype;
final switch(syntx){
case 'p':
fmt.type = ProtoConfig.Type.Proto;
break;
case 's' :
fmt.type = ProtoConfig.Type.Dcode;
break;
case 'd' :
fmt.type = ProtoConfig.Type.Dfile;
break;
}

Appender!string buffer;
pack.toString((const(char)[] data){buffer.put(data);},fmt);
file.write(buffer.data);
}
70 changes: 70 additions & 0 deletions examples/proto/person.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package persion;

import std.range;
import dproto.serialize;

static struct Person {
static import dproto.attributes;
mixin dproto.attributes.ProtoAccessors;

enum PhoneType {
WORK = 2,
HOME = 0,
MOBILE = 0,
}

static struct PhoneNumber {
static import dproto.attributes;
mixin dproto.attributes.ProtoAccessors;

@(dproto.attributes.Required())
@(dproto.attributes.ProtoField("string", 1))
BuffType!"string" number= UnspecifiedDefaultValue!(BuffType!"string");


@(dproto.attributes.ProtoField("PhoneType", 2))
dproto.serialize.PossiblyNullable!(PhoneType) type= SpecifiedDefaultValue!(PhoneType, "MOBILE");

}

@(dproto.attributes.Required())
@(dproto.attributes.ProtoField("string", 1))
BuffType!"string" name= UnspecifiedDefaultValue!(BuffType!"string");


@(dproto.attributes.Required())
@(dproto.attributes.ProtoField("int32", 2))
BuffType!"int32" id= UnspecifiedDefaultValue!(BuffType!"int32");


@(dproto.attributes.ProtoField("string", 3))
BuffType!"string" email= UnspecifiedDefaultValue!(BuffType!"string");


@(dproto.attributes.ProtoField("PhoneNumber", 4))
PhoneNumber[] phone;

}

static struct ServiceRequest {
static import dproto.attributes;
mixin dproto.attributes.ProtoAccessors;

@(dproto.attributes.ProtoField("string", 1))
BuffType!"string" request= UnspecifiedDefaultValue!(BuffType!"string");

}

static struct ServiceResponse {
static import dproto.attributes;
mixin dproto.attributes.ProtoAccessors;

@(dproto.attributes.ProtoField("string", 1))
BuffType!"string" response= UnspecifiedDefaultValue!(BuffType!"string");

}

interface TestService {
ServiceResponse TestMethod (ServiceRequest);
}

16 changes: 15 additions & 1 deletion examples/proto/person.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package persion;

message Person {
required string name = 1;
required string name = 1; // namnmknhi
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???

required int32 id = 2;
optional string email = 3;

Expand All @@ -16,3 +18,15 @@ message Person {

repeated PhoneNumber phone = 4;
}


message ServiceRequest {
string request = 1;
}
message ServiceResponse {
string response = 1;
}

service TestService {
rpc TestMethod (ServiceRequest) returns (ServiceResponse);
}
Loading