Esempio n. 1
0
        public static ArraySegment <byte> ToChatTopicBlock(ChatTopic message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            ArraySegment <byte> value;

            using (Stream messageStream = message.Export(_bufferManager))
                using (Stream compressStream = ContentConverter.Compress(messageStream))
                    using (Stream typeStream = ContentConverter.AddType(compressStream, "ChatTopic"))
                    {
                        value = new ArraySegment <byte>(_bufferManager.TakeBuffer((int)typeStream.Length), 0, (int)typeStream.Length);
                        typeStream.Read(value.Array, value.Offset, value.Count);
                    }

            return(value);
        }
Esempio n. 2
0
        public static ChatTopic FromChatTopicBlock(ArraySegment <byte> message)
        {
            if (message.Array == null)
            {
                throw new ArgumentNullException("message.Array");
            }

            try
            {
                using (Stream typeStream = new MemoryStream(message.Array, message.Offset, message.Count))
                    using (Stream compressStream = ContentConverter.RemoveType(typeStream, "ChatTopic"))
                        using (Stream messageStream = ContentConverter.Decompress(compressStream))
                        {
                            return(ChatTopic.Import(messageStream, _bufferManager));
                        }
            }
            catch (Exception)
            {
                return(null);
            }
        }