Esempio n. 1
0
    public static ByteBuf NewPacket(pb.ID id, Google.ProtocolBuffers.IMessage msg = null)
    {
        var bufLen = BitConverter.GetBytes((ushort)0);


        var t = new List <byte>();

        byte[] buffData = null;
        if (null != msg)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                //Save the person to a stream
                msg.WriteTo(stream);
                buffData = stream.ToArray();

                bufLen = BitConverter.GetBytes((ushort)buffData.Length);
            }
        }

        if (BitConverter.IsLittleEndian)
        {
            Array.Reverse(bufLen);
        }
        t.AddRange(bufLen);
        t.Add((byte)id);
        if (null != buffData)
        {
            t.AddRange(buffData);
        }

        return(new ByteBuf(t.ToArray()));
    }
        public void IsStarChefEvent_should_return_false_for_null()
        {
            IMessage nullMessage = null;
            var      actual      = nullMessage.IsStarChefEvent();

            Assert.False(actual);
        }
Esempio n. 3
0
 // BEGIN INSERTED CODE
 public virtual void CallMethod(
     Google.ProtocolBuffers.Descriptors.MethodDescriptor method,
     Google.ProtocolBuffers.IRpcController controller,
     Google.ProtocolBuffers.IMessage request,
     Google.ProtocolBuffers.IMessage responsePrototype,
     Action <Google.ProtocolBuffers.IMessage> done)
 {
     RcfProtoChannelImpl.CallMethod(this, method, controller, request, responsePrototype, done);
 }
Esempio n. 4
0
 public void Send(pb.ID id, Google.ProtocolBuffers.IMessage obj = null)
 {
     if (null != client && client.IsRunning() && Connected)
     {
         client.Send(PacketWraper.NewPacket(id, obj));
     }
     else
     {
         UnityEngine.Debug.LogError("client no connect");
     }
 }
Esempio n. 5
0
        private void WriteUnknownFields(uint type, Google.ProtocolBuffers.IMessage payload)
        {
            var u = payload.UnknownFields.FieldDictionary;

            if (u != null)
            {
                foreach (var kvp in u)
                {
                    Console.WriteLine($"[UNKNOWN FIELD] Message type: {type}, Key: {kvp.Key}");
                }
            }
        }
Esempio n. 6
0
 public Google.ProtocolBuffers.IMessage HandleBuf(PACKET_TYPE packet_type, byte[] packet_buf)
 {
     Google.ProtocolBuffers.IMessage message = null;
     if (m_handlers.ContainsKey(packet_type) == true)
     {
         m_handlers[packet_type](packet_buf);
     }
     else
     {
         // Console.WriteLine("Invalid packet_type({0})", packet_type);
     }
     return(message);
 }
Esempio n. 7
0
 protected override void doRecv()
 {
     try
     {
         while (recverRunnable)
         {
             int length = 0;
             try
             {
                 length = socket.recv(recvBuffer, 0, 4);
                 Utils.swap(recvBuffer, 4);
                 int len = BitConverter.ToInt32(recvBuffer, 0);
                 length = socket.recv(recvBuffer, 0, len);
                 Utils.swap(recvBuffer, 4);
                 uint  id  = BitConverter.ToUInt32(recvBuffer, 0);
                 PBMsg msg = codecMgr.decode(id, recvBuffer, 4, length - 4);
                 if (msg != null)
                 {
                     PBNetMessage t = msgPool.rent();
                     t.setMessage(msg);
                     t.setID(id);
                     lock (recvQueue)
                     {
                         recvQueue.Enqueue(t);
                         Log.Logger.debug(Log.Module.Network, "enqueue recv:" + id);
                     }
                 }
                 else
                 {
                     Log.Logger.debug(Log.Module.Network, "recv unrecoginized message with id:" + id);
                 }
             }
             catch (SocketException e1)
             {
                 doDisconnect();
                 Log.Logger.exception(Log.Module.Network, e1.StackTrace);
             }
             catch (EndOfStreamException e2)
             {
                 Log.Logger.exception(Log.Module.Network, e2.StackTrace);
             }
         }
         Log.Logger.info(Log.Module.Network, "doRecv exit");
     }
     catch (Exception e3)
     {
         Log.Logger.warn(Log.Module.Network, "doRecv exit, encounter exception:" + e3.ToString());
         doDisconnect();
     }
 }
Esempio n. 8
0
        public void SendProtobuf(Google.ProtocolBuffers.IMessage message, PACKET_TYPE packet_type)
        {
            if (m_socket == null || m_socket.Connected == false)
            {
                Disconnect();
                return;
            }
            byte[] type_bytes = BitConverter.GetBytes((int)packet_type);

            byte[] packet_buffer = message.ToByteArray();
            int    size          = packet_buffer.Length;

            byte[] size_bytes = BitConverter.GetBytes(size);

            int buf_size = packet_buffer.Length + size_bytes.Length + type_bytes.Length;

            byte[] send_buf = new byte[buf_size];
            System.Buffer.BlockCopy(size_bytes, 0, send_buf, 0, size_bytes.Length);
            System.Buffer.BlockCopy(type_bytes, 0, send_buf, size_bytes.Length, type_bytes.Length);
            System.Buffer.BlockCopy(packet_buffer, 0, send_buf, size_bytes.Length + type_bytes.Length, packet_buffer.Length);
            m_socket.Send(send_buf);
            // Console.WriteLine("Send len({0}) = header({1} + {2}) + body({3})", buf_size, size_bytes.Length, type_bytes.Length, packet_buffer.Length);
        }
Esempio n. 9
0
 public void LogOutgoing(Google.ProtocolBuffers.IMessage msg, bnet.protocol.Header header)
 {
     Log(Level.Dump, ShortHeader(header) + "[O] " + msg.AsText(), null);
 }
Esempio n. 10
0
 /// <summary>
 /// Logs an incoming moonet (protocol-buffer) packet.
 /// </summary>
 /// <param name="message">Outgoing protocol-buffer packet.</param>
 /// <param name="header"><see cref="bnet.protocol.Header"/> header</param>
 public void LogOutgoingPacket(Google.ProtocolBuffers.IMessage message, bnet.protocol.Header header)
 {
     Log(Level.PacketDump, ShortHeader(header) + "[O] " + message.AsText(), null);
 }
Esempio n. 11
0
 public void LogOutgoing(Google.ProtocolBuffers.IMessage msg)
 {
     Log(Level.Dump, "[O] " + msg.AsText(), null);
 }
        public void IsStarChefEvent_should_return_false_for_nonStarChef(IMessage message)
        {
            var actual = message.IsStarChefEvent();

            Assert.False(actual);
        }
        public void IsStarChefEvent_should_return_true_for_StarChef(IMessage message)
        {
            var actual = message.IsStarChefEvent();

            Assert.True(actual);
        }
Esempio n. 14
0
 public void LogIncoming(Google.ProtocolBuffers.IMessage msg)
 {
     Log(Level.Incoming, msg.AsText(), null);
 }