Пример #1
0
        public BinaryEnvelope Serialize(Envelope envelope)
        {
            var binaryEnvelope = new BinaryEnvelope();
            var memory         = new MemoryStream();

            _serializer.Model.SerializeWithLengthPrefix(memory, envelope.Header, typeof(EnvelopeHeader), PrefixStyle.Base128, 0);
            binaryEnvelope.Header = memory.ToArray();

            foreach (var item in envelope.Items)
            {
                var binaryMessageEnvelope = WriteMessageEnvelope(item);
                binaryEnvelope.AddBinaryMessageEnvelope(binaryMessageEnvelope);
            }

            return(binaryEnvelope);
        }
Пример #2
0
        public Envelope Deserialize(BinaryEnvelope binaryEnvelope)
        {
            var envelope = new Envelope();


            using (var memory = new MemoryStream(binaryEnvelope.Header))
            {
                envelope.Header = (EnvelopeHeader)_serializer.Model.DeserializeWithLengthPrefix(memory, null, typeof(EnvelopeHeader), PrefixStyle.Base128, 0, null);
            }

            foreach (var binaryMessageEnvelope in binaryEnvelope.MessageEnvelopes)
            {
                var item = ReadMessageEnvelope(binaryMessageEnvelope);
                envelope.AddItem(item);
            }

            return(envelope);
        }