コード例 #1
0
        public void Test_Add()
        {
            XType add = vf.GetType("add");

            Field x = new Field("x");

            add.PutValidator(x, Validator_int.Get(0));

            Field y = new Field("y");

            add.PutValidator(y, Validator_int.Get(0));

            Field _mf__messageId = DefaultValueFactory._mf__messageId;

            add.PutValidator(_mf__messageId, Validator_long.Get(0));

            long msgid = 0x0102030405060708L;

            Message msg = new Message(add, vf);

            msg.Add(x, 1);
            msg.Add(y, 2);
            msg.Add(_mf__messageId, msgid);
            testmsg2bytes(msg, null, new sbyte[] { 3, -122, 39, -23, -73, -100, 3, -122, 21, 10, 44, -77, 1, -122, 99, 6, -76, 104, -121, 1, 2, 3, 4, 5, 6, 7, 8, -122, 21, 10, 44, -76, 2, -127 });
            testmsg2bytes(msg, false, new sbyte[] { 3, -122, 39, -23, -73, -100, 3, -122, 21, 10, 44, -77, 1, -122, 99, 6, -76, 104, -121, 1, 2, 3, 4, 5, 6, 7, 8, -122, 21, 10, 44, -76, 2, -127 });
            testmsg2bytes(msg, true, new sbyte[] { 3, -109, 3, 97, 100, 100, 3, -109, 1, 120, 1, -109, 10, 95, 109, 101, 115, 115, 97, 103, 101, 73, 100, -121, 1, 2, 3, 4, 5, 6, 7, 8, -109, 1, 121, 2, -127 });

            msg = new Message(add, vf);
            msg.Add(x, 1000000000);
            msg.Add(y, 2000000000);
            msg.Add(_mf__messageId, msgid);
            testmsg2bytes(msg, null, new sbyte[] { 3, -122, 39, -23, -73, -100, 3, -122, 21, 10, 44, -77, -122, 59, -102, -54, 0, -122, 99, 6, -76, 104, -121, 1, 2, 3, 4, 5, 6, 7, 8, -122, 21, 10, 44, -76, -122, 119, 53, -108, 0, -127 });
            testmsg2bytes(msg, false, new sbyte[] { 3, -122, 39, -23, -73, -100, 3, -122, 21, 10, 44, -77, -122, 59, -102, -54, 0, -122, 99, 6, -76, 104, -121, 1, 2, 3, 4, 5, 6, 7, 8, -122, 21, 10, 44, -76, -122, 119, 53, -108, 0, -127 });
            testmsg2bytes(msg, true, new sbyte[] { 3, -109, 3, 97, 100, 100, 3, -109, 1, 120, -122, 59, -102, -54, 0, -109, 10, 95, 109, 101, 115, 115, 97, 103, 101, 73, 100, -121, 1, 2, 3, 4, 5, 6, 7, 8, -109, 1, 121, -122, 119, 53, -108, 0, -127 });
        }
コード例 #2
0
ファイル: TestMessage.cs プロジェクト: NeoTim/etch
        public TestMessage()
        {
            mt1.PutValidator(mf1, Validator_int.Get(0));
            mt1.PutValidator(mf2, Validator_int.Get(0));
            mt1.PutValidator(vf.mf_messageId, Validator_long.Get(0));

            rmt.PutValidator(vf.mf_messageId, Validator_long.Get(0));
            rmt.PutValidator(vf.mf_inReplyTo, Validator_long.Get(0));
        }
コード例 #3
0
        /// <summary>
        /// Defines custom fields in the value factory so that the importer
        /// can find them
        /// </summary>
        /// <param name="type"></param>
        /// <param name="class2type"></param>
        public static void Init(XType type, Class2TypeMap class2type)
        {
            Field field = type.GetField(FIELD_NAME);

            class2type.Add(typeof(DateTime), type);
            type.SetComponentType(typeof(DateTime));
            type.SetImportExportHelper(new DateSerializer(type, field));
            type.PutValidator(field, Validator_long.Get(0));
            type.Lock();
        }
コード例 #4
0
ファイル: TestMessagizer.cs プロジェクト: NeoTim/etch
            static MyValueFactory()
            {
                DefaultValueFactory.Init(types, class2type);

                mt_add.PutValidator(mf_x, Validator_int.Get(0));
                mt_add.PutValidator(mf_y, Validator_int.Get(0));
                mt_add.PutValidator(DefaultValueFactory._mf__messageId, Validator_long.Get(0));

                mt_add_result.PutValidator(mf_result, Validator_int.Get(0));
                mt_add_result.PutValidator(DefaultValueFactory._mf__messageId, Validator_long.Get(0));
                mt_add_result.PutValidator(DefaultValueFactory._mf__inReplyTo, Validator_long.Get(0));
            }
コード例 #5
0
        public void Test_add_perf()
        {
            vf = new MyValueFactory();

            XType add = vf.GetType("add");

            Field x = new Field("x");

            add.PutValidator(x, Validator_int.Get(0));

            Field y = new Field("y");

            add.PutValidator(y, Validator_int.Get(0));

            Field _mf__messageId = DefaultValueFactory._mf__messageId;

            add.PutValidator(_mf__messageId, Validator_long.Get(0));

            long msgid = 0x0123456789abcdefL;

            Message msg = new Message(add, vf);

            msg.Add(x, 123456789);
            msg.Add(y, 876543210);
            msg.Add(_mf__messageId, msgid);

            Resources res = new Resources();

            res.Add(TransportConsts.VALUE_FACTORY, vf);
            MyPacketSource ps = new MyPacketSource();
            Messagizer     m  = new Messagizer(ps, "foo:?Messagizer.format=binary", res);

            m.TransportMessage(null, msg);


            int n = 900973;

            for (int i = 0; i < 3; i++)
            {
                TestPerf("test_add_perf", i, m, msg, n);
            }
        }
コード例 #6
0
        public void Test_sum_perf()
        {
            XType sum = vf.GetType("sum");

            Field values = new Field("values");

            sum.PutValidator(values, Validator_int.Get(1));

            Field _mf__messageId = DefaultValueFactory._mf__messageId;

            sum.PutValidator(_mf__messageId, Validator_long.Get(0));

            long msgid = 0x0123456789abcdefL;

            int[] array = new int[2];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = 123456789;
            }

            Message msg = new Message(sum, vf);

            msg.Add(values, array);
            msg.Add(_mf__messageId, msgid);

            Resources res = new Resources();

            res.Add(TransportConsts.VALUE_FACTORY, vf);
            MyPacketSource ps = new MyPacketSource();
            Messagizer     m  = new Messagizer(ps, "foo:?Messagizer.format=binary", res);

            m.TransportMessage(null, msg);

            int n = 509520;

            for (int i = 0; i < 1; i++)
            {
                TestPerf("test_sum_perf", i, m, msg, n);
            }
        }
コード例 #7
0
        public void Test_long()
        {
            // 2 dimensional
            TestX(new long[][] { new long[] { long.MinValue, int.MinValue, short.MinValue,
                                              SByte.MinValue, -1, 0, 1, sbyte.MaxValue, short.MaxValue,
                                              int.MaxValue, long.MaxValue }, new long[] { 23 } },
                  Validator_long.Get(2));

            // 3 dimensional
            TestX(
                new long[][][]
            {
                new long[][] { new long[] { long.MinValue, int.MinValue, short.MinValue,
                                            SByte.MinValue, -1, 0, 1, sbyte.MaxValue, short.MaxValue,
                                            int.MaxValue, long.MaxValue }, new long[] { 23 } },
                new long[][] { new long[] { long.MinValue, int.MaxValue, short.MaxValue,
                                            SByte.MinValue, -1, 0, 1, sbyte.MaxValue, short.MinValue,
                                            int.MinValue, long.MaxValue }, new long[] { 23 } },
                new long[][] { new long[] { long.MaxValue, int.MaxValue, short.MaxValue,
                                            SByte.MaxValue, -1, 0, 1, sbyte.MinValue, short.MinValue,
                                            int.MinValue, long.MinValue }, new long[] { 23 } }
            },
                Validator_long.Get(3));
        }
コード例 #8
0
        public void test_add_in()
        {
            XType add = vf.GetType("add");

            Field x = new Field("x");

            add.PutValidator(x, Validator_int.Get(0));

            Field y = new Field("y");

            add.PutValidator(y, Validator_int.Get(0));

            Field _mf__messageId = DefaultValueFactory._mf__messageId;

            add.PutValidator(_mf__messageId, Validator_long.Get(0));

            long msgid = 0x0123456789abcdefL;

            //sbyte[] _buf = { 1, -9, -100, -73, -23, 39, -9, 104, -76, 6, 99, -13, -17, -51, -85, -119, 103, 69, 35, 1, -9, -76, 44, 10, 21, 66, -9, -77, 44, 10, 21, 65, -22 } ;
            sbyte[] _buf = { 3,                   // version
                             -122,                // INT (Type)
                             39,   -23, -73,-100, // add
                             3,                   // length
                             -122,
                             99,     6, -76, 104,
                             -121,                // LONG (value)
                             1,     35,  69, 103,-119, -85, -51, -17,
                             -122,                // INT (key)
                             21,    10,  44, -76, // y
                             2,                   // tiny int = 2 (value)
                             -122,                // INT (key)
                             21,    10,  44, -77, // x
                             1,                   // tiny int =1
                             -127                 // NONE
            };
            byte[]  buf = new byte[_buf.Length];
            Buffer.BlockCopy(_buf, 0, buf, 0, _buf.Length);

            Message msg = Bytes2msg(buf);

            msg.CheckType(add);
            Assert.AreEqual(3, msg.Count);
            Assert.AreEqual(1, msg[x]);
            Assert.AreEqual(2, msg[y]);
            Assert.AreEqual(msgid, msg[_mf__messageId]);

            //_buf = new sbyte[] { 1, -9, -100, -73, -23, 39, -9, 104, -76, 6, 99, -13, -17, -51, -85, -119, 103, 69, 35, 1, -9, -76, 44, 10, 21, -9, 0, -108, 53, 119, -9, -77, 44, 10, 21, -9, 0, -54, -102, 59, -22 };
            // _buf = new sbyte[] { 3, -9, 39, -23, -73, -100, -9, 99, 6, -76, 104, -13, 1, 35, 69, 103, -119, -85, -51, -17, -9, 21, 10, 44, -76, -9, 119, 53, -108, 0, -9, 21, 10, 44, -77, -9, 59, -102, -54, 0, -22 };
            _buf = new sbyte[]
            {
                3,                  // version
                -122,               // INT (type)
                39, -23, -73, -100, // add
                3,                  // length
                -122,               // INT (key)
                99, 6, -76, 104,
                -121,               // LONG (value)
                1, 35, 69, 103, -119, -85, -51, -17,
                -122,               // INT (key)
                21, 10, 44, -76,    // y
                -122,               // INT (value)
                119, 53, -108, 0,
                -122,               // INT (key)
                21, 10, 44, -77,    // x
                -122,               // INT (value)
                59, -102, -54, 0,
                -127                // NONE
            };

            buf = new byte[_buf.Length];
            Buffer.BlockCopy(_buf, 0, buf, 0, _buf.Length);

            msg = Bytes2msg(buf);
            msg.CheckType(add);
            Assert.AreEqual(3, msg.Count);
            Assert.AreEqual(1000000000, msg[x]);
            Assert.AreEqual(2000000000, msg[y]);
            Assert.AreEqual(msgid, msg[_mf__messageId]);
        }
コード例 #9
0
        static MyValueFactoryCuae()
        {
            DefaultValueFactory.Init(types, class2type);

            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit.SetAsyncMode(AsyncMode.QUEUED);
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit.SetResult(_mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit);
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient_doit2.SetAsyncMode(AsyncMode.FREE);
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient_doit2.SetResult(_mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2);
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit3.SetResult(_mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit3);



            //	class2type.Add( typeof( etch.bindings.csharp.examples.cuae.ConstsCuae.Request ), _mt_etch_bindings_csharp_examples_cuae_Cuae_Request );
            //	_mt_etch_bindings_csharp_examples_cuae_Cuae_Request.SetClass( typeof( etch.bindings.csharp.examples.cuae.ConstsCuae.Request ) );
            _mt_etch_bindings_csharp_examples_cuae_Cuae_Request.SetImportExportHelper
            (
                new ImportExportHelper(

                    delegate(ValueFactory vf, Object value)
            {
                return((StructValue)value);
            },
                    delegate(StructValue sv)
            {
                return(sv);
            }
                    )
            );


            //	class2type.Add( typeof( etch.bindings.csharp.examples.cuae.ConstsCuae.Response ), _mt_etch_bindings_csharp_examples_cuae_Cuae_Response );
            //  _mt_etch_bindings_csharp_examples_cuae_Cuae_Response.SetClass( typeof( etch.bindings.csharp.examples.cuae.ConstsCuae.Response ) );
            _mt_etch_bindings_csharp_examples_cuae_Cuae_Response.SetImportExportHelper
            (
                new ImportExportHelper(
                    delegate(ValueFactory vf, Object value)
            {
                return((StructValue)value);
            },
                    delegate(StructValue sv)
            {
                return(sv);
            }
                    )
            );

            _mt_etch_bindings_csharp_examples_cuae_Cuae_ReqWithMessage.SetSuperType(_mt_etch_bindings_csharp_examples_cuae_Cuae_Request);

            _mt_etch_bindings_csharp_examples_cuae_Cuae_ReqWithMessage.SetImportExportHelper
            (
                new ImportExportHelper(
                    delegate(ValueFactory vf, Object value)
            {
                return((StructValue)value);
            },
                    delegate(StructValue sv)
            {
                return(sv);
            }
                    )
            );

            _mt_etch_bindings_csharp_examples_cuae_Cuae_RespWithCode.SetSuperType(_mt_etch_bindings_csharp_examples_cuae_Cuae_Response);
            _mt_etch_bindings_csharp_examples_cuae_Cuae_RespWithCode.SetImportExportHelper
            (
                new ImportExportHelper(
                    delegate(ValueFactory vf, Object value)
            {
                return((StructValue)value);
            },
                    delegate(StructValue sv)
            {
                return(sv);
            }
                    )
            );

            // initialize the extern serializers:

            // done updating types and fields, lock them.
            types.Lock();

            class2type.Lock();


            _mt_etch_bindings_csharp_examples_cuae_Cuae_Request.PutValidator(_mf_code, Validator_int.Get(0));

            _mt_etch_bindings_csharp_examples_cuae_Cuae_ReqWithMessage.PutValidator(_mf_code, Validator_int.Get(0));
            _mt_etch_bindings_csharp_examples_cuae_Cuae_ReqWithMessage.PutValidator(_mf_msg, Validator_string.Get(0));


            _mt_etch_bindings_csharp_examples_cuae_Cuae_Response.PutValidator(_mf_msg, Validator_string.Get(0));

            _mt_etch_bindings_csharp_examples_cuae_Cuae_RespWithCode.PutValidator(_mf_msg, Validator_string.Get(0));
            _mt_etch_bindings_csharp_examples_cuae_Cuae_RespWithCode.PutValidator(_mf_code, Validator_int.Get(0));



            // params for doit
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit.PutValidator(_mf_req, Validator_StructValue.Get(_mt_etch_bindings_csharp_examples_cuae_Cuae_Request, 0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit.PutValidator(_mf__messageId, Validator_long.Get(0));



            // params for _result_doit
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit.PutValidator(_mf_result, Validator_StructValue.Get(_mt_etch_bindings_csharp_examples_cuae_Cuae_Response, 0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit.PutValidator(_mf__messageId, Validator_long.Get(0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit.PutValidator(_mf_result, Validator_RuntimeException.Get());       // thrown RuntimeException
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit.PutValidator(_mf__inReplyTo, Validator_long.Get(0));



            // params for doit2
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient_doit2.PutValidator(_mf_req, Validator_StructValue.Get(_mt_etch_bindings_csharp_examples_cuae_Cuae_Request, 0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient_doit2.PutValidator(_mf__messageId, Validator_long.Get(0));



            // params for _result_doit2
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2.PutValidator(_mf_result, Validator_StructValue.Get(_mt_etch_bindings_csharp_examples_cuae_Cuae_Response, 0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2.PutValidator(_mf__messageId, Validator_long.Get(0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2.PutValidator(_mf_result, Validator_RuntimeException.Get());       // thrown RuntimeException
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2.PutValidator(_mf__inReplyTo, Validator_long.Get(0));

            // params for doit3
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit3.PutValidator(_mf_req, Validator_StructValue.Get(_mt_etch_bindings_csharp_examples_cuae_Cuae_Request, 1));
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit3.PutValidator(_mf__messageId, Validator_long.Get(0));



            // params for _result_doit3
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit3.PutValidator(_mf_result, Validator_StructValue.Get(_mt_etch_bindings_csharp_examples_cuae_Cuae_Response, 1));
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit3.PutValidator(_mf__messageId, Validator_long.Get(0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit3.PutValidator(_mf_result, Validator_RuntimeException.Get()); // thrown RuntimeException
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit3.PutValidator(_mf__inReplyTo, Validator_long.Get(0));

            _mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2.Timeout       = 500;
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2.ResponseField = _mf_result;
        } // end of static constructor