IEnumerable <byte> EncodeCapabilities(IEnumerable <Tlv> capabilities) { var outStream = new MemoryStream(); var parser = new TlvParser(1, 1); capabilities.ToList().ForEach(tlv => parser.Encode(outStream, tlv)); var encodedCapabilities = outStream.GetBuffer().Take(Convert.ToInt32(outStream.Position)).ToArray(); return(EncodeNumber(Convert.ToUInt32(encodedCapabilities.Length), 1).Concat(encodedCapabilities)); }
IEnumerable <Tlv> ParseCapabilities(Stream dataStream) { var capabilitiesLength = ReadNumber(dataStream, 1); var capabilities = new List <Tlv>(); var parser = new TlvParser(1, 1); while (dataStream.Position < dataStream.Length) { capabilities.Add(parser.Decode(dataStream)); } return(capabilities); }