Exemple #1
0
 /// <summary>
 /// Render some memory, reading from the provided <see cref="ImageReader"/>, into
 /// a suitable output device <paramref name="output" />.
 /// </summary>
 /// <param name="rdr">Imagereader to read the data from.</param>
 /// <param name="enc">Text encoding used to render textual data.</param>
 /// <param name="output">Output device to which the rendered strings
 /// are emitted.</param>
 public void RenderMemory(EndianImageReader rdr, Encoding enc, IMemoryFormatterOutput output)
 {
     while (RenderLine(rdr, enc, output))
     {
         ;
     }
 }
Exemple #2
0
        /// <summary>
        /// Render some memory, reading from the provided <see cref="ImageReader"/>, into
        /// a suitable output device <paramref name="output" />. This method
        /// takes into account that the image reader may not be positioned at
        /// the beginning of a logical line; in that case it will render
        /// filler space to ensure the display lines up.
        /// </summary>
        /// <param name="rdr">Imagereader to read the data from.</param>
        /// <param name="enc">Text encoding used to render textual data.</param>
        /// <param name="output">Output device to which the rendered strings
        /// are emitted.</param>
        public bool RenderLine(EndianImageReader rdr, Encoding enc, IMemoryFormatterOutput output)
        {
            output.BeginLine();
            var offStart = rdr.Offset;
            var addr     = rdr.Address;

            output.RenderAddress(addr);

            var addrStart       = Align(addr, unitsPerLine);
            var prePaddingUnits = (int)(addr - addrStart);
            var offsetEndLine   = (rdr.Offset - prePaddingUnits) + unitsPerLine;

            output.RenderFillerSpan(PaddingCells(prePaddingUnits));

            bool moreData         = true;
            int  postPaddingUnits = 0;

            while (moreData && rdr.Offset < offsetEndLine)
            {
                addr     = rdr.Address;
                moreData = rdr.TryRead(dtUnit, out var c);
                if (moreData)
                {
                    output.RenderUnit(addr, string.Format(unitFormat, c.GetValue()));
                }
                else
                {
                    postPaddingUnits = (int)(offsetEndLine - rdr.Offset);
                }
            }

            output.RenderFillerSpan(PaddingCells(postPaddingUnits));

            var cb = rdr.Offset - offStart;

            rdr.Offset = offStart;
            var bytes = rdr.ReadBytes((int)cb);

            string sBytes = RenderAsText(enc, bytes);

            output.RenderUnitsAsText(prePaddingUnits * this.bytesPerUnit, sBytes, postPaddingUnits * this.bytesPerUnit);

            output.EndLine(bytes);

            return(moreData && rdr.IsValid);
        }