当前位置: 首页>>代码示例>>C#>>正文


C# Message.Get方法代码示例

本文整理汇总了C#中Message.Get方法的典型用法代码示例。如果您正苦于以下问题:C# Message.Get方法的具体用法?C# Message.Get怎么用?C# Message.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Message的用法示例。


在下文中一共展示了Message.Get方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            //
            // TODO: Add code to start application here
            //
            Message m = new Message();
            DumpMessage(m);
            m.Set("t", "abc");
            DumpMessage(m);

            String v = "a";
            if (m.Get("t", ref v))
            {
                Console.WriteLine("succeeded: {0}", v);
            }
            else
            {
                Console.WriteLine("Get failed");
            }
        }
开发者ID:kragen,项目名称:mod_pubsub,代码行数:20,代码来源:Class1.cs

示例2: testGet

        public void testGet()
        {
            TestUtil.INIT_TESTCASE("testGet");

            Message m1 = new Message();
            m1.Set("field1", "Value1");
            m1.Set("field2", "Value2");
            m1.Set("field3", "Value3");
            m1.Set("field4", "Value4");
            TestUtil.dumpMsg("Msg: m1", m1);

            string str1 = "";
            bool result;
            result = m1.Get("field1", ref str1);
            TestUtil.dump("str1=" + str1);

            Assertion.Assert("result", result);
            Assertion.Assert("str1.Equals(\"Value1\")", str1.Equals("Value1"));
            Assertion.Assert("!str1.Equals(\"Value1\")", !str1.Equals("Value2"));

            result = m1.Get("field5", ref str1);
            Assertion.Assert("!result", !result);
        }
开发者ID:kragen,项目名称:mod_pubsub,代码行数:23,代码来源:messageTS.cs

示例3: testSerialization

        public void testSerialization()
        {
            TestUtil.INIT_TESTCASE("testSerialization");

            Message m1 = new Message();
            m1.Set("field1", "Value1");
            m1.Set("field2", "Value2  ");
            m1.Set("field3", "  Value3");
            m1.Set("field4", "  Value4  ");
            TestUtil.dumpMsg("Msg: m1", m1);

            string str1 = m1.GetAsSimpleFormat();
            TestUtil.dump("str1=" + str1);

            Message m2 = new Message();
            bool result = m2.InitFromSimple(str1);
            Assertion.Assert("result", result);
            TestUtil.dumpMsg("Msg: m2", m2);

            string val1 = "";
            string val2 = "";
            string val3 = "";
            string val4 = "";
            string val5 = "";
            result = m2.Get("field1", ref val1);
            Assertion.Assert("result", result);
            result = m2.Get("field2", ref val2);
            Assertion.Assert("result", result);
            result = m2.Get("field3", ref val3);
            Assertion.Assert("result", result);
            result = m2.Get("field4", ref val4);
            Assertion.Assert("result", result);
            result = m2.Get("field5", ref val5);
            Assertion.Assert("!result", !result);

            Assertion.Assert("val1 = Value1", val1 == "Value1");
            Assertion.Assert("val2 = Value2", val2 == "Value2  ");
            Assertion.Assert("val3 = Value3", val3 == "  Value3");
            Assertion.Assert("val4 = Value4", val4 == "  Value4  ");

            Assertion.Assert("m2.IsEqual(m1)", m2.IsEqual(m1));
        }
开发者ID:kragen,项目名称:mod_pubsub,代码行数:42,代码来源:messageTS.cs

示例4: AsMessage

        protected void AsMessage(Message msg, MessageDescriptor ci)
        {
            if (ci.HasOptions)
            {
                AsMessageEx(msg, ci);
                return;
            }

            // should be ready to pick up value if parsing into Json data node special class.
            if (_tlast != JsToken.ObjectStart)
                Expected("object start");

            // parse JSON object into message fields.
            var comma = false;
            FieldDescriptor kvfs = null;
            while (true)
            {
                if ((_tlast = Next()) == JsToken.ObjectEnd)
                {
                    if (kvfs == null) break;
                    kvfs = null; continue;
                }
                if (!comma) comma = true;
                else
                    if (_tlast != JsToken.Comma) Expected("comma");
                    else _tlast = Next();
                if (_tlast != JsToken.String) Expected("name");
                _last_name = _sdata;
                if (Next() != JsToken.Semicolon) Expected(":");
                if (GetValue() == JsToken.Null) continue;

                // when parsing JSON object into map, populate next entry.
                if (kvfs != null)
                {
                    msg.Get(kvfs, this);
                    continue;
                }

                // find message field descriptor by name.
                var fs = ci.Find(_last_name);
                if (fs == null) continue;
                if (_tlast != JsToken.ArrayStart)
                    // save field desc for extracting kv-map values.
                    if (fs.DataType != WireType.MapEntry)
                        msg.Get(fs, this);
                    else if (_tlast == JsToken.ObjectStart)
                        { kvfs = fs; comma = false; }
                    else Expected("object start");
                else AsArray(msg, fs);
            }
        }
开发者ID:Dataflow-Software,项目名称:Dataflow.NET,代码行数:51,代码来源:Jsons.cs

示例5: AsMessageEx

 protected void AsMessageEx(Message msg, MessageDescriptor ci)
 {
     if (ci.IsGoogleType)
     {
         var type = msg.GetType();
         if (type == typeof(Struct))
             AsStructJs(msg as Struct);
         else if (type == typeof(Value))
             AsValueJs(msg as Value);
         else { }
     }
     else if (ci.IsKvMap)
     {
         var kmap = msg as MapEntry;
         var fs = ci.Fields;
         // set map entry key and value.
         if (fs[0].DataType == WireType.String) kmap.skey = _last_name;
         else { long lk = 0; if (long.TryParse(_last_name, out lk)) kmap.lkey = lk; else Expected("ordinal key value"); }
         var fi = fs[1];
         kmap.Get(fs[1], this);
     }
     else if (ci.IsBoxType)
     {
         if (!ci.IsListType) msg.Get(null, this);
         else AsArray(msg, null);
     }
 }
开发者ID:Dataflow-Software,项目名称:Dataflow.NET,代码行数:27,代码来源:Jsons.cs

示例6: AsArray

 public void AsArray(Message msg, FieldDescriptor pos)
 {
     for (GetValue(); _tlast != JsToken.ArrayEnd; )
     {
         if (_tlast != JsToken.Null)
             msg.Get(pos, this);
         if ((_tlast = Next()) == JsToken.Comma)
             GetValue();
         else if (_tlast != JsToken.ArrayEnd && (int)_tlast < (int)JsToken.ObjectStart)
             Expected("value");
     }
 }
开发者ID:Dataflow-Software,项目名称:Dataflow.NET,代码行数:12,代码来源:Jsons.cs

示例7: GetMessage

 private void GetMessage(Message msg, MessageDescriptor ci)
 {
     // enter next message parsing level.
     var prev = PushLimit();
     while (_storage.Limit > 0)
     {
         // read next PB value from the stream.
         var id = _storage.GetIntPB();
         switch (_wirefmt = id & 0x7)
         {
             case Pbs.iVarInt: _data = _storage.GetLongPB(); break;
             case Pbs.iBit64: _data = _storage.GetB64(); break;
             case Pbs.iString:
                 _fsz = _storage.GetIntPB();
                 if (_fsz <= _storage.Limit)
                     break;
                 throw new ProtoBufException("nested blob size");
             case Pbs.iBit32: _data = _storage.GetB32(); break;
             default: throw new ProtoBufException("unsupported wire format");
         }
         // match PB field descriptor by id.
         var fi = ci.Find(id);
         if (fi != null)
             if(fi.Id == id)
                 msg.Get(fi, this);
             else TryReadPacked(fi, msg);
         else
             if (_fsz > 0) { _storage.Skip(_fsz); _fsz = 0; }
     }
     // exit message segment parsing.
     if (_storage.Limit < 0)
         throw new ProtoBufException("message size out of sync");
     _level--;
     PopLimit(prev);
 }
开发者ID:Dataflow-Software,项目名称:Dataflow.NET,代码行数:35,代码来源:Pbufs.cs

示例8: TryReadPacked

        public void TryReadPacked(FieldDescriptor fs, Message msg)
        {
            // since 2.3 PB deserializers are supposed to read both packed and unpacked.
            var wireFmt = fs.Id & 0x7;
            if (_wirefmt == Pbs.iString)
                _wirefmt = wireFmt;
            else FormatError(wireFmt);

            var prev = PushLimit();
            while (_storage.Limit > 0)
            {
                switch (_wirefmt)
                {
                    case Pbs.iVarInt: _data = _storage.GetLongPB(); break;
                    case Pbs.iBit64: _data = _storage.GetB64(); break;
                    case Pbs.iBit32: _data = _storage.GetB32(); break;
                    default: throw new ProtoBufException("packed: type");
                }
                msg.Get(fs, this);
            }
            PopLimit(prev);
        }
开发者ID:Dataflow-Software,项目名称:Dataflow.NET,代码行数:22,代码来源:Pbufs.cs


注:本文中的Message.Get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。