Пример #1
0
        //成员序列化
        public static string GetClassSerializeFromNodeType(CClassNode v)
        {
            var sb = new StringBuilder();

            switch (v.Ctype)
            {
            case "list":
                switch (v.Ctype1)
                {
                case "bool":
                case "byte":
                case "short":
                case "int":
                case "uint":
                case "long":
                case "float":
                case "string":
                case "DateTime":
                case "TimeSpan":
                    sb.Append($"nbs.Write(k);");
                    break;

                default:
                    sb.Append($"k.Serialize(nbs);");
                    break;
                }
                break;

            case "dict":
                sb.Append($"nbs.Write(kvp.Key);");
                switch (v.Ctype2)
                {
                case "bool":
                case "byte":
                case "short":
                case "int":
                case "uint":
                case "long":
                case "float":
                case "string":
                case "DateTime":
                case "TimeSpan":
                    sb.Append($"nbs.Write(kvp.Value);");
                    break;

                default:
                    sb.Append($"kvp.Value.Serialize(nbs);");
                    break;
                }
                break;

            default:
                break;
            }
            return(sb.ToString());
        }
Пример #2
0
        //成员反序列化
        public static string GetClassUnserializeFromNodeTypeListLua(CClassNode v)
        {
            var    sb      = new StringBuilder();
            string varname = GetVariablesId();

            switch (v.Ctype1)
            {
            case "bool":
                sb.AppendLine($"local {varname} = nbs:ReadBool()");
                break;

            case "byte":
                sb.AppendLine($"local {varname} = nbs:ReadByte()");
                break;

            case "short":
                sb.AppendLine($"local {varname} = nbs:ReadShort()");
                break;

            case "int":
                sb.AppendLine($"local {varname} = nbs:ReadInt()");
                break;

            case "uint":
                sb.AppendLine($"local {varname} = nbs:ReadUint()");
                break;

            case "long":
                sb.AppendLine($"local {varname} = nbs:ReadLong()");
                break;

            case "float":
                sb.AppendLine($"local {varname} = nbs:ReadFloat()");
                break;

            case "string":
                sb.AppendLine($"local {varname} = nbs:ReadString()");
                break;

            case "DateTime":
                sb.AppendLine($"local {varname} = nbs:ReadDateTime()");
                break;

            case "TimeSpan":
                sb.AppendLine($"local {varname} = nbs:ReadTimeSpan()");
                break;

            default:
                sb.AppendLine($"local {varname} = Lua{v.Ctype1}.new()");
                sb.AppendLine($"        {varname}:Unserialize(nbs)");
                break;
            }
            sb.Append($"        self.{v.Body}:Add({varname})");
            return(sb.ToString());
        }
Пример #3
0
        //成员和初始化
        public static string GetClassBodyFromNode(CClassNode v)
        {
            var sb = new StringBuilder();

            //if (v.Desc != "")
            //{
            //    sb.Append($"        [Desc(\"{v.Desc}\")]\r\n");
            //}
            switch (v.Ctype)
            {
            case "bool":
                sb.Append($"        public {v.Ctype} {v.Body} = false;");
                break;

            case "byte":
            case "short":
            case "int":
            case "uint":
            case "long":
                sb.Append($"        public {v.Ctype} {v.Body} = 0;");
                break;

            case "float":
                sb.Append($"        public {v.Ctype} {v.Body} = 0.0f;");
                break;

            case "string":
                sb.Append($"        public {v.Ctype} {v.Body} = \"\";");
                break;

            case "dt":
            case "datetime":
            case "DateTime":
                sb.Append($"        public {v.Ctype} {v.Body} = {v.Ctype}.Now;");
                break;

            case "list":
                sb.Append($"        public List<{v.Ctype1}> {v.Body} = new List<{v.Ctype1}>();");
                break;

            case "dict":
                sb.Append($"        public Dictionary<{v.Ctype1}, {v.Ctype2}> {v.Body} = new Dictionary<{v.Ctype1}, {v.Ctype2}>();");
                break;

            default:
                sb.Append($"        public {v.Ctype} {v.Body} = new {v.Ctype}();");
                break;
            }
            //if (v.Desc != "")
            //{
            //    sb.Append($"    // {v.Desc}");
            //}
            return(sb.ToString());
        }
Пример #4
0
        //成员序列化
        public static string GetClassSerializeFromNodeTypeListLua(CClassNode v)
        {
            var sb = new StringBuilder();

            switch (v.Ctype1)
            {
            case "bool":
                sb.Append($"nbs:WriteBool(self.{v.Body}[i])");
                break;

            case "byte":
                sb.Append($"nbs:WriteByte(self.{v.Body}[i])");
                break;

            case "short":
                sb.Append($"nbs:WriteShort(self.{v.Body}[i])");
                break;

            case "int":
                sb.Append($"nbs:WriteInt(self.{v.Body}[i])");
                break;

            case "uint":
                sb.Append($"nbs:WriteUInt(self.{v.Body}[i])");
                break;

            case "long":
                sb.Append($"nbs:WriteLong(self.{v.Body}[i])");
                break;

            case "float":
                sb.Append($"nbs:WriteFloat(self.{v.Body}[i])");
                break;

            case "string":
                sb.Append($"nbs:WriteString(self.{v.Body}[i])");
                break;

            case "DateTime":
                sb.Append($"nbs:WriteDateTime(self.{v.Body}[i])");
                break;

            case "TimeSpan":
                sb.Append($"nbs.WriteTimeSpan(self.{v.Body}[i])");
                break;

            default:
                sb.Append($"(self.{v.Body}[i]):Serialize(nbs)");
                break;
            }
            return(sb.ToString());
        }
Пример #5
0
        //成员反序列化
        public static string GetClassUnserializeFromNode(CClassNode v, string space)
        {
            var    sb      = new StringBuilder();
            string varname = GetVariablesId();

            switch (v.Ctype)
            {
            case "bool":
            case "byte":
            case "short":
            case "int":
            case "uint":
            case "long":
            case "float":
            case "string":
            case "DateTime":
            case "TimeSpan":
                sb.Append($"{space}nbs.Read(out {v.Body});\r\n");
                break;

            case "list":
                sb.Append($"{space}nbs.Read(out int {varname});\r\n");
                sb.Append($"{space}for (int k = 0; k < {varname}; k++)\r\n");
                sb.Append($"{space}{{\r\n");
                sb.Append($"    {space}{GetClassUnserializeFromNodeType(v)}\r\n");
                sb.Append($"{space}}}\r\n");
                break;

            case "dict":
                sb.Append($"{space}nbs.Read(out int {varname});\r\n");
                sb.Append($"{space}for (int k = 0; k < {varname}; k++)\r\n");
                sb.Append($"{space}{{\r\n");
                sb.Append($"    {space}{GetClassUnserializeFromNodeType(v)}\r\n");
                sb.Append($"{space}}}\r\n");
                break;

            default:
                if (v.Ctype.Length > 0 && v.Ctype[0] == 'E')
                {
                    sb.Append($"{space}if (true) {{ nbs.Read(out short etemp); {v.Body} = ({v.Ctype})etemp; }}\r\n");
                }
                else
                {
                    sb.Append($"{space}{v.Body}.Unserialize(nbs);\r\n");
                }
                break;
            }
            return(sb.ToString());
        }
Пример #6
0
        //成员序列化
        public static string GetClassSerializeFromNode(CClassNode v, string space)
        {
            var sb = new StringBuilder();

            switch (v.Ctype)
            {
            case "bool":
            case "byte":
            case "short":
            case "int":
            case "uint":
            case "long":
            case "float":
            case "string":
            case "DateTime":
            case "TimeSpan":
                sb.Append($"{space}nbs.Write({v.Body});\r\n");
                break;

            case "list":
                sb.Append($"{space}nbs.Write({v.Body}.Count);\r\n");
                sb.Append($"{space}foreach (var k in {v.Body})\r\n");
                sb.Append($"{space}{{\r\n");
                sb.Append($"    {space}{GetClassSerializeFromNodeType(v)}\r\n");
                sb.Append($"{space}}}\r\n");
                break;

            case "dict":
                sb.Append($"{space}nbs.Write({v.Body}.Count);\r\n");
                sb.Append($"{space}foreach (var kvp in {v.Body})\r\n");
                sb.Append($"{space}{{\r\n");
                sb.Append($"    {space}{GetClassSerializeFromNodeType(v)}\r\n");
                sb.Append($"{space}}}\r\n");
                break;

            default:
                if (v.Ctype.Length > 0 && v.Ctype[0] == 'E')
                {
                    sb.Append($"{space}nbs.Write((short){v.Body});\r\n");
                }
                else
                {
                    sb.Append($"{space}{v.Body}.Serialize(nbs);\r\n");
                }
                break;
            }
            return(sb.ToString());
        }
Пример #7
0
        //成员转化
        public static void GetNodeFromLine(ref CClassNode node)
        {
            node.Line  = LineCount;
            node.Desc  = LineDesc;
            node.Ctype = TypeConvert(LineContect[0]);
            switch (node.Ctype)
            {
            case "list":
                node.Ctype1 = LineContect[1];
                node.Body   = LineContect[2];
                break;

            case "dict":
                node.Ctype1 = LineContect[1];
                node.Ctype2 = LineContect[2];
                node.Body   = LineContect[3];
                break;

            default:
                node.Body = LineContect[1];
                break;
            }
        }
Пример #8
0
        //成员和初始化
        public static string GetClassBodyHtml(CClassNode v)
        {
            var sb = new StringBuilder();

            switch (v.Ctype)
            {
            case "list":
                sb.Append($"List[{v.Ctype1}] {v.Body}");
                break;

            case "dict":
                sb.Append($"Dictionary[{v.Ctype1}, {v.Ctype2}] {v.Body}");
                break;

            default:
                sb.Append($"{v.Ctype} {v.Body}");
                break;
            }
            if (!string.IsNullOrEmpty(v.Desc))
            {
                sb.Append($"  //{v.Desc}");
            }
            return(sb.ToString());
        }
Пример #9
0
        //成员反序列化
        public static string GetClassUnserializeFromNodeType(CClassNode v)
        {
            var    sb      = new StringBuilder();
            string varname = GetVariablesId();

            switch (v.Ctype)
            {
            case "list":
                switch (v.Ctype1)
                {
                case "bool":
                case "byte":
                case "short":
                case "int":
                case "uint":
                case "long":
                case "float":
                case "string":
                case "DateTime":
                case "TimeSpan":
                    sb.Append($"nbs.Read(out {v.Ctype1} {varname});"); break;

                default:
                    sb.Append($"var {varname} = new {v.Ctype1}(); {varname}.Unserialize(nbs);");
                    break;
                }
                sb.Append($"{v.Body}.Add({varname});");
                break;

            case "dict":
                switch (v.Ctype1)
                {
                case "bool":
                case "byte":
                case "short":
                case "int":
                case "uint":
                case "long":
                case "float":
                case "string":
                    sb.Append($"nbs.Read(out {v.Ctype1} {varname}); "); break;

                default:
                    sb.Append($"var {varname} = new {v.Ctype1}(); {varname}.Unserialize(nbs); ");
                    break;
                }
                string varname2 = GetVariablesId();
                switch (v.Ctype2)
                {
                case "bool":
                case "byte":
                case "short":
                case "int":
                case "uint":
                case "long":
                case "float":
                case "string":
                case "DateTime":
                case "TimeSpan":
                    sb.Append($"nbs.Read(out {v.Ctype2} {varname2}); "); break;

                default:
                    sb.Append($"var {varname2} = new {v.Ctype2}(); {varname2}.Unserialize(nbs); ");
                    break;
                }
                sb.Append($"{v.Body}.Add({varname}, {varname2}); ");
                break;

            default:
                break;
            }
            return(sb.ToString());
        }
Пример #10
0
        private static void ProtocolReaderLine()
        {
            if (LineText == "")
            {
                return;
            }
            if (LineText[0] == '$')
            {
                if (LineText.Length >= 2)
                {
                    if (LineText[1] == '$')
                    {
                        MMode2 = LineText.TrimStart('$');
                    }
                    else
                    {
                        MMode1 = LineText.TrimStart('$');
                    }
                }
                return;
            }
            if (LineText[0] == '@')
            {
                ClassDesc = LineText.TrimStart('@');
                return;
            }
            LineText.Trim();
            ProtocolReaderLineAnalyze();

            if (LineContect.Count <= 0)
            {
                return;
            }
            if (LineContect[0] == "enums")
            {
                BodyType    = EBodyType.eBodyTypeEnum;
                EnumCurrent = new CEnum(LineContect[1], ClassDesc);
                CEnumId     = 0;
            }
            else if (LineContect[0] == "enume")
            {
                DictEnum.Add(EnumCurrent.Name, EnumCurrent);
            }
            else if (LineContect[0] == "msgs")
            {
                BodyType = EBodyType.eBodyTypeClass;
                if (LineContect.Count > 2)
                {
                    ClassCurrent = new CClass(0, LineContect[1], ClassDesc, S2I(LineContect[2]));
                }
                else
                {
                    ClassCurrent = new CClass(0, LineContect[1], ClassDesc);
                }
            }
            else if (LineContect[0] == "msge")
            {
                DictClass.Add(ClassCurrent.Name, ClassCurrent);
            }
            else if (LineContect[0] == "pubs")
            {
                BodyType = EBodyType.eBodyTypeClass;
                if (LineContect.Count > 2)
                {
                    ClassCurrent = new CClass(1, LineContect[1], ClassDesc, S2I(LineContect[2]));
                }
                else
                {
                    ClassCurrent = new CClass(1, LineContect[1], ClassDesc);
                }
            }
            else if (LineContect[0] == "pube")
            {
                DictClass.Add(ClassCurrent.Name, ClassCurrent);
            }
            else
            {
                if (BodyType == EBodyType.eBodyTypeEnum)
                {
                    var node = new CEnum.Node()
                    {
                        Line = LineCount,
                        Body = LineContect[0],
                    };
                    if (LineContect.Count > 1)
                    {
                        CEnumId    = S2I(LineContect[1]);
                        node.Value = CEnumId;
                    }
                    else
                    {
                        CEnumId++;
                        node.Value = CEnumId;
                    }
                    node.Desc = LineDesc;
                    EnumCurrent.DictBody.Add(LineCount, node);
                }
                else if (BodyType == EBodyType.eBodyTypeClass)
                {
                    var node = new CClassNode();
                    GetNodeFromLine(ref node);
                    ClassCurrent.DictBody.Add(LineCount, node);
                }
            }
        }
Пример #11
0
        //成员和初始化
        public static string GetClassBodyFromNodeLua(CClassNode v)
        {
            var sb = new StringBuilder();

            switch (v.Ctype)
            {
            case "bool":
                sb.Append($"    self.{v.Body} = false");
                break;

            case "byte":
            case "short":
            case "int":
            case "uint":
            case "long":
            case "float":
                sb.Append($"    self.{v.Body} = 0");
                break;

            case "string":
                sb.Append($"    self.{v.Body} = \"\"");
                break;

            case "dt":
            case "datetime":
            case "DateTime":
                //sb.Append($"        public {v.Ctype} {v.Body} = {v.Ctype}.Now;");
                break;

            case "ts":
            case "timespan":
            case "TimeSpan":
                break;

            case "list":
                sb.Append($"    self.{v.Body} = List:New(Lua{v.Ctype1})");
                break;

            case "dict":
                sb.Append($"    self.{v.Body} = Dictionary:New()");
                break;

            default:
                if (v.Ctype.Length > 0 && v.Ctype[0] == 'E')
                {
                    sb.Append($"    self.{v.Body} = 0");
                }
                else
                {
                    sb.Append($"    self.{v.Body} = Lua{v.Ctype}.new()");
                }
                break;
            }
            if (sb.Length > 0)
            {
                if (v.Desc != "")
                {
                    sb.Append($"    -- {v.Desc}");
                }
            }
            return(sb.ToString());
        }
Пример #12
0
        //成员反序列化
        public static string GetClassUnserializeFromNodeLua(CClassNode v, string space)
        {
            var    sb      = new StringBuilder();
            string varname = GetVariablesId();

            switch (v.Ctype)
            {
            case "bool":
                sb.Append($"{space}self.{v.Body} = nbs:ReadBool()");
                break;

            case "byte":
                sb.Append($"{space}self.{v.Body} = nbs:ReadByte()");
                break;

            case "short":
                sb.Append($"{space}self.{v.Body} = nbs:ReadShort()");
                break;

            case "int":
                sb.Append($"{space}self.{v.Body} = nbs:ReadInt()");
                break;

            case "uint":
                sb.Append($"{space}self.{v.Body} = nbs:ReadUint()");
                break;

            case "long":
                sb.Append($"{space}self.{v.Body} = nbs:ReadLong()");
                break;

            case "float":
                sb.Append($"{space}self.{v.Body} = nbs:ReadFloat()");
                break;

            case "string":
                sb.Append($"{space}self.{v.Body} = nbs:ReadString()");
                break;

            case "DateTime":
                sb.Append($"{space}self.{v.Body} = nbs:ReadDateTime()");
                break;

            case "TimeSpan":
                sb.Append($"{space}self.{v.Body} = nbs:ReadTimeSpan()");
                break;

            case "list":
                sb.AppendLine($"{space}local {varname} = nbs:ReadInt()");
                sb.AppendLine($"{space}for i = 1, {varname} do");
                sb.AppendLine($"    {space}{GetClassUnserializeFromNodeTypeListLua(v)}");
                sb.Append($"{space}end");
                break;

            case "dict":
                sb.AppendLine($"{space}local {varname} = nbs:ReadInt()");
                sb.AppendLine($"{space}for i = 1, {varname} do");
                sb.AppendLine($"    {space}{GetClassUnserializeFromNodeTypeDictLua(v)}");
                sb.Append($"{space}end");
                break;

            default:
                if (v.Ctype.Length > 0 && v.Ctype[0] == 'E')
                {
                    sb.Append($"{space}self.{v.Body} = nbs:ReadShort()");
                }
                else
                {
                    sb.Append($"{space}self.{v.Body}:Unserialize(nbs)");
                }
                break;
            }
            return(sb.ToString());
        }
Пример #13
0
        //成员序列化
        public static string GetClassSerializeFromNodeLua(CClassNode v, string space)
        {
            var sb = new StringBuilder();

            switch (v.Ctype)
            {
            case "bool":
                sb.Append($"{space}nbs:WriteBool(self.{v.Body})");
                break;

            case "byte":
                sb.Append($"{space}nbs:WriteByte(self.{v.Body})");
                break;

            case "short":
                sb.Append($"{space}nbs:WriteShort(self.{v.Body})");
                break;

            case "int":
                sb.Append($"{space}nbs:WriteInt(self.{v.Body})");
                break;

            case "uint":
                sb.Append($"{space}nbs:WriteUInt(self.{v.Body})");
                break;

            case "long":
                sb.Append($"{space}nbs:WriteLong(self.{v.Body})");
                break;

            case "float":
                sb.Append($"{space}nbs:WriteFloat(self.{v.Body})");
                break;

            case "string":
                sb.Append($"{space}nbs:WriteString(self.{v.Body})");
                break;

            case "DateTime":
                sb.Append($"{space}nbs:WriteDateTime(self.{v.Body})");
                break;

            case "TimeSpan":
                sb.Append($"{space}nbs:WriteTimeSpan(self.{v.Body})");
                break;

            case "list":
                sb.AppendLine($"{space}nbs:WriteInt(#self.{v.Body})");
                sb.AppendLine($"{space}for i = 1, #self.{v.Body} do");
                sb.AppendLine($"    {space}{GetClassSerializeFromNodeTypeListLua(v)}");
                sb.Append($"{space}end");
                break;

            case "dict":
                sb.AppendLine($"{space}nbs:WriteInt(#self.{v.Body})");
                sb.AppendLine($"{space}for key, value in pairs(self.{v.Body}) do");
                sb.AppendLine($"    {space}{GetClassSerializeFromNodeTypeDictLua(v)}");
                sb.Append($"{space}end");
                break;

            default:
                if (v.Ctype.Length > 0 && v.Ctype[0] == 'E')
                {
                    sb.Append($"{space}nbs:WriteShort({v.Body})");
                }
                else
                {
                    sb.Append($"{space}{v.Body}:Serialize(nbs)");
                }
                break;
            }
            return(sb.ToString());
        }
Пример #14
0
        //成员序列化
        public static string GetClassSerializeFromNodeTypeDictLua(CClassNode v)
        {
            var sb = new StringBuilder();

            switch (v.Ctype1)
            {
            case "bool":
                sb.Append($"nbs:WriteBool(key)");
                break;

            case "byte":
                sb.Append($"nbs:WriteByte(key)");
                break;

            case "short":
                sb.Append($"nbs:WriteShort(key)");
                break;

            case "int":
                sb.Append($"nbs:WriteInt(key)");
                break;

            case "uint":
                sb.Append($"nbs:WriteUInt(key)");
                break;

            case "long":
                sb.Append($"nbs:WriteLong(key)");
                break;

            case "float":
                sb.Append($"nbs:WriteFloat(key)");
                break;

            case "string":
                sb.Append($"nbs:WriteString(key)");
                break;

            case "DateTime":
                sb.Append($"nbs:WriteDateTime(key)");
                break;

            case "TimeSpan":
                sb.Append($"nbs:WriteTimeSpan(key)");
                break;

            default:
                sb.Append($"key:Serialize(nbs)");
                break;
            }
            sb.AppendLine();
            sb.Append("        ");
            switch (v.Ctype2)
            {
            case "bool":
                sb.Append($"nbs:WriteBool(value)");
                break;

            case "byte":
                sb.Append($"nbs:WriteByte(value)");
                break;

            case "short":
                sb.Append($"nbs:WriteShort(value)");
                break;

            case "int":
                sb.Append($"nbs:WriteInt(value)");
                break;

            case "uint":
                sb.Append($"nbs:WriteUInt(value)");
                break;

            case "long":
                sb.Append($"nbs:WriteLong(value)");
                break;

            case "float":
                sb.Append($"nbs:WriteFloat(value)");
                break;

            case "string":
                sb.Append($"nbs:WriteString(value)");
                break;

            case "DateTime":
                sb.Append($"nbs:WriteDateTime(value)");
                break;

            case "TimeSpan":
                sb.Append($"nbs:WriteTimeSpan(value)");
                break;

            default:
                sb.Append($"value:Serialize(nbs)");
                break;
            }
            return(sb.ToString());
        }