Exemplo n.º 1
0
        public void SendUdp(EndPoint endPoint, Socket socket, Buf buffer, ISerializer messageContents)
        {
            UInt32 messageContentLength = (messageContents == null) ? 0 : messageContents.SerializationLength();
            UInt32 totalMessageLength   = SerializationLength() + messageContentLength;

            buffer.EnsureCapacityCopyData(totalMessageLength); // Extra 4 bytes for the record header

            if (RpcPerformanceLog.rpcMessageSerializationLogger != null)
            {
                RpcPerformanceLog.StartSerialize();
            }
            UInt32 offset = Serialize(buffer.array, 0);

            if (messageContents != null)
            {
                offset = messageContents.Serialize(buffer.array, offset);
            }
            if (RpcPerformanceLog.rpcMessageSerializationLogger != null)
            {
                RpcPerformanceLog.StopSerializationAndLog("RpcSerializationTime");
            }

            if (offset != totalMessageLength)
            {
                throw new InvalidOperationException(String.Format("[CodeBug] The caclulated serialization length of RpcMessage '{0}' was {1} but actual size was {2}",
                                                                  DataStringBuilder.DataString(this, new StringBuilder()), totalMessageLength, offset));
            }

            socket.SendTo(buffer.array, 0, (Int32)totalMessageLength, SocketFlags.None, endPoint);
        }
Exemplo n.º 2
0
 public RpcMessage(Byte[] data, UInt32 offset, UInt32 offsetLimit, out UInt32 contentOffset)
     : base(memberSerializers)
 {
     if (RpcPerformanceLog.rpcMessageSerializationLogger != null)
     {
         RpcPerformanceLog.StartSerialize();
     }
     contentOffset = Deserialize(data, offset, offsetLimit);
     if (RpcPerformanceLog.rpcMessageSerializationLogger != null)
     {
         RpcPerformanceLog.StopSerializationAndLog("RpcDeserializationTime");
     }
 }
Exemplo n.º 3
0
        public RpcMessage(Socket socket, Buf buffer, out UInt32 contentOffset, out UInt32 contentOffsetLimit)
            : base(memberSerializers)
        {
            //
            // TODO: catch socket exception to prevent server from failing
            //

            buffer.EnsureCapacityCopyData(12);
            socket.ReadFullSize(buffer.array, 0, 4); // read the size
            Int32 rpcMessageSize = (
                (0x7F000000 & (buffer.array[0] << 24)) |
                (0x00FF0000 & (buffer.array[1] << 16)) |
                (0x0000FF00 & (buffer.array[2] << 8)) |
                (0x000000FF & (buffer.array[3])));

            if ((buffer.array[0] & 0x80) != 0x80)
            {
                throw new NotImplementedException(String.Format("Records with multiple fragments it not currently implemented"));
            }

            buffer.EnsureCapacityCopyData(rpcMessageSize);
            socket.ReadFullSize(buffer.array, 0, rpcMessageSize);

            //
            // Deserialize
            //
            contentOffsetLimit = (UInt32)rpcMessageSize;

            if (RpcPerformanceLog.rpcMessageSerializationLogger != null)
            {
                RpcPerformanceLog.StartSerialize();
            }
            contentOffset = Deserialize(buffer.array, 0, (UInt32)rpcMessageSize);
            if (RpcPerformanceLog.rpcMessageSerializationLogger != null)
            {
                RpcPerformanceLog.StopSerializationAndLog("RpcDeserializationTime");
            }
        }