예제 #1
0
        public IppAttribute ReadAttribute(Tag tag, BinaryReader stream, IppAttribute?prevAttribute)
        {
            var len            = stream.ReadInt16BigEndian();
            var name           = Encoding.ASCII.GetString(stream.ReadBytes(len));
            var value          = ReadValue(stream, tag);
            var normalizedName = string.IsNullOrEmpty(name) && prevAttribute != null ? prevAttribute.Name : name;

            if (string.IsNullOrEmpty(normalizedName))
            {
                throw new ArgumentException("0 length attribute name found not in a 1setOf");
            }

            var attribute = new IppAttribute(tag, normalizedName, value);

            return(attribute);
        }
예제 #2
0
        public void Write(BinaryWriter stream, IppAttribute attribute, bool isSet)
        {
            stream.Write((byte)attribute.Tag);
            if (isSet)
            {
                stream.WriteBigEndian((short)0);
            }
            else
            {
                stream.WriteBigEndian((short)attribute.Name.Length);
                stream.Write(Encoding.ASCII.GetBytes(attribute.Name));
            }

            var value = attribute.Value;

            WriteValue(value, stream);
        }