Example #1
0
        public void SendUdp(EndPoint endPoint, Socket socket, ref Byte[] buffer, ISerializer messageContents)
        {
            UInt32 messageContentLength = (messageContents == null) ? 0 : messageContents.SerializationLength();
            UInt32 totalMessageLength   = SerializationLength() + messageContentLength;

            ArrayExt.EnsureCapacityNoCopy(ref buffer, totalMessageLength);

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

            if (messageContents != null)
            {
                offset = messageContents.Serialize(buffer, 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, 0, (Int32)totalMessageLength, SocketFlags.None, endPoint);
        }