Ejemplo n.º 1
0
    public static SpTypeManager Import(Stream stream)
    {
        SpTypeManager instance = new SpTypeManager();

        new SpProtoParser(instance).Parse(stream);
        return(instance);
    }
Ejemplo n.º 2
0
    public static SpTypeManager Import(string proto)
    {
        SpTypeManager instance = new SpTypeManager();

        new SpProtoParser(instance).Parse(proto);
        return(instance);
    }
Ejemplo n.º 3
0
	public SpField (string name, short tag, string type, bool table, string key, SpTypeManager m) {
		Name = name;
		Tag = tag;
		TypeName = type;
		IsTable = table;
		KeyName = key;

        mTypeManager = m;
	}
Ejemplo n.º 4
0
	public Benchmark () {
        manager = LoadProto ();
		
		obj = CreateObject ();
		manager.Codec.Encode ("AddressBook", obj, encode_stream);
		encode_stream.Position = 0;
		SpPacker.Pack (encode_stream, pack_stream);
		pack_stream.Position = 0;
		SpPacker.Unpack (pack_stream, unpack_stream);
	}
Ejemplo n.º 5
0
    private SpTypeManager LoadProto()
    {
        SpTypeManager tm   = null;
        string        path = Util.GetFullPath("foobar.sproto");

        using (FileStream stream = new FileStream(path, FileMode.Open)) {
            tm = SpTypeManager.Import(stream);
        }
        return(tm);
    }
Ejemplo n.º 6
0
    public SpField(string name, short tag, string type, bool table, string key, SpTypeManager m)
    {
        Name     = name;
        Tag      = tag;
        TypeName = type;
        IsTable  = table;
        KeyName  = key;

        mTypeManager = m;
    }
Ejemplo n.º 7
0
    public Benchmark()
    {
        manager = LoadProto();

        obj = CreateObject();
        manager.Codec.Encode("AddressBook", obj, encode_stream);
        encode_stream.Position = 0;
        SpPacker.Pack(encode_stream, pack_stream);
        pack_stream.Position = 0;
        SpPacker.Unpack(pack_stream, unpack_stream);
    }
Ejemplo n.º 8
0
    public void Run()
    {
        SpTypeManager server_tm = SpTypeManager.Import(server_proto);

        server = SpRpc.Create(server_tm, "package");

        client = SpRpc.Create(client_proto, "package");
        client.Attach(server_tm);

        TestFoobar();
        TestFoo();
        TestBar();
        TestBlackhole();
    }
Ejemplo n.º 9
0
    public void Run()
    {
        string proto = @"
			.ss {
				a 0 : string
			}

			.ability {
				hp 0 : integer
				att 1 : integer
			}

			.attribute {
				templateId 0 : integer
				level 1 : integer
				ability 2 : ability
			}

			.character {
				id 0 : integer
				attribute 1 : attribute
			}

			.clist {
				character 0 : *character(id)
			}
			
		"        ;

        manager = SpTypeManager.Import(proto);



        TestStr("12345678");         /*
                                      * TestNest ();
                                      *
                                      * TestStr ("");
                                      * TestStr ("123");
                                      * TestStr ("123456");
                                      * TestStr ("12345678");
                                      * TestStr ("12345678123");
                                      * TestStr ("12345678123456");
                                      * TestStr ("1234567812345678");
                                      * TestStr ("12345678123456781234567812345678");
                                      * TestStr ("123456781234567812345678123456781");
                                      * TestStr ("123456781234567812345678123456781234567"); */
    }
Ejemplo n.º 10
0
    public void Run()
    {
        SpTypeManager manager = LoadProto();

        SpObject obj = CreateObject();

        CheckObj(obj);

        Util.Log("Encode");
        SpStream encode_stream = new SpStream();

        manager.Codec.Encode("AddressBook", obj, encode_stream);

        encode_stream.Position = 0;
        Util.DumpStream(encode_stream);

        Util.Log("Decode");
        encode_stream.Position = 0;
        SpObject newObj = manager.Codec.Decode("AddressBook", encode_stream);

        CheckObj(newObj);

        Util.Log("Pack");
        encode_stream.Position = 0;
        SpStream pack_stream = new SpStream();

        SpPacker.Pack(encode_stream, pack_stream);

        pack_stream.Position = 0;
        Util.DumpStream(pack_stream);

        Util.Log("Unpack");
        pack_stream.Position = 0;
        SpStream unpack_stream = new SpStream();

        SpPacker.Unpack(pack_stream, unpack_stream);

        unpack_stream.Position = 0;
        Util.DumpStream(unpack_stream);

        Util.Log("Decode");
        unpack_stream.Position = 0;
        newObj = manager.Codec.Decode("AddressBook", unpack_stream);
        CheckObj(newObj);
    }
Ejemplo n.º 11
0
    public static SpRpc Create(SpTypeManager tm, string package)
    {
        if (tm == null)
        {
            return(null);
        }

        SpType t = tm.GetType(package);

        if (t == null)
        {
            return(null);
        }

        SpRpc rpc = new SpRpc(tm, t);

        return(rpc);
    }
Ejemplo n.º 12
0
        private SpRpc CreateProto(string subDir)
        {
            SpTypeManager c2SMgr;
            SpTypeManager s2CMgr;

            var c2S = _path + subDir + "/c2s.sproto";

            using (var stream = new FileStream(c2S, FileMode.Open)) {
                c2SMgr = SpTypeManager.Import(stream);
            }

            var s2C = _path + subDir + "/s2c.sproto";

            using (var stream = new FileStream(s2C, FileMode.Open)) {
                s2CMgr = SpTypeManager.Import(stream);
            }

            var rpc = SpRpc.Create(s2CMgr, "package");

            rpc.Attach(c2SMgr);
            return(rpc);
        }
Ejemplo n.º 13
0
 public static SpRpc Create(string proto, string package)
 {
     return(Create(SpTypeManager.Import(proto), package));
 }
Ejemplo n.º 14
0
	public void Run () {
		
		string proto = @"
			.ss {
				a 0 : string
			}

			.ability {
				hp 0 : integer
				att 1 : integer
			}

			.attribute {
				templateId 0 : integer
				level 1 : integer
				ability 2 : ability
			}

			.character {
				id 0 : integer
				attribute 1 : attribute
			}

			.clist {
				character 0 : *character(id)
			}
			
		";
		manager = SpTypeManager.Import (proto);


		
		TestStr ("12345678");/*
		TestNest ();
		
		TestStr ("");
		TestStr ("123");
		TestStr ("123456");
		TestStr ("12345678");
		TestStr ("12345678123");
		TestStr ("12345678123456");
		TestStr ("1234567812345678");
		TestStr ("12345678123456781234567812345678");
		TestStr ("123456781234567812345678123456781");
		TestStr ("123456781234567812345678123456781234567"); */
	}
Ejemplo n.º 15
0
 public SpRpc(SpTypeManager tm, SpType t)
 {
     mHostTypeManager = tm;
     mHeaderType      = t;
 }
Ejemplo n.º 16
0
    public void Run()
    {
        SpTypeManager manager = LoadProto();

        // different ways to create SpObject
        Util.Log("Object Create Check");
        CheckObj(CreateObject());
        CheckObj(CreateObject2());
        SpObject obj = CreateObject3();

        CheckObj(obj);

        Util.Log("Encode");
        SpStream small_stream = new SpStream(32);
        bool     success      = manager.Codec.Encode("foobar", obj, small_stream);

        Util.Assert(success == false);
        Util.Log("encode failed! require size : " + small_stream.Position);
        small_stream.Position = 0;
        Util.DumpStream(small_stream);

        SpStream encode_stream = manager.Codec.Encode("foobar", obj);

        encode_stream.Position = 0;
        Util.DumpStream(encode_stream);

        Util.Log("Decode ");
        encode_stream.Position = 0;
        SpObject ooo = manager.Codec.Decode("foobar", encode_stream);

        CheckObj(ooo);

        Util.Log("Pack");
        encode_stream.Position = 0;
        small_stream.Position  = 0;
        success = SpPacker.Pack(encode_stream, small_stream);
        Util.Assert(success == false);
        Util.Log("pack failed! require size : " + small_stream.Position);
        small_stream.Position = 0;
        Util.DumpStream(small_stream);

        SpStream pack_stream = SpPacker.Pack(encode_stream);

        pack_stream.Position = 0;
        Util.DumpStream(pack_stream);

        Util.Log("Unpack");
        pack_stream.Position  = 0;
        small_stream.Position = 0;
        success = SpPacker.Unpack(pack_stream, small_stream);
        Util.Assert(success == false);
        Util.Log("unpack failed! require size : " + small_stream.Position);
        small_stream.Position = 0;
        Util.DumpStream(small_stream);

        pack_stream.Position = 0;
        SpStream decode_stream = SpPacker.Unpack(pack_stream);

        decode_stream.Position = 0;
        Util.DumpStream(decode_stream);

        Util.Log("Decode ");
        decode_stream.Position = 0;
        SpObject newObj = manager.Codec.Decode("foobar", decode_stream);

        CheckObj(newObj);
    }
Ejemplo n.º 17
0
 public void Attach(string proto)
 {
     Attach(SpTypeManager.Import(proto));
 }
Ejemplo n.º 18
0
 public void Attach(SpTypeManager tm)
 {
     mAttachTypeManager = tm;
 }
Ejemplo n.º 19
0
 public void Attach (SpTypeManager tm) {
     mAttachTypeManager = tm;
 }
Ejemplo n.º 20
0
 public SpRpc (SpTypeManager tm, SpType t) {
     mHostTypeManager = tm;
     mHeaderType = t;
 }
Ejemplo n.º 21
0
    public static SpRpc Create (SpTypeManager tm, string package) {
        if (tm == null)
            return null;

        SpType t = tm.GetType (package);
        if (t == null)
            return null;

        SpRpc rpc = new SpRpc (tm, t);
        return rpc;
    }
Ejemplo n.º 22
0
 public SpCodec (SpTypeManager m) {
     mTypeManager = m;
 }
Ejemplo n.º 23
0
 public SpCodec(SpTypeManager m)
 {
     mTypeManager = m;
 }