public ImmutableEnvelope(string envelopeId, DateTime createdUtc, object message, MessageAttribute[] attributes) { EnvelopeId = envelopeId; Message = message; CreatedUtc = createdUtc; if (null == attributes) { Attributes = MessageAttribute.Empty; } else { // just ensuring that we have an immutable copy var copy = new MessageAttribute[attributes.Length]; Array.Copy(attributes, copy, attributes.Length); Attributes = copy; } }
public MessageAttribute[] ReadAttributes(Stream stream) { using (var reader = new BitReader(stream)) { var attributeCount = reader.Read7BitInt(); if (attributeCount == 0) return Empty; var attributes = new MessageAttribute[attributeCount]; for (var i = 0; i < attributeCount; i++) { var key = reader.ReadString(); var value = reader.ReadString(); attributes[i] = new MessageAttribute(key, value); } return attributes; } }