Esempio n. 1
0
void ZASParser::ParseHandler_Prettify::ParsedBinary(const ZStreamR& iStream)
{
    if (fDumpBinaries)
    {
        if (fInBlock)
            spWriteIndent(fStrimW, fIndent);

        // Let's see if we've got more than 16 bytes. We only have a read
        // stream, so we can't _ask_ how many bytes would be physically
        // readable (CountReadable only provides a lower limit, and
        // can return zero even when there's data available). So we
        // have to actually suck it and see. We use a ZStreamR_DynamicBuffered,
        // which lets us read the stream, then return the read bytes to
        // be re-read if it turns out we've got enough to warrant doing
        // indentation.

        ZStreamRWPos_RAM theStreamRAM;
        ZStreamR_DynamicBuffered theStream(iStream, theStreamRAM);
        uint64 countSkipped;
        theStream.Skip(17, &countSkipped);
        theStream.Rewind();
        theStream.Commit();

        if (countSkipped <= 16)
        {
            // We've got 16 or fewer bytes, emit them on the same line.
            fStrimW.Write("binary { ");
            ZStreamW_HexStrim(" ", "", 16, fStrimW).CopyAllFrom(theStream, nullptr, nullptr);
            fStrimW.Write(" }\n");
        }
        else
        {
            // We've got more than 16 bytes, break them up into nice lines.
            fStrimW.Write("binary\n");

            spWriteIndent(fStrimW, fIndent + 1);
            fStrimW.Write("{");

            uint64 size;
            string chunkSeparator = "\n" + string(fIndent + 1, '\t');
            ZStreamW_HexStrim(" ", chunkSeparator, 16, fStrimW)
            .CopyAllFrom(theStream, &size, nullptr);

            fStrimW.Write("\n");
            spWriteIndent(fStrimW, fIndent + 1);
            fStrimW.Writef("} // %lld bytes\n", size);
        }
    }
    else
    {
        uint64 size;
        iStream.SkipAll(&size);

        if (fInBlock)
            spWriteIndent(fStrimW, fIndent);

        fStrimW.Writef("binary { /* content not shown */ } // %d bytes\n", size);
    }
}
Esempio n. 2
0
void ZASParser::ParseHandler::ParsedBinary(const ZStreamR& iStream)
	{
	// Just suck up and ignore the data
	iStream.SkipAll(nil);
	}