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()); }
public void ForceUDP(IBuilderLite retpb, byte flowId, byte errorCode) { if (udpAgent != null) { udpAgent.SendPacket(retpb); } }
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()); }
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); }
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()); }
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)); }
public void TestIBuilderLiteWeakBuild() { IBuilderLite builder = TestRequiredLite.CreateBuilder() .SetD(0) .SetEn(ExtraEnum.EXLITE_BAZ); Assert.IsTrue(builder.IsInitialized); builder.WeakBuild(); }
void ICodedInputStream.ReadGroup(int fieldNumber, IBuilderLite builder, ExtensionRegistry extensionRegistry) { if (_depth++ > MaxDepth) { throw new RecursionLimitExceededException(); } ReadGroup(builder, extensionRegistry); _depth--; }
void ICodedInputStream.ReadMessage(IBuilderLite builder, ExtensionRegistry extensionRegistry) { if (_depth++ > MaxDepth) { throw new RecursionLimitExceededException(); } ReadMessage(builder, extensionRegistry); _depth--; }
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); }
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()); }
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); }
public void SendUDPPacket(IBuilderLite retpb, byte flowId, byte errorCode) { if (udpAgent != null && useUDP) { udpAgent.SendPacket(retpb); } else { SendPacket(retpb, flowId, errorCode); } }
/// <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); }
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); }
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--; }
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()); }
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()); }
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()); }
/// <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; }
/// <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; }
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); } }
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()); //返回该二进制流 }
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(); } }
/* * 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); }
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); }
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); }