I might have missed something, but I'm trying to deal with protocol buffers in an easy way to provide extensions later. This seems a little obscure, so I'll get right to the problem right away.
I am writing an assembly to support various tasks, one of which includes a description of structured data. Great time to use protocol buffers. The primary class for using protocol buffers is called StateDefinition. Here is the .proto file that I came up with for it:
package Kannon.State;
message StateDefinition {
enum StateTypes {
GRAPHICS = 0;
AUDIO = 1;
MIND = 2;
PHYSICS = 3;
NETWORK = 4;
GENERIC = 5;
}
repeated StateTypes requiredStates = 1;
optional GraphicsStateDef Graphics = 2;
optional AudioStateDef Audio = 3;
(etc)
}
message GraphicsStateDef {
extensions 100 to max;
}
message AudioStateDef {
extensions 100 to max;
}
(etc)
My goal was to allow these _StateDef messages to be expanded later with what fields he would need. However, this extension will happen regardless of the library I'm writing now.
Kagents.dll -> Manages the analysis of StateDefinition, etc.
Something referencing Kagents.dll → Has a protobuff file with a “GraphicsStateDef extension” to determine the required state.
I was hoping that the definition of "extend GraphicsStateDef" would lead to code that would allow me to use properties to access these fields and avoid the cumbersome syntaxes Extendible.AppendValue () and GetValue ().
, , , DLL , :
public static class GraphicsExt
{
enum Fields
{
someValue = 1,
someOtherValue = 2
}
public static Int32 someValue(this State.GraphicsStateDef def)
{
return Extensible.GetValue(def, Fields.someValue);
}
public static void someValue(this State.graphicsStateDef def, Int32 value)
{
Extensible.AppendValue(def, fields.someValue, value);
}
}
- , .
, , , , - , , . =)
EDIT:
, , , .
StateReference GameState. , StateDefinition, . (GraphicsStateDef), .
, StateDefinition "repeat StateTypes requiredStates = 1". .
- , ? , , , .