Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement socket communication via protocol buffers #49

Open
douglasrizzo opened this issue Nov 14, 2019 · 7 comments
Open

Implement socket communication via protocol buffers #49

douglasrizzo opened this issue Nov 14, 2019 · 7 comments

Comments

@douglasrizzo
Copy link
Contributor

Hello @santiontanon . You have mentioned to me in another medium that, when communicating to and from MicroRTS using sockets, building and passing XML and JSON messages creates a bottleneck in simulation time.

I have seen a tendency in the community to opt for protocol buffers (protobuf) when communication time is a priority over human-readability.

Basically, you create a .proto text file which dictates the message format, compile it using a tool that generates classes in multiple languages, and use these classes to create interchangeable objects, which can be serialized in byte arrays, for example.

I have found this comparison between JSON and Protobuf which indicates that the later is up to 5x times faster.

I was working through the tutorials and ended up creating a .proto file for a MicroRTS game state and was thinking about testing it sometime soon.

If successful, would there be interest to include something like this into MicroRTS?

syntax = "proto3";

option java_package = "ai.socket.protobuf";
option java_outer_classname = "GameStateProtobuf";

message unit {
  string type = 1;
  int32 ID = 2;
  int32 player = 3;
  int32 x = 4;
  int32 y = 5;
  int32 resources = 6;
  int32 hitpoints = 7;
}

message player {
  int32 ID = 1;
  int32 resources = 2;
}

message PGS {
  int32 width = 1;
  int32 height = 2;
  string terrain = 3;
  repeated player players = 4;
  repeated unit units = 5;
}

message action {
  int32 type = 1;
  int32 parameter = 2;
}

message actions {
  int32 ID = 1;
  int32 time = 2;
  action action = 3;
}

message state {
  int32 time = 1;
  PGS pgs = 2;
  repeated actions actions = 3;
}
@santiontanon
Copy link
Contributor

Hi Douglas, yes! I am very familiar with protobuffs, as I use them regularly in my everyday work at Google. That would be great! As I mentioned on the Gradle-related pull request, if we go with this, I'd like to do it in a way that we do not depend on an external package, so I need to think about how to do this. But yes, it's something I'd definitively be interested in!

@douglasrizzo
Copy link
Contributor Author

I haven't used protobufs before but I believe that, once the classes derived from the protos are generated, you actually don't need any dependencies. All the methods necessary to serialize and deserialize objects are contained inside the classes. It would be good to add the protos to the repo, though.

@santiontanon
Copy link
Contributor

Yes, I agree. That would be a good solution. Add the protobuffs to the repo (and maybe a build script for whoever wants to rebuild), but include the result of compiling them in to a Java class!

@douglasrizzo
Copy link
Contributor Author

OK, I'll investigate this further in a fork.

@santiontanon
Copy link
Contributor

Awesome, thanks a lot! (apologies for rejecting your other pull request concerning Gradle, but that was something I really didn't want to do).

@douglasrizzo
Copy link
Contributor Author

That pull request was not mine!

@santiontanon
Copy link
Contributor

oh, true! got confused, since you replied there, my bad! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants