Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411644 Posts in 69395 Topics- by 58450 Members - Latest Member: pp_mech

May 15, 2024, 03:36:37 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)TutorialsGoogle's "Protocol buffers" (Simple game saving, loading, networking)
Pages: [1]
Print
Author Topic: Google's "Protocol buffers" (Simple game saving, loading, networking)  (Read 1440 times)
EddieBytes
Level 1
*


I have ideas, and I'm not afraid to use them


View Profile
« on: March 23, 2012, 09:32:01 AM »

Google protobuf
Noticed some of you hate writing save/load code. I use it for game saving/loading and networking. It's awesome.
A quote from the website:
Quote
Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. Google uses Protocol Buffers for almost all of its internal RPC protocols and file formats.

You write a .proto file like this:
Code:
message Person {
  required int32 id = 1;
  required string name = 2;
  optional string email = 3;
}
Then you compile it with protoc, the protocol buffer compiler, to produce code in C++, Java, or Python.

Then, if you are using C++, you use that code like this:
Code:
Person person;
person.set_id(123);
person.set_name("Bob");
person.set_email("[email protected]");

fstream out("person.pb", ios::out | ios::binary | ios::trunc);
person.SerializeToOstream(&out);
out.close();
Pure awesomeness that right there. Enjoy!

PS: No point in writing a tutorial myself here, a very easy and comprehensive one can be found on the official page I linked at the beginning of this post.
Logged

Check out our thread for Boltus
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic