Skip to content

Instantly share code, notes, and snippets.

@0xa
Created March 17, 2013 15:33
Show Gist options
  • Save 0xa/5182051 to your computer and use it in GitHub Desktop.
Save 0xa/5182051 to your computer and use it in GitHub Desktop.
#include <iostream>
#include "net/network.h"
using namespace Ponyca;
class TestType : public Net::AbstractSerializable {
public:
virtual std::string serialize() const {
std::string buffer;
buffer += serializeInt32(fieldInt);
buffer += serializeFloat32(fieldFloat);
return buffer;
}
virtual uint16_t unserialize(std::string const &buffer) {
char const *cstr = buffer.c_str();
uint16_t offset = 0;
offset += unserializeInt32(cstr+offset, fieldInt);
offset += unserializeFloat32(cstr+offset, fieldFloat);
return offset;
}
int32_t fieldInt;
float fieldFloat;
};
int main(int argc, char** argv) {
std::cout << "Hello Equestria!" << std::endl;
TestType t;
t.fieldInt = 42;
t.fieldFloat = 13.37;
std::string serialized(t.serialize());
TestType t2;
t2.unserialize(serialized);
std::cout << t2.fieldInt << "; " << t2.fieldFloat << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment