// build API doc class void BuildAPIDoc(ProtocolXml.MessageBase msg, MsgType msgType, string typeName, Parameter[] parameters) { string Name = msg.Name; OutStream.WriteLine("## {0}{1}", msg.Name, typeName); OutStream.WriteLine("{0}", msg.Desc); OutStream.WriteLine(""); // Build function OutStream.WriteLine(" Result {0}{1}({2})", msg.Name, typeName, ParamInString(parameters)); NewLine(); // Parameter descriptions //OutStream.WriteLine("**Parameter descriptions**"); foreach (var parameter in parameters) { OutStream.WriteLine("\t\t- Out{0}: {1} type. {2}", InParamName(parameter.Name), parameter.TypeName, parameter.Desc); NewLine(); } }
// Build API DOC for command/result message void BuildAPIDoc(ProtocolXml.MessageBase msg, Parameter[] cmdParameters, Parameter[] resultParameters) { string Name = msg.Name; OutStream.WriteLine("## {0} Request", msg.Name); OutStream.WriteLine("{0}", msg.Desc); OutStream.WriteLine(""); // Build function OutStream.WriteLine("1. Command interface"); OutStream.WriteLine(""); OutStream.WriteLine(" Result {0}Cmd({1})", msg.Name, ParamInString(cmdParameters)); NewLine(); // Parameter descriptions foreach (var parameter in cmdParameters) { OutStream.WriteLine("\t\t- Out{0}: {1} type. {2}", parameter.Name, parameter.TypeName, parameter.Desc); NewLine(); } // Build function OutStream.WriteLine("2. Result interface"); NewLine(); OutStream.WriteLine("C++: Cast message to {0}Res to access values", msg.Name); NewLine(); NewLine(); // Parameter descriptions foreach (var parameter in resultParameters) { OutStream.WriteLine("\t\t- Out{0}: {1} type. {2}", parameter.Name, parameter.TypeName, parameter.Desc); } NewLine(); }
// build parser class void BuildParserClass(ProtocolXml.MessageBase msg, MsgType msgType, string typeName, Parameter[] parameters) { string Name = msg.Name; string strClassName = MsgClassName(Name, typeName); OpenSection("class", strClassName + " : public MessageBase"); MatchIndent(-1); OutStream.WriteLine("public:"); MatchIndent(); OutStream.WriteLine("static const MessageID MID;"); // Generate parameter Indicators for Template implementations MatchIndent(); OutStream.WriteLine("// Parameter type informations for template"); var parameterNameMap = new Dictionary <string, Parameter>(); if (parameters != null) { foreach (Parameter param in parameters) { parameterNameMap.Add(param.Name, param); } } OpenSection("enum", "ParameterTypeInfo"); foreach (var parameterName in GenerateParameterTypeInfoList) { MatchIndent(); OutStream.WriteLine("Has{0} = {1},", parameterName.Name, parameterNameMap.ContainsKey(parameterName.Name) ? 1 : 0); } CloseSection(); // Add fake access functions MatchIndent(-1); OutStream.WriteLine("public:"); foreach (var parameter in GenerateParameterTypeInfoList) { if (parameterNameMap.ContainsKey(parameter.Name)) { continue; } MatchIndent(); OutStream.WriteLine("{1} Get{0}() {{ return {1}{{}}; }}", parameter.Name, ToTargetTypeName(parameter)); } bool bHasInternalTypeOverride = HasInternalTypeOverride(parameters); // Generate parameter variables MatchIndent(-1); OutStream.WriteLine("private:"); // member section if (parameters != null) { foreach (Parameter param in parameters) { var typeInfo = SystemTypeInfo.GetParameterInfo(param); if (param.IsArray) { MatchIndent(); if (typeInfo.IsVariableSize) { OutStream.WriteLine("DynamicArray<{0}> m_{1};", ToTargetTypeName(param), param.Name); } else { OutStream.WriteLine("ArrayView<{0}> m_{1};", ToTargetTypeName(param), param.Name); } } else if (!typeInfo.IsString && !typeInfo.IsCSharpStruct && typeInfo.IsVariableSize) { MatchIndent(); OutStream.WriteLine("ArrayView<uint8_t> m_{1}Raw;", ToTargetTypeName(param), param.Name); MatchIndent(); OutStream.WriteLine("mutable bool m_{1}HasParsed = false;", ToTargetTypeName(param), param.Name); MatchIndent(); OutStream.WriteLine("mutable {0} m_{1};", ToTargetTypeName(param), param.Name); } else { MatchIndent(); OutStream.WriteLine("{0} m_{1}{{}};", ToTargetTypeName(param), param.Name); } } } MatchIndent(-1); OutStream.WriteLine("public:"); // Constructors MatchIndent(); OutStream.WriteLine(strClassName + "()"); MatchIndent(1); OutStream.WriteLine("{}"); NewLine(); MatchIndent(); OutStream.WriteLine(strClassName + "( const MessageDataPtr &pMsg )"); MatchIndent(1); OutStream.WriteLine(": MessageBase(pMsg)"); MatchIndent(1); OutStream.WriteLine("{}"); NewLine(); // Usage MatchIndent(1); OutStream.WriteLine("MessageUsage GetMessageUsage() {{ return MessageUsage_{0}; }}", msg.Usage.ToString()); NewLine(); // Generate Get functions if (parameters != null) { foreach (Parameter param in parameters) { var typeInfo = SystemTypeInfo.GetParameterInfo(param); if (param.IsArray) { MatchIndent(); OutStream.WriteLine("const Array<{0}>& Get{1}() const\t{{ return m_{1}; }};", ToTargetTypeName(param), param.Name); } else if (IsStrType(param)) { MatchIndent(); OutStream.WriteLine("{0} Get{1}() const\t{{ return m_{1}; }};", ToTargetTypeName(param), param.Name); } else if (!typeInfo.IsCSharpStruct && typeInfo.IsVariableSize) { MatchIndent(); OutStream.WriteLine("const Array<uint8_t>& Get{1}Raw() const\t{{ return m_{1}Raw; }};", ToTargetTypeName(param), param.Name); //MatchIndent(); OutStream.WriteLine("const {0}& Get{1}() const\t{{ return m_{1}; }};", ToTargetTypeName(param.Type), param.Name); MatchIndent(); OutStream.WriteLine("const {0}& Get{1}() const;", ToTargetTypeName(param), param.Name); } else { MatchIndent(); OutStream.WriteLine("const {0}& Get{1}() const\t{{ return m_{1}; }};", ToTargetTypeName(param), param.Name); } } } NewLine(); // message trace function MatchIndent(); OutStream.WriteLine("static Result TraceOut(const char* prefix, const MessageDataPtr& pMsg);"); NewLine(); // Parse function MatchIndent(); OutStream.WriteLine("virtual Result ParseMessage(const MessageData* pIMsg);"); if (AppConfig.GetValue("VariableMapParser", false)) { MatchIndent(); OutStream.WriteLine("static Result ParseMessageTo(const MessageDataPtr& pIMsg, IVariableMapBuilder& variableBuilder );"); } MatchIndent(); OutStream.WriteLine("static Result ParseMessageToMessageBase(IHeap& memHeap, const MessageDataPtr& pIMsg, MessageBase* &pMsgBase);"); NewLine(); // Build function MatchIndent(); OutStream.WriteLine("static MessageData* Create( {0} );", BuilderParamString(parameters)); if (bHasInternalTypeOverride) { MatchIndent(); OutStream.WriteLine("static MessageData* Create( {0} );", BuilderParamString(parameters, bUseOriginalType: true)); } NewLine(); // Override route context function //if (Group.GenParameterRouteContext) //{ // MatchIndent(); OutStream.WriteLine("Result OverrideRouteContextDestination( EntityUID to );"); // NewLine(); //} // Override route hop function //if (Group.GenParameterRouteHopCount) //{ // MatchIndent(); OutStream.WriteLine("Result OverrideRouteInformation( EntityUID to, unsigned hopCount );"); // NewLine(); //} CloseSection(); }