TMessage IRpcDispatch.CallMethod <TMessage, TBuilder>(string method, IMessageLite request,
                                                       IBuilderLite <TMessage, TBuilder> response)
 {
     byte[] rawResponse = _wire.Execute(method, request.ToByteArray());
     response.MergeFrom(rawResponse);
     return(response.Build());
 }
Esempio n. 2
0
 public void ForceUDP(IBuilderLite retpb, byte flowId, byte errorCode)
 {
     if (udpAgent != null)
     {
         udpAgent.SendPacket(retpb);
     }
 }
Esempio n. 3
0
        public void SendPacket(IBuilderLite retpb)
        {
            if (udpClient == null)
            {
                return;
            }
            if (IsClose)
            {
                return;
            }

            //LogHelper.Log("UDP", "SendPacket: "+retpb.ToString());

            ServerBundle bundle;
            var          bytes = ServerBundle.sendImmediateError(retpb, 0, 0, out bundle);

            ServerBundle.ReturnBundle(bundle);

            var mb = new MsgBuffer()
            {
                position = 0, buffer = bytes, bundle = bundle, remoteEnd = remoteEnd
            };

            socketServer.SendUDPPacket(mb);
        }
        public void TestIBuilderLiteWeakBuildUninitialized()
        {
            IBuilderLite builder = TestRequiredLite.CreateBuilder();

            Assert.IsFalse(builder.IsInitialized);
            Assert.Throws <UninitializedMessageException>(() => builder.WeakBuild());
        }
Esempio n. 5
0
        public static void Merge(string text, ExtensionRegistry registry, IBuilderLite builder)
        {
            TextTokenizer   tokenizer = new TextTokenizer(text);
            TextInputStream ts        = TextInputStream.CreateInstance(tokenizer);

            builder.WeakMergeFrom(ts);
        }
        public void TestIBuilderLiteWeakBuildUninitialized()
        {
            IBuilderLite builder = TestRequiredLite.CreateBuilder();

            Assert.IsFalse(builder.IsInitialized);
            builder.WeakBuild();
        }
 /// <summary>
 /// Merges the input stream into the provided IBuilderLite
 /// </summary>
 protected override bool ReadMessage(IBuilderLite builder, ExtensionRegistry registry)
 {
     Assert(_input.IsStartElement());
     ReadMessageStart(_input.LocalName);
     builder.WeakMergeFrom(this, registry);
     ReadMessageEnd();
     return(true);
 }
Esempio n. 8
0
 public virtual TMessage CallMethod <TMessage, TBuilder>(string method, IMessageLite request,
                                                         IBuilderLite <TMessage, TBuilder> response)
     where TMessage : IMessageLite <TMessage, TBuilder>
     where TBuilder : IBuilderLite <TMessage, TBuilder>
 {
     CallService(method, request, response);
     return(response.Build());
 }
Esempio n. 9
0
 public void ReadGroupArray <T>(uint fieldTag, string fieldName, ICollection <T> list, T messageType, ExtensionRegistry registry) where T : IMessageLite
 {
     do
     {
         IBuilderLite builderLite = messageType.WeakCreateBuilderForType();
         this.ReadGroup(WireFormat.GetTagFieldNumber(fieldTag), builderLite, registry);
         list.Add((T)((object)builderLite.WeakBuildPartial()));
     }while (this.ContinueArray(fieldTag));
 }
Esempio n. 10
0
        public void TestIBuilderLiteWeakBuild()
        {
            IBuilderLite builder = TestRequiredLite.CreateBuilder()
                                   .SetD(0)
                                   .SetEn(ExtraEnum.EXLITE_BAZ);

            Assert.IsTrue(builder.IsInitialized);
            builder.WeakBuild();
        }
Esempio n. 11
0
 void ICodedInputStream.ReadGroup(int fieldNumber, IBuilderLite builder, ExtensionRegistry extensionRegistry)
 {
     if (_depth++ > MaxDepth)
     {
         throw new RecursionLimitExceededException();
     }
     ReadGroup(builder, extensionRegistry);
     _depth--;
 }
Esempio n. 12
0
 void ICodedInputStream.ReadMessage(IBuilderLite builder, ExtensionRegistry extensionRegistry)
 {
     if (_depth++ > MaxDepth)
     {
         throw new RecursionLimitExceededException();
     }
     ReadMessage(builder, extensionRegistry);
     _depth--;
 }
Esempio n. 13
0
        public static IMessageLite sendImmediate(IBuilderLite build)
        {
            var bundle = new Bundle();
            var data   = build.WeakBuild();

            bundle.newMessage(data.GetType());
            var fid = bundle.writePB(data);

            bundle.sendImm(KBEngine.KBEngineApp.app.networkInterface(), fid);
            return(data);
        }
Esempio n. 14
0
        public static byte[] GetPacket(IBuilderLite build)
        {
            var bundle = new Bundle();
            var data   = build.WeakBuild();

            Log.Net("GetPacket: " + data);
            bundle.newMessage(data.GetType());
            var fid = bundle.writePB(data);

            return(bundle.stream.getbuffer());
        }
Esempio n. 15
0
    public static SendPacketInfo GetPacketFull(IBuilderLite build, out Bundle b)
    {   //根据建的proto协议解析成二进制流,返回SendPacketInfo的结构体,该结构体包含而进制流和fidid
        var data = GetPacket(build, out b);
        var t    = new SendPacketInfo()
        {
            fid  = lastFid,
            data = data,
        };

        return(t);
    }
Esempio n. 16
0
 public void SendUDPPacket(IBuilderLite retpb, byte flowId, byte errorCode)
 {
     if (udpAgent != null && useUDP)
     {
         udpAgent.SendPacket(retpb);
     }
     else
     {
         SendPacket(retpb, flowId, errorCode);
     }
 }
Esempio n. 17
0
        /// <summary>
        /// Merges the input stream into the provided IBuilderLite
        /// </summary>
        protected override bool ReadMessage(IBuilderLite builder, ExtensionRegistry registry)
        {
            IDictionary <string, object> values = null;

            if (GetValue(ref values))
            {
                new DictionaryReader(values).Merge(builder, registry);
                return(true);
            }
            return(false);
        }
Esempio n. 18
0
        public static SendPacketInfo GetPacketFull(IBuilderLite build, out Bundle b)
        {
            var data = GetPacket(build, out b);
            var t    = new SendPacketInfo()
            {
                fid  = lastFid,
                data = data,
            };

            return(t);
        }
Esempio n. 19
0
 public void ReadUnknownGroup(int fieldNumber, IBuilderLite builder)
 {
     if (this.recursionDepth >= this.recursionLimit)
     {
         throw InvalidProtocolBufferException.RecursionLimitExceeded();
     }
     this.recursionDepth++;
     builder.WeakMergeFrom(this);
     this.CheckLastTagWas(WireFormat.MakeTag(fieldNumber, WireFormat.WireType.EndGroup));
     this.recursionDepth--;
 }
Esempio n. 20
0
        public void TestIBuilderLiteWeakBuildPartial()
        {
            IBuilderLite builder = TestRequiredLite.CreateBuilder();

            Assert.IsFalse(builder.IsInitialized);

            IMessageLite msg = builder.WeakBuildPartial();

            Assert.IsFalse(msg.IsInitialized);

            Assert.AreEqual(msg.ToByteArray(), TestRequiredLite.DefaultInstance.ToByteArray());
        }
Esempio n. 21
0
        public static byte[] MakePacket(IBuilderLite build, byte flowId)
        {
            var data = build.WeakBuild();

            var bundle = new ServerBundle();

            bundle.newMessage(data.GetType());
            bundle.flowId = flowId;
            bundle.writePB(data);

            return(bundle.stream.getbuffer());
        }
Esempio n. 22
0
        public static byte[] sendImmediateError(IBuilderLite build, byte flowId, byte errorCode)
        {
            var data = build.WeakBuild();

            var bundle = new ServerBundle();

            bundle.newMessage(data.GetType());
            bundle.flowId = flowId;
            bundle.writePB(data, errorCode);

            return(bundle.stream.getbuffer());
        }
Esempio n. 23
0
 /// <summary>
 /// Reads a group field value from the stream.
 /// </summary>
 public void ReadGroup(int fieldNumber, IBuilderLite builder,
                       ExtensionRegistry extensionRegistry)
 {
     if (recursionDepth >= recursionLimit)
     {
         throw InvalidProtocolBufferException.RecursionLimitExceeded();
     }
     ++recursionDepth;
     builder.WeakMergeFrom(this, extensionRegistry);
     CheckLastTagWas(WireFormat.MakeTag(fieldNumber, WireFormat.WireType.EndGroup));
     --recursionDepth;
 }
Esempio n. 24
0
 /// <summary>
 /// Reads an embedded message field value from the stream.
 /// </summary>
 public void ReadMessage(IBuilderLite builder, ExtensionRegistry extensionRegistry)
 {
     if (++recursionDepth >= recursionLimit)
     {
         throw InvalidProtocolBufferException.RecursionLimitExceeded();
     }
     tokenizer.TryConsume(":");
     tokenizer.TryConsume("{");
     builder.WeakMergeFrom(this, extensionRegistry);
     CheckLastTagWas("}");
     --recursionDepth;
 }
Esempio n. 25
0
        public void SendPacket(IBuilderLite retpb, uint flowId, int errorCode)
        {
            if (currentCon == null || currentCon.isClose)
            {
                return;
            }
            var bytes = ServerBundle.sendImmediateError(retpb, flowId, errorCode);

            Debug.Log("DemoServer: Send Packet " + flowId);
            lock (currentCon.msgBuffer) {
                currentCon.msgBuffer.Add(bytes);
            }
        }
Esempio n. 26
0
    public static byte[] GetPacket(IBuilderLite build, out Bundle b)
    {   //根据创建的proto协议解析成二进制流返回,并可附带传入包含二进制流的Bundle对象
        var bundle = GetBundle();

        b = bundle;
        var data = build.WeakBuild(); //通过WeakBuild接口,把IBuilderLite转化为2进制流的数据

        Debug.Log("GetPacket: " + data);
        bundle.newMessage(data.GetType()); //设置该Bundle的moduleId和msgid
        var fid = bundle.writePB(data);    //把数据写入bundle,包括协议头,数据长度,协议id,msgid,数据

        lastFid = fid;                     //Fidid可以用来表示该客户端写入的第几条消息
        return(bundle.stream.getbuffer()); //返回该二进制流
    }
Esempio n. 27
0
        protected override void Decode(IChannelHandlerContext context, IByteBuffer message, List <object> output)
        {
            Contract.Requires(context != null);
            Contract.Requires(message != null);
            Contract.Requires(output != null);

            int length = message.ReadableBytes;

            if (length <= 0)
            {
                return;
            }

            Stream inputStream = null;

            try
            {
                CodedInputStream codedInputStream;
                if (message.IoBufferCount == 1)
                {
                    ArraySegment <byte> bytes = message.GetIoBuffer(message.ReaderIndex, length);
                    codedInputStream = CodedInputStream.CreateInstance(bytes.Array, bytes.Offset, length);
                }
                else
                {
                    inputStream      = new ReadOnlyByteBufferStream(message, false);
                    codedInputStream = CodedInputStream.CreateInstance(inputStream);
                }

                IBuilderLite newBuilder     = this.protoType.WeakCreateBuilderForType();
                IBuilderLite messageBuilder = this.extensionRegistry == null
                    ? newBuilder.WeakMergeFrom(codedInputStream)
                    : newBuilder.WeakMergeFrom(codedInputStream, this.extensionRegistry);

                IMessageLite decodedMessage = messageBuilder.WeakBuild();
                if (decodedMessage != null)
                {
                    output.Add(decodedMessage);
                }
            }
            catch (Exception exception)
            {
                throw new CodecException(exception);
            }
            finally
            {
                inputStream?.Dispose();
            }
        }
Esempio n. 28
0
        /*
         *      public IEnumerator SendCoroutine(NetworkInterface networkInterface, uint fId, PacketHolder par) {
         *              fini (true);
         *              //Debug.Log ("message Number " + streamList.Count);
         *              bool resp = false;
         *              if(networkInterface.valid())
         *              {
         *      networkInterface.send(stream.getbuffer(), delegate(Packet p) {
         *          par.packet = p;
         *          resp = true;
         *      }, fId);
         *      Log.Sys("SendNetworkSuc");
         *              }
         *              else
         *              {
         *                      Dbg.ERROR_MSG("Bundle::send: networkInterface invalid!");
         *              }
         *
         *              //streamList.Clear();
         *              //stream = new MemoryStream();
         *          float passTime = 0;
         *              while (!resp && passTime < 5) {
         *                      yield return null;
         *                  passTime += Time.deltaTime;
         *              }
         *          if (!resp)
         *          {
         *              Debug.LogError("RequestTimeOut: "+fId+" con ");
         *          }
         *      }
         *
         * private void sendImm(NetworkInterface networkInterface, uint fId)
         * {
         *  fini(true);
         *  if (networkInterface.valid())
         *  {
         *      networkInterface.send(stream.getbuffer(), delegate(Packet p)
         *      {
         *      }, fId);
         *  }
         *  else
         *  {
         *      Dbg.ERROR_MSG("Bundle::send: networkInterface invalid!");
         *  }
         * }
         *
         * public static IEnumerator sendSimple(UnityEngine.MonoBehaviour mo, IBuilderLite build, PacketHolder par) {
         *
         *              var bundle = GetBundle();
         *              var data = build.WeakBuild();
         *
         *              bundle.newMessage (data.GetType ());
         *              var fid = bundle.writePB (data);
         *              Log.Net ("send Simple "+bundle+" d "+data+" fd "+fid);
         *              yield return mo.StartCoroutine(bundle.SendCoroutine(KBEngine.KBEngineApp.app.networkInterface(), fid, par));
         *      }
         */

        public static Packet GetPacketFid(IBuilderLite build)
        {
            var p = new Packet();

            var bundle = GetBundle();
            var data   = build.WeakBuild();

            Log.Net("GetPacket: " + data);
            bundle.newMessage(data.GetType());
            var fid  = bundle.writePB(data);
            var buff = bundle.stream.getbuffer();

            p.flowId = (byte)fid;
            p.data   = buff;
            return(p);
        }
Esempio n. 29
0
 public override bool ReadMessageArray <T>(string field, ICollection <T> items, IMessageLite messageType,
                                           ExtensionRegistry registry)
 {
     object[] array = null;
     if (GetValue(ref array))
     {
         foreach (IDictionary <string, object> item in array)
         {
             IBuilderLite builder = messageType.WeakCreateBuilderForType();
             new DictionaryReader(item).Merge(builder);
             items.Add((T)builder.WeakBuild());
         }
         return(true);
     }
     return(false);
 }
Esempio n. 30
0
        public void ReadMessage(IBuilderLite builder, ExtensionRegistry extensionRegistry)
        {
            int byteLimit = (int)this.ReadRawVarint32();

            if (this.recursionDepth >= this.recursionLimit)
            {
                throw InvalidProtocolBufferException.RecursionLimitExceeded();
            }
            int oldLimit = this.PushLimit(byteLimit);

            this.recursionDepth++;
            builder.WeakMergeFrom(this, extensionRegistry);
            this.CheckLastTagWas(0u);
            this.recursionDepth--;
            this.PopLimit(oldLimit);
        }
 public void ReadUnknownGroup(int fieldNumber, IBuilderLite builder)
 {
   if (recursionDepth >= recursionLimit) {
     throw InvalidProtocolBufferException.RecursionLimitExceeded();
   }
   ++recursionDepth;
   builder.WeakMergeFrom(this);
   CheckLastTagWas(WireFormat.MakeTag(fieldNumber, WireFormat.WireType.EndGroup));
   --recursionDepth;
 }
 /// <summary>
 /// Reads an embedded message field value from the stream.
 /// </summary>   
 public void ReadMessage(IBuilderLite builder, ExtensionRegistry extensionRegistry) {
   int length = (int) ReadRawVarint32();
   if (recursionDepth >= recursionLimit) {
     throw InvalidProtocolBufferException.RecursionLimitExceeded();
   }
   int oldLimit = PushLimit(length);
   ++recursionDepth;
   builder.WeakMergeFrom(this, extensionRegistry);
   CheckLastTagWas(0);
   --recursionDepth;
   PopLimit(oldLimit);
 }