项目作者: netpyoung

项目描述 :
:blue_book: Generate interface class from .proto
高级语言: Python
项目地址: git://github.com/netpyoung/nf.protocol-flow.git
创建时间: 2017-03-01T18:38:38Z
项目社区:https://github.com/netpyoung/nf.protocol-flow

开源协议:MIT License

下载


nf.protocol-flow

flow.png
flow.puml

introduce

this is sample protocol flow. When I making a game(in unity), I don’t like to hard-coding for protocol class from message.

Almost mobile projects use web api server. so I choose protobuf as IDL. after that, I need to writing API call method. But It’s boring work that changing code everytime when .proto changed. so I’m writing custom class generator, and protocol exporter for that work.

If you want to use Akka.net, check Akka.Interfaced.

basic Knowledge.

flow

example

  1. $ rake --version
  2. rake, version 10.4.2
  3. $ dotnet --version
  4. 2.1.101
  5. $ protoc --version
  6. libprotoc 3.5.1
  7. # autogen
  8. $ rake
  9. # launch test server
  10. $ rake test_server
  11. # generate protoc-doc
  12. $ rake doc

message

  1. message QHello {
  2. int32 q1 = 1; /// hello description.
  3. int32 q2 = 2;
  4. }
  5. message RHello {
  6. int32 r1 = 1;
  7. int32 r2 = 2;
  8. }

server

  1. @post('/')
  2. def hello():
  3. r = hello_pb2.RHello()
  4. r.r1 = 11
  5. r.r2 = 22
  6. print(r)
  7. return r.SerializeToString()

client

  1. // Hello.autogen.cs
  2. public interface IHello: IMessageSender
  3. {
  4. Task<Result<RHello, int>> Hello(QHello q);
  5. Task<Result<RHello, int>> Hello(System.Int32 Q1, System.Int32 Q2);
  6. }
  1. private async void Start()
  2. {
  3. ProtobufHttpSender sender = new ProtobufHttpSender(new Uri("http://127.0.0.1:8080/"), 3000);
  4. Result<RHello, int> t = await sender.Hello(1, 2);
  5. if (t.IsErr)
  6. {
  7. Debug.LogError(t.Err);
  8. return;
  9. }
  10. Debug.Log(t.Ok);
  11. }

etc