private void ReadSection(BinaryReader reader, IppResponseMessage res) { IppAttribute? prevAttribute = null; List <IppAttribute>?attributes = null; do { var data = reader.ReadByte(); var sectionTag = (SectionTag)data; switch (sectionTag) { //https://tools.ietf.org/html/rfc8010#section-3.5.1 case SectionTag.EndOfAttributesTag: return; case SectionTag.Reserved: case SectionTag.OperationAttributesTag: case SectionTag.JobAttributesTag: case SectionTag.PrinterAttributesTag: case SectionTag.UnsupportedAttributesTag: var section = new IppSection { Tag = sectionTag }; res.Sections.Add(section); attributes = section.Attributes; break; default: var attribute = ReadAttribute((Tag)data, reader, prevAttribute); prevAttribute = attribute; if (attributes == null) { throw new ArgumentException( $"Section start tag not found in stream. Expected < 0x06. Actual: {data}"); } attributes.Add(attribute); break; } } while (true); }
public static IDictionary <string, IppAttribute[]> AllAttributes(this IppSection ippSection) => ippSection.Attributes.GroupBy(x => x.Name).ToDictionary(g => g.Key, g => g.ToArray());