예제 #1
0
        public static T FromMessagePackObject <T>(this MessagePackSerializer <T> source, MessagePackObject mpo)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            // This idea is borrowed from @TSnake41
            using (var buffer = new MemoryStream())
            {
                using (var packer = Packer.Create(buffer, PackerCompatibilityOptions.None, ownsStream: false))
                {
                    mpo.PackToMessage(packer, null);
                }

                buffer.Position = 0;

                return(source.Unpack(buffer));
            }
        }
예제 #2
0
 /// <summary>
 ///		Directly deserialize specified MessagePack <see cref="Stream"/> as <see cref="MessagePackObject"/> tree.
 /// </summary>
 /// <param name="stream">The stream which contains deserializing data.</param>
 /// <returns>A <see cref="MessagePackObject"/> which is root of the deserialized MessagePack object tree.</returns>
 /// <exception cref="ArgumentNullException">
 ///		<paramref name="stream"/> is <c>null</c>.
 /// </exception>
 /// <remarks>
 ///		This method is convinient wrapper for <see cref="MessagePackSerializer.Get{T}(SerializationContext)"/> for <see cref="MessagePackObject"/>.
 ///		<note>
 ///			You cannot override this method behavior because this method uses private <see cref="SerializationContext"/> instead of default context which is able to be accessed via <see cref="SerializationContext.Default"/>.
 ///		</note>
 /// </remarks>
 public static MessagePackObject UnpackMessagePackObject(Stream stream)
 {
     return(_singleTonMpoDeserializer.Unpack(stream));
 }