예제 #1
0
    public bool Request(string proto, SpObject args, int session, SpStream stream)
    {
        SpStream encode_stream = EncodeRequest(proto, args, session);

        encode_stream.Position = 0;
        return(SpPacker.Pack(encode_stream, stream));
    }
예제 #2
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);
    }
예제 #3
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);
    }
예제 #4
0
    private void TestStr(string s)
    {
        SpObject obj = new SpObject(SpObject.ArgType.Table, "a", s);

        Util.Log("------------------TestStr----------------------------");
        Util.Log(s);

        Util.Log("Encode");
        SpStream encode_stream = new SpStream(2);
        bool     ret           = manager.Codec.Encode("ss", obj, encode_stream);

        Util.Assert(ret == false);
        encode_stream = new SpStream(encode_stream.Position);
        ret           = manager.Codec.Encode("ss", obj, encode_stream);
        Util.Assert(ret == true);
        encode_stream.Position = 0;
        Util.DumpStream(encode_stream);

        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;
        SpObject dobj = manager.Codec.Decode("ss", unpack_stream);
        string   ds   = dobj["a"].AsString();

        Util.Log(ds);
        Util.Assert(s == ds);
    }
예제 #5
0
    public double EncodeAndPack()
    {
        double begin = GetMs();

        for (int i = 0; i < BENCHUMARK_RUN_TIMES; i++)
        {
            encode_stream.Position = 0;
            pack_stream.Position   = 0;
            unpack_stream.Position = 0;

            manager.Codec.Encode("AddressBook", obj, encode_stream);
            SpPacker.Pack(encode_stream, pack_stream);
            //SpPacker.Unpack (pack_stream, unpack_stream);
            unpack_stream.Position = 0;
            //manager.Codec.Decode ("AddressBook", unpack_stream);
        }

        double end = GetMs();

        return((end - begin) / 1000);
    }
예제 #6
0
    public SpStream Response(int session, SpObject args)
    {
        SpObject header = new SpObject();

        header.Insert("session", session);

        SpStream encode_stream = new SpStream();

        mHostTypeManager.Codec.Encode(mHeaderType, header, encode_stream);

        if (session != 0 && mSessions.ContainsKey(session))
        {
            mHostTypeManager.Codec.Encode(mSessions[session].Response, args, encode_stream);
        }

        SpStream pack_stream = new SpStream();

        encode_stream.Position = 0;
        SpPacker.Pack(encode_stream, pack_stream);

        pack_stream.Position = 0;
        return(pack_stream);
    }
예제 #7
0
    private void TestNest()
    {
        SpObject clist = new SpObject(SpObject.ArgType.Table,
                                      "character",
                                      new SpObject(SpObject.ArgType.Array,
                                                   new SpObject(SpObject.ArgType.Table,
                                                                "id",
                                                                1,
                                                                "attribute",
                                                                new SpObject(SpObject.ArgType.Table,
                                                                             "level",
                                                                             1,
                                                                             "templateId",
                                                                             1001,
                                                                             "ability",
                                                                             new SpObject(SpObject.ArgType.Table,
                                                                                          "hp", 2530,
                                                                                          "att", 2310
                                                                                          )
                                                                             )
                                                                ),
                                                   new SpObject(SpObject.ArgType.Table,
                                                                "id",
                                                                2,
                                                                "attribute",
                                                                new SpObject(SpObject.ArgType.Table,
                                                                             "level",
                                                                             1,
                                                                             "templateId",
                                                                             1002,
                                                                             "ability",
                                                                             new SpObject(SpObject.ArgType.Table,
                                                                                          "hp", 1320,
                                                                                          "att", 2090
                                                                                          )
                                                                             )
                                                                )
                                                   )
                                      );

        Util.Log("------------------TEST CHARACTER----------------------------");
        Util.DumpObject(clist);

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

        manager.Codec.Encode("clist", clist, encode_stream);
        encode_stream.Position = 0;
        Util.DumpStream(encode_stream);

        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;
        SpObject dobj = manager.Codec.Decode("clist", unpack_stream);

        Util.DumpObject(dobj);
    }
예제 #8
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);
    }