cbor: make `DiagnosticWriter` a little smarter.

The DiagnosticWriter converts CBOR structures into debugging strings. It
approximately caps the size of the returned strings to avoid huge
messages causing problems. But when a CBOR structure contains a huge
bytestring, that can immediately hit the limit and cause all the
rest of the structure to be ignored.

This change causes any bytestring that, when hex-encoded, is > 87.5% of
the max output length, or which pushes the debugging string over the
limit, to be replaced by a placeholder: "(x bytes)".

This isn't perfect, it's still a greedy algorithm, but it's a modest
debugging improvement when there are large bytestrings in a message.

Change-Id: I3a812d179a0f353336f86cab612ae517d9b572cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5310565
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Auto-Submit: Adam Langley <agl@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1263095}
NOKEYCHECK=True
GitOrigin-RevId: ec76a6e2a0b400e2283df7a290b166956cc24ac9
2 files changed