Exemple #1
0
        /// <summary>
        /// Generate "hexdump" output of the buffer at src like the following:
        /// <p><blockquote><pre>
        /// 00000: 04 d2 29 00 00 01 00 00 00 00 00 01 20 45 47 46  |..).........
        /// </summary>
        /// <remarks>
        /// Generate "hexdump" output of the buffer at src like the following:
        /// <p><blockquote><pre>
        /// 00000: 04 d2 29 00 00 01 00 00 00 00 00 01 20 45 47 46  |..)......... EGF|
        /// 00010: 43 45 46 45 45 43 41 43 41 43 41 43 41 43 41 43  |CEFEECACACACACAC|
        /// 00020: 41 43 41 43 41 43 41 43 41 43 41 41 44 00 00 20  |ACACACACACAAD.. |
        /// 00030: 00 01 c0 0c 00 20 00 01 00 00 00 00 00 06 20 00  |..... ........ .|
        /// 00040: ac 22 22 e1                                      |."".            |
        /// </blockquote></pre>
        /// </remarks>
        public static void ToHexdump(LogStream ps, byte[] src, int srcIndex, int length)
        {
            if (length == 0)
            {
                return;
            }
            int s = length % 16;
            int r = (s == 0) ? length / 16 : length / 16 + 1;

            char[] c = new char[r * (74 + NlLength)];
            char[] d = new char[16];
            int    i;
            int    si = 0;
            int    ci = 0;

            do
            {
                ToHexChars(si, c, ci, 5);
                ci     += 5;
                c[ci++] = ':';
                do
                {
                    if (si == length)
                    {
                        int n = 16 - s;
                        Array.Copy(SpaceChars, 0, c, ci, n * 3);
                        ci += n * 3;
                        Array.Copy(SpaceChars, 0, d, s, n);
                        break;
                    }
                    c[ci++] = ' ';
                    i       = src[srcIndex + si] & 0xFF;
                    ToHexChars(i, c, ci, 2);
                    ci += 2;
                    if (i < 0 || IsIsoControl((char)i))
                    {
                        d[si % 16] = '.';
                    }
                    else
                    {
                        d[si % 16] = (char)i;
                    }
                }while ((++si % 16) != 0);
                c[ci++] = ' ';
                c[ci++] = ' ';
                c[ci++] = '|';
                Array.Copy(d, 0, c, ci, 16);
                ci     += 16;
                c[ci++] = '|';
                //Sharpen.Runtime.GetCharsForString(NL, 0, NL_LENGTH, c, ci);

                //winrt
                //  NL.getChars( 0, NL_LENGTH, c, ci );void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
                var nlCharArray = Nl.ToCharArray(0, NlLength);
                for (int j = 0; j < NlLength; j++)
                {
                    c[ci++] = nlCharArray[j];
                }

                //c = Nl.ToCharArray(0, NlLength);
                //ci += NlLength;
            }while (si < length);
            ps.WriteLine(c);
        }