Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting gob stream encoder? #636

Closed
oderwat opened this issue Nov 18, 2022 · 7 comments
Closed

Supporting gob stream encoder? #636

oderwat opened this issue Nov 18, 2022 · 7 comments

Comments

@oderwat
Copy link
Contributor

oderwat commented Nov 18, 2022

I consider using some kind of gob encoding for the payload (see GOB_ENCODER) and think that it would be nice to have something like nats sub --gob gobsubject which then dumps the result in some more readable way. I also wonder if there should be a --hex or --b64 flag to output the data as hex or base64 encoded data. This probably would help when debugging something which is not using JSON or the default encoder. As these tools are really cool, I wonder it this was considered before and what the state is for that.

@ripienaar
Copy link
Collaborator

I have considered it - but there is an infinite amount of options so seems like a losing battle

so it supports emitting the data raw (no decorations or metadata) and you should be able to pipe or to other, encoding specific, tools or use things like xargs.

If anything rather than a long series of supported encoding formats I am more likely to add the ability to pass each message through an external binary for deciding before rendering so it can support anything.

@oderwat
Copy link
Contributor Author

oderwat commented Nov 18, 2022

If anything rather than a long series of supported encoding formats I am more likely to add the ability to pass each message through an external binary for deciding before rendering so it can support anything.

I see, and I also thought about piping it through some decoder (and would implement one right away).

Still, using b64 / hex seems like an easy way to support everything for a quick "copy & paste" or in the case of hex even for reading it "natively". While "gob" is one of the NATS supported internal decoders (at least I am coming right from an example that shows its usage). I have no insights, but it feels like a practical option for encoding when staying in the Go language domain for clients and services.

so it supports emitting the data raw (no decorations or metadata)

Furthermore, the current implementation just spills everything into the terminal, even if you do not use --raw. This may create a big mess. Having it detect binary and convert that to some hex representation (or suppress it) seems very attractive to me.

@ripienaar
Copy link
Collaborator

Yeah it’s certainly not ideal at present with binary data (though iirc I do base64 it? Might remeber wrong)

hex and base64 decoders at the least would be good. But I would need to be carefully to detect if the output is not a terminal to enable that behaviour since it will almost certainly be binary data then

@oderwat
Copy link
Contributor Author

oderwat commented Nov 18, 2022

I wonder if some people already rely on it being binary in the non --raw mode. I think the standard mode could get some variant of the raw mode, maybe --unfiltered or --noesc. But perhaps it would be safer to add a --escape flag, that escapes the output (into base64 or hex) only if it is not printable because if you just leave it "raw" in the case where it is not a terminal, it will not work well with something like tee or watch tail -100 or something I need to make up :)

@oderwat
Copy link
Contributor Author

oderwat commented Nov 18, 2022

This is what I currently get using json and gob encoder:

$ nats sub "hello"
21:37:41 Subscribing on hello 
[#1] Received on "hello"
{"Name":"derek","Address":"140 New Montgomery Street, San Francisco, CA","Age":22}

[#2] Received on "hello"
1��person��Name
               Address
                      Age:��derek,140 New Montgomery Street, San Francisco, CA,

@ripienaar
Copy link
Collaborator

Ah yes, nats sub just dumps what it finds, its pretty low level on purpose.

will give it some thought, for sure dumping binary to stdout is bad news

@ripienaar
Copy link
Collaborator

Closing this since we have the translation feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants