예제 #1
0
        public void TestWriteEnum()
        {
            ProtoBufferDic  dic = new ProtoBufferDic("dic");
            ProtoBufferFile file;
            List <string>   list;

            list = new List <string>();
            list.Add("package com.morln.game;");
            list.Add("enum FooEnum {");
            list.Add("ONE = 1;");

            list.Add("}");

            list.Add("message Foo{");
            list.Add("required FooEnum required_enum = 1;");
            list.Add("optional FooEnum optional_enum = 2;");
            list.Add("repeated FooEnum repeated_enum = 3;");
            list.Add("}");
            file = new ProtoBufferFile("foo.proto", dic, list);
            dic.AddFile(file);
            dic.Parse();

            ProtoBufferMessage msg = dic.Message("com.morln.game", "Foo");

            ProtoBufferMessageWriter writer = new ProtoBufferMessageWriter();

            writer.NeedCheckRequired = true;
            MemoryStream memoryStream = new MemoryStream();

            writer.WriteMessage(msg, memoryStream);
            string content = UTF8Encoding.UTF8.GetString(memoryStream.ToArray());

            Console.WriteLine(content);
        }
예제 #2
0
        public void TestMultiFiles()
        {
            ProtoBufferDic  dic = new ProtoBufferDic("dic");
            ProtoBufferFile file;
            List <string>   list;

            list = new List <string>();
            list.Add("package com.morln.game;");

            list.Add("message Foo {");

            list.Add("required bool a_required_bool = 1;");
            list.Add("required int32 a_required_int = 2;");
            list.Add("required int64 a_required_long = 3;");
            list.Add("required float a_required_float = 4;");
            list.Add("required double a_required_double = 5;");
            list.Add("required string a_required_string = 6;");
            list.Add("required bytes a_required_bytes = 7;");

            list.Add("optional bool a_optional_bool = 8;");
            list.Add("optional int32 a_optional_int = 9;");
            list.Add("optional int64 a_optional_long = 10;");
            list.Add("optional float a_optional_float = 11;");
            list.Add("optional double a_optional_double = 12;");
            list.Add("optional string a_optional_string = 13;");
            list.Add("optional bytes a_optional_bytes = 14;");

            list.Add("repeated bool a_repeated_bool = 15;");
            list.Add("repeated int32 a_repeated_int = 16;");
            list.Add("repeated int64 a_repeated_long = 17;");
            list.Add("repeated float a_repeated_float = 18;");
            list.Add("repeated double a_repeated_double = 19;");
            list.Add("repeated string a_repeated_string = 20;");
            list.Add("repeated bytes a_repeated_bytes = 21;");


            list.Add("}");


            file = new ProtoBufferFile("foo.proto", dic, list);
            dic.AddFile(file);
            dic.Parse();

            ProtoBufferMessage msg = dic.Message("com.morln.game", "Foo");

            ProtoBufferMessageWriter writer = new ProtoBufferMessageWriter();

            writer.NeedCheckRequired = true;
            MemoryStream memoryStream = new MemoryStream();

            writer.WriteMessage(msg, memoryStream);
            string content = UTF8Encoding.UTF8.GetString(memoryStream.ToArray());

            Console.WriteLine(content);
        }
예제 #3
0
        public void TestLocalFiles()
        {
            string path = "E:\\tmp";

               ProtoBufferDic dic = new ProtoBufferDic(path);

               dic.Parse();

               ProtoBufferMessageWriter writer = new ProtoBufferMessageWriter();

               foreach (ProtoBufferMessage msg in dic.Messages)
               {
               writer.WriteMessage(msg, path);

               }
        }
예제 #4
0
        public void TestMultiNamespace()
        {
            ProtoBufferDic  dic = new ProtoBufferDic();
            List <string>   list;
            ProtoBufferFile file;

            list = new List <string>();
            list.Add("package com.morln.fooenum;");
            list.Add("enum FooEnum{");
            list.Add("}");
            file = new ProtoBufferFile("fooenum.proto", dic, list);
            dic.AddFile(file);
            list = new List <string>();
            list.Add("package com.morln.foo;");
            list.Add("message Foo{");
            list.Add("}");
            file = new ProtoBufferFile("foo.proto", dic, list);
            dic.AddFile(file);

            list = new List <string>();
            list.Add("package com.morln.packet;");
            list.Add("import fooenum.proto;");
            list.Add("import foo.proto");
            list.Add("message Packet{");
            list.Add("required FooEnum a_foo_enum = 1");
            list.Add("required Foo foo = 2");
            list.Add("repeated int32 value = 3;");
            list.Add("}");

            file = new ProtoBufferFile("packet.proto", dic, list);
            dic.AddFile(file);


            dic.Parse();

            ProtoBufferMessage msg = dic.Message("com.morln.packet", "Packet");

            ProtoBufferMessageWriter writer = new ProtoBufferMessageWriter();

            writer.NeedCheckRequired = true;
            MemoryStream memoryStream = new MemoryStream();

            writer.WriteMessage(msg, memoryStream);
            string content = UTF8Encoding.UTF8.GetString(memoryStream.ToArray());

            Console.WriteLine(content);
        }
예제 #5
0
        public void TestLocalFiles()
        {
            string path = "E:\\tmp";


            ProtoBufferDic dic = new ProtoBufferDic(path);


            dic.Parse();

            ProtoBufferMessageWriter writer = new ProtoBufferMessageWriter();

            foreach (ProtoBufferMessage msg in dic.Messages)
            {
                writer.WriteMessage(msg, path);
            }
        }
예제 #6
0
        public void TestWriteEnum()
        {
            ProtoBufferDic dic = new ProtoBufferDic("dic");
            ProtoBufferFile file;
            List<string> list;

            list = new List<string>();
            list.Add("package com.morln.game;");
            list.Add("enum FooEnum {");
            list.Add("ONE = 1;");

            list.Add("}");

            list.Add("message Foo{");
            list.Add("required FooEnum required_enum = 1;");
            list.Add("optional FooEnum optional_enum = 2;");
            list.Add("repeated FooEnum repeated_enum = 3;");
            list.Add("}");
            file = new ProtoBufferFile("foo.proto", dic, list);
            dic.AddFile(file);
            dic.Parse();

            ProtoBufferMessage msg = dic.Message("com.morln.game", "Foo");

            ProtoBufferMessageWriter writer = new ProtoBufferMessageWriter();
            writer.NeedCheckRequired = true;
            MemoryStream memoryStream = new MemoryStream();
            writer.WriteMessage(msg, memoryStream);
            string content = UTF8Encoding.UTF8.GetString(memoryStream.ToArray());
            Console.WriteLine(content);
        }
예제 #7
0
        public void TestMultiNamespace()
        {
            ProtoBufferDic dic = new ProtoBufferDic();
            List<string> list;
            ProtoBufferFile file;

            list = new List<string>();
            list.Add("package com.morln.fooenum;");
            list.Add("enum FooEnum{");
            list.Add("}");
            file = new ProtoBufferFile("fooenum.proto", dic, list);
            dic.AddFile(file);
            list = new List<string>();
            list.Add("package com.morln.foo;");
            list.Add("message Foo{");
            list.Add("}");
            file = new ProtoBufferFile("foo.proto", dic, list);
            dic.AddFile(file);

            list = new List<string>();
            list.Add("package com.morln.packet;");
            list.Add("import fooenum.proto;");
            list.Add("import foo.proto");
            list.Add("message Packet{");
            list.Add("required FooEnum a_foo_enum = 1");
            list.Add("required Foo foo = 2");
            list.Add("repeated int32 value = 3;");
            list.Add("}");

            file = new ProtoBufferFile("packet.proto", dic, list);
            dic.AddFile(file);

            dic.Parse();

            ProtoBufferMessage msg = dic.Message("com.morln.packet", "Packet");

            ProtoBufferMessageWriter writer = new ProtoBufferMessageWriter();
            writer.NeedCheckRequired = true;
            MemoryStream memoryStream = new MemoryStream();
            writer.WriteMessage(msg, memoryStream);
            string content = UTF8Encoding.UTF8.GetString(memoryStream.ToArray());
            Console.WriteLine(content);
        }
예제 #8
0
        public void TestMultiFiles()
        {
            ProtoBufferDic dic = new ProtoBufferDic("dic");
            ProtoBufferFile file;
            List<string> list ;

            list = new List<string>();
            list.Add("package com.morln.game;");

            list.Add("message Foo {");

            list.Add("required bool a_required_bool = 1;");
            list.Add("required int32 a_required_int = 2;");
            list.Add("required int64 a_required_long = 3;");
            list.Add("required float a_required_float = 4;");
            list.Add("required double a_required_double = 5;");
            list.Add("required string a_required_string = 6;");
            list.Add("required bytes a_required_bytes = 7;");

            list.Add("optional bool a_optional_bool = 8;");
            list.Add("optional int32 a_optional_int = 9;");
            list.Add("optional int64 a_optional_long = 10;");
            list.Add("optional float a_optional_float = 11;");
            list.Add("optional double a_optional_double = 12;");
            list.Add("optional string a_optional_string = 13;");
            list.Add("optional bytes a_optional_bytes = 14;");

            list.Add("repeated bool a_repeated_bool = 15;");
            list.Add("repeated int32 a_repeated_int = 16;");
            list.Add("repeated int64 a_repeated_long = 17;");
            list.Add("repeated float a_repeated_float = 18;");
            list.Add("repeated double a_repeated_double = 19;");
            list.Add("repeated string a_repeated_string = 20;");
            list.Add("repeated bytes a_repeated_bytes = 21;");

            list.Add("}");

            file = new ProtoBufferFile("foo.proto",dic,list);
            dic.AddFile(file);
            dic.Parse();

            ProtoBufferMessage msg = dic.Message("com.morln.game","Foo");

            ProtoBufferMessageWriter writer = new ProtoBufferMessageWriter();
            writer.NeedCheckRequired = true;
            MemoryStream memoryStream = new MemoryStream();
            writer.WriteMessage(msg,memoryStream);
            string content = UTF8Encoding.UTF8.GetString(memoryStream.ToArray());
            Console.WriteLine(content);
        }