Exemplo n.º 1
0
        public static string CreateServerInterfaceCode(ParseInterface parse)
        {
            string interfaceClassName = StringTo.ToUpper(parse.InterfaceName) + "Interface";
            string interfaceClassVar  = parse.InterfaceName[0] +
                                        Md5Helper.Md5(interfaceClassName).ToLower().Replace("-", "");

            interfaceClassVar = interfaceClassVar.ToLower();

            string strs = "var (\n\t" + interfaceClassVar + " *" + interfaceClassName + "\n)\n\n";

            strs += "func Fasten" + parse.InterfaceName + "(psrv *rpcs.Server) {\n";
            strs += "\t" + interfaceClassVar + " = &" + interfaceClassName + "{_implsrv:psrv}\n";
            foreach (FunctionAttr funAttr in parse.Functions)
            {
                strs += "\t" + interfaceClassVar + "._implsrv.BindDelegate(" + funAttr.FuncHash + "," +
                        interfaceClassVar + "." + funAttr.FuncName + "Interface," +
                        "\"" + parse.InterfaceName + "Service." + funAttr.FuncName + "\")\n";
            }
            strs += "}\n\n";


            strs += "type " + StringTo.ToUpper(parse.InterfaceName) + "Interface struct {\n";
            strs += "\t_implsrv *rpcs.Server\n";
            strs += "}\n\n";

            foreach (FunctionAttr funAttr in parse.Functions)
            {
                strs += functionAttrCode.CreateServerInterfaceCode(funAttr, parse.InterfaceName);
            }

            return(strs);
        }
Exemplo n.º 2
0
        public static string CreateClientInterfaceCode(ParseInterface parse)
        {
            string interfaceClassName = StringTo.ToUpper(parse.InterfaceName, 0) + "Interface";
            string strs = "type " + interfaceClassName + " struct {\n";

            strs += "}\n\n";
            foreach (FunctionAttr funAttr in parse.Functions)
            {
                strs += functionAttrCode.CreateClientInterfaceCode(funAttr, parse.InterfaceName);
            }

            return(strs);
        }
Exemplo n.º 3
0
        public static string CreateServerServiceCode(ParseInterface parse)
        {
            string serviceName = StringTo.ToUpper(parse.InterfaceName) + "Service";
            string strs        = "type " + serviceName + " struct {\n";

            strs += "\t_implcontext *rpcb.Context\n";
            strs += "}\n\n";

            foreach (FunctionAttr funAttr in parse.Functions)
            {
                strs += functionAttrCode.CreateServerServiceCode(funAttr, parse.InterfaceName);
            }

            return(strs);
        }
Exemplo n.º 4
0
        public static string CreateClientServiceCode(ParseInterface parse)
        {
            string serviceName = StringTo.ToUpper(parse.InterfaceName) + "Service";
            string strs        = "type " + serviceName + " struct {\n";

            strs += "\t" + "_brokerImpl *rpclient.Broker\n";
            strs += "\t" + "_compressType rpcc.MRPC_PACKAGE_COMPRESS\n";
            strs += "}\n\n";
            strs += "func (" + serviceName[0].ToString().ToLower() + " *" + serviceName + ") WithBroker(broker *rpclient.Broker) {\n";
            strs += "\t" + serviceName[0].ToString().ToLower() + "._brokerImpl = broker\n";
            strs += "}\n";

            strs += "func (" + serviceName[0].ToString().ToLower() + " *" + serviceName + ") WithCommpressType(compressType rpcc.MRPC_PACKAGE_COMPRESS) {\n";
            strs += "\t" + serviceName[0].ToString().ToLower() + "._compressType = compressType\n";
            strs += "}\n";


            foreach (FunctionAttr funAttr in parse.Functions)
            {
                strs += functionAttrCode.CreateClientServiceCode(funAttr, parse.InterfaceName);
            }

            return(strs);
        }
Exemplo n.º 5
0
        bool parse(string data)
        {
            data = Regex.Replace(data, @"\/\/[^\n]*", "");
            data = Regex.Replace(data, @"[\n\r\t]", "");
            data = Regex.Replace(data, @"\s{2,}", "");

            string[] classes = Regex.Split(data, @"[@\}]");

            if (classes.Length == 0)
            {
                throw new System.Exception("parse classes is failed, no class struct!!");
            }

            //

            foreach (string c in classes)
            {
                string[] symbolFlag = c.Split('{');
                if (symbolFlag.Length != 2)
                {
                    continue;
                }

                string[] symbolAttr = symbolFlag[0].Split(":");
                if (symbolAttr.Length != 2)
                {
                    throw new Exception("parse symbol  attr is failed,  symbol missing :, " + symbolFlag[0]);
                }

                IBParse idlParse;
                switch (symbolAttr[0])
                {
                case Symbol.Struct:
                    idlParse = new ParseStruct();
                    break;

                case Symbol.Interface:
                    idlParse = new ParseInterface();
                    break;

                case Symbol.Namespace:
                    idlParse = new ParseNamespace();
                    break;

                default:
                    throw new Exception("parse symbol attr is error,  symbol: " + symbolAttr[0]);
                }

                if (idlParse.Parse(m_fileName, symbolAttr[1].Trim(), symbolFlag[1].Trim()))
                {
                    switch (symbolAttr[0])
                    {
                    case Symbol.Struct:
                        Vars.RegisterStruct(idlParse.GetName(), idlParse);
                        break;

                    case Symbol.Interface:
                        Vars.RegisterInterface(idlParse.GetName(), idlParse);
                        break;

                    case Symbol.Namespace:
                        Vars.RegisterNamespace(idlParse);
                        break;
                    }
                }
            }

            //TODDO:解释代码修
            createCode();
            return(true);
        }