Example #1
0
        /// <summary>
        /// Serializes the specified message.
        /// </summary>
        /// <param name="system">The system.</param>
        /// <param name="address"></param>
        /// <param name="message">The message.</param>
        /// <returns>SerializedMessage.</returns>
        public static SerializedMessage Serialize(ActorSystem system, Address address, object message)
        {
            Serializer serializer = system.Serialization.FindSerializerFor(message);

            SerializedMessage.Builder messageBuilder = new SerializedMessage.Builder()
                                                       .SetMessage(ByteString.Unsafe.FromBytes(serializer.ToBinaryWithAddress(address, message)))
                                                       .SetSerializerId(serializer.Identifier);

            var serializer2 = serializer as SerializerWithStringManifest;

            if (serializer2 != null)
            {
                var manifest = serializer2.Manifest(message);
                if (!string.IsNullOrEmpty(manifest))
                {
                    messageBuilder.SetMessageManifest(ByteString.CopyFromUtf8(manifest));
                }
            }
            else
            {
                if (serializer.IncludeManifest)
                {
                    messageBuilder.SetMessageManifest(ByteString.CopyFromUtf8(message.GetType().AssemblyQualifiedName));
                }
            }

            return(messageBuilder.Build());
        }
Example #2
0
        /// <summary>
        /// Serializes the specified message.
        /// </summary>
        /// <param name="system">The system.</param>
        /// <param name="address"></param>
        /// <param name="message">The message.</param>
        /// <returns>SerializedMessage.</returns>
        public static SerializedMessage Serialize(ActorSystem system, Address address, object message)
        {
            Serializer serializer = system.Serialization.FindSerializerFor(message);

            SerializedMessage.Builder messageBuilder = new SerializedMessage.Builder()
                .SetMessage(ByteString.Unsafe.FromBytes(serializer.ToBinaryWithAddress(address, message)))
                .SetSerializerId(serializer.Identifier);

            var serializer2 = serializer as SerializerWithStringManifest;
            if (serializer2 != null)
            {
                var manifest = serializer2.Manifest(message);
                if (!string.IsNullOrEmpty(manifest))
                {
                    messageBuilder.SetMessageManifest(ByteString.CopyFromUtf8(manifest));
                }
            }
            else
            {
                if (serializer.IncludeManifest)
                    messageBuilder.SetMessageManifest(ByteString.CopyFromUtf8(message.GetType().AssemblyQualifiedName));
            }

            return messageBuilder.Build();
        }
        /// <summary>
        /// Serializes the specified message.
        /// </summary>
        /// <param name="system">The system.</param>
        /// <param name="message">The message.</param>
        /// <returns>SerializedMessage.</returns>
        public static SerializedMessage Serialize(ActorSystem system, object message)
        {
            Serializer serializer = system.Serialization.FindSerializerFor(message);
            byte[] messageBytes = serializer.ToBinary(message);
            SerializedMessage.Builder messageBuilder = new SerializedMessage.Builder()
                .SetSerializerId(serializer.Identifier);
            if (serializer.IncludeManifest)
                messageBuilder.SetMessageManifest(ByteString.CopyFromUtf8(message.GetType().AssemblyQualifiedName));
            messageBuilder.SetMessage(ByteString.Unsafe.FromBytes(messageBytes));

            return messageBuilder.Build();
        }
Example #4
0
        /// <summary>
        /// Serializes the specified message.
        /// </summary>
        /// <param name="system">The system.</param>
        /// <param name="message">The message.</param>
        /// <returns>SerializedMessage.</returns>
        public static SerializedMessage Serialize(ActorSystem system, object message)
        {
            Serializer serializer = system.Serialization.FindSerializerFor(message);

            byte[] messageBytes = serializer.ToBinary(message);
            SerializedMessage.Builder messageBuilder = new SerializedMessage.Builder()
                                                       .SetSerializerId(serializer.Identifier);
            if (serializer.IncludeManifest)
            {
                messageBuilder.SetMessageManifest(ByteString.CopyFromUtf8(message.GetType().AssemblyQualifiedName));
            }
            messageBuilder.SetMessage(ByteString.Unsafe.FromBytes(messageBytes));

            return(messageBuilder.Build());
        }