示例#1
0
 /// <summary>
 ///     Encode TLV object.
 /// </summary>
 /// <returns>TLV object as bytes</returns>
 public byte[] Encode()
 {
     using (TlvWriter writer = new TlvWriter(new MemoryStream()))
     {
         writer.WriteTag(this);
         return(((MemoryStream)writer.BaseStream).ToArray());
     }
 }
示例#2
0
        /// <summary>
        ///     Encode child TLV list to byte array.
        /// </summary>
        /// <returns>TLV list elements as byte array</returns>
        public override byte[] EncodeValue()
        {
            using (TlvWriter writer = new TlvWriter(new MemoryStream()))
            {
                foreach (ITlvTag tag in _childTags)
                {
                    writer.WriteTag(tag);
                }

                return(((MemoryStream)writer.BaseStream).ToArray());
            }
        }
示例#3
0
        /// <summary>
        /// Build new TLV tag as RawTag.
        /// </summary>
        /// <returns></returns>
        public RawTag BuildTag()
        {
            using (TlvWriter writer = new TlvWriter(new MemoryStream()))
            {
                foreach (ITlvTag tag in _childTags)
                {
                    writer.WriteTag(tag);
                }

                return(new RawTag(_type, _nonCritical, _forward, ((MemoryStream)writer.BaseStream).ToArray()));
            }
        }
示例#4
0
        /// <summary>
        ///     Write TlvTag to stream.
        /// </summary>
        /// <param name="outputStream">output stream</param>
        public void WriteTo(Stream outputStream)
        {
            if (outputStream == null)
            {
                throw new ArgumentNullException(nameof(outputStream));
            }

            if (!outputStream.CanWrite)
            {
                throw new KsiException("Output stream is not writable.");
            }

            // Cannot use "using", otherwise outputStream will be closed
            TlvWriter writer = new TlvWriter(outputStream);

            writer.WriteTag(this);
        }