Skip to content

ByteSequence toString ? #399

@vorburger

Description

@vorburger

For debugging, I've found it sometimes useful to log the ByteSequence of a KV.

Our io.etcd.jetcd.data.ByteSequence currently does not implement java.lang.Object.toString().

I have therefore implemented this helper utility for this (see also its usage in ByteSequencesTest), and was wondering if a contribution with that here would be welcome?

Keys (and Values) of course may well contain arbitrary byte sequences. The escaping I implemented is more meant to "look nice, and compact, in logs" than being a reliable bi-directional "codec" (i.e. my goal was only to be able to go from byte[] to readable text, NOT to come up with a representation where said text can be re-transformed into a byte[]). It looks like e.g. «A·00B·FF» for 4 bytes ('A', 0 b, 'B', FF b).

PS: ByteSequence does have a toString(Charset) but that is not for debug logging, and perhaps should have instead better be named getString(), like its getBytes(), or even asString(), but it's already too late for that now, I guess?)

PPS: Perhaps etcdctl ls could print using the same format? I'll file an issue there.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions