Created
July 14, 2015 04:38
-
-
Save adam4813/e13bc84e87dcc4327c9e to your computer and use it in GitHub Desktop.
Protobuf example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
syntax = "proto2"; | |
package tec.proto; | |
message Entity { | |
required uint64 id = 1; | |
message Component { | |
message ComponentProperty { | |
enum Type { | |
BOOL = 0; | |
STRING = 1; | |
INT = 2; | |
FLOAT = 3; | |
} | |
required Type type = 1; | |
required string name = 2; | |
optional bool bvalue = 3; | |
optional string svalue = 4; | |
optional int64 ivalue = 5; | |
optional float fvalue = 6; | |
} | |
required string type = 1; | |
repeated ComponentProperty properties = 2; | |
} | |
repeated Component components = 2; | |
} | |
message EntityList { | |
repeated Entity entities = 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Renderable::Out(proto::Entity_Component* target) { | |
proto::Entity_Component_ComponentProperty* prop = target->add_properties(); | |
prop->set_type(proto::Entity_Component_ComponentProperty_Type_STRING); | |
prop->set_name("mesh_name"); | |
prop->set_svalue(this->mesh_name); | |
prop = target->add_properties(); | |
prop->set_type(proto::Entity_Component_ComponentProperty_Type_STRING); | |
prop->set_name("shader_name"); | |
prop->set_svalue(this->shader_name); | |
prop = target->add_properties(); | |
prop->set_type(proto::Entity_Component_ComponentProperty_Type_BOOL); | |
prop->set_name("hidden"); | |
prop->set_bvalue(this->hidden); | |
} | |
void Renderable::In(proto::Entity_Component* source) { | |
for (int i = 0; i < source->properties_size(); ++i) { | |
const proto::Entity_Component_ComponentProperty& prop = source->properties(i); | |
if (prop.name() == "mesh_name") { | |
if (prop.type() == proto::Entity_Component_ComponentProperty_Type_STRING) { | |
this->mesh_name = prop.svalue(); | |
} | |
} | |
else if (prop.name() == "shader_name") { | |
if (prop.type() == proto::Entity_Component_ComponentProperty_Type_STRING) { | |
this->shader_name = prop.svalue(); | |
} | |
} | |
else if (prop.name() == "hidden") { | |
if (prop.type() == proto::Entity_Component_ComponentProperty_Type_BOOL) { | |
this->hidden = prop.bvalue(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated components