Open codefromthecrypt opened 5 years ago
You could write a Source
and/or Sink
that did this on-the-fly without Wire ever needing to know about it. Then it's just about wrapping your inputs/outputs as they make their way to Wire.
This is basically what the Gzip and Deflate wrappers are doing: on-the-fly transcoding. Hex is, thankfully, a much simpler encoding so it should be much simpler to do.
So I guess where I was at was I didn't want to interfere with the bookeeping going on with ProtoReader (it keeps track of how many bytes etc). Are you saying you would make a proto-aware source that looks at encoded fields to figure out which ones are bytes and should become hex?
I'm referring to this which I couldn't find a sensible way to work around without invalidating the reader (doing stream parsing) https://github.com/square/wire/blob/master/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/ProtoReader.kt#L371
Oh so you want an individual field to do hex-to-byte conversion? Is it represented as a string or as bytes in the encoded form?
On Fri, May 10, 2019, 10:33 PM Adrian Cole notifications@github.com wrote:
I'm referring to this which I couldn't find a sensible way to work around without invalidating the reader (doing stream parsing) https://github.com/square/wire/blob/master/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/ProtoReader.kt#L371
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/square/wire/issues/958#issuecomment-491472447, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAQIEKK5MLJWUFCB2N66KLPUYV53ANCNFSM4HMHDT3A .
yep. in proto it is bytes, in everywhere else (java type, correlation and json encoding) it is hex
incidentally there's a slightly related problem in the same data type as IPs are in the proto as bytes, but everywhere else string literals. Ideally some callback to process the bytes one-by-one would be good, but at any rate having the hex thing for IDs improves a good measure.
There's an undocumented concept called adapters which should be able to solve this. Perhaps Jesse can chime in since he wrote it. Otherwise I'll circle back soon.
On Fri, May 10, 2019, 10:44 PM Adrian Cole notifications@github.com wrote:
incidentally there's a slightly related problem in the same data type as IPs are in the proto as bytes, but everywhere else string literals. Ideally some callback to process the bytes one-by-one would be good, but at any rate having the hex thing for IDs improves a good measure.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/square/wire/issues/958#issuecomment-491473125, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAQIEPC23ZPZSOR3BH7MHLPUYXIHANCNFSM4HMHDT3A .
While edge case, Zipkin's primary representation of bytes is hex (even if they are transmitted in proto as raw bytes). It helps performance wise to be able to parse into a hex string (likely other way, too)
ex