-
Notifications
You must be signed in to change notification settings - Fork 65
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
How to convert to string? #40
Comments
I think that bytes array is actually correct.
I don't think this is what you need, but if for some reason you actually need a string with the If you just want to convert the bytes type (suitable for sending to a socket, for instance) to a string (suitable for writing to a log file or something), you can use the Hope this helps! |
Thanks! You are correct, I just need to store the FIX message as a string to another file for an application to process which is expecting "^A" as the delimiter. If I use decode, it seems that I lose the "\x01" chars all together.
Is this expected? Or the "\x01" chars are present in the string but are unprintable ? |
Yes, it really depends on where the result is being displayed: the SOH character doesn't have a standard representation, which is why some things show "^A", and Python uses "\x01", and others just show nothing. It's pretty common in FIX logging, for instance, to replace them with the vertical bar character for exactly this reason. In fact, built into
|
Thank you, this function resolves my issue.
This prints - |
Great that you've got it working. I think you could make one further simplification:
Doesn't save much, but ... you can have |
I tried that first but got the following error. It looks like the "sep" parameter is expecting a char and "^A" is considered two chars.
Thanks. |
Ah ... that feels like a bug. I'm going to reopen this issue, and investigate further, but ... it seems like it'd be much more useful if it accepted a string (or bytes) there? I think this is in fact the very first bit of code that subsequently became simplefix. I haven't looked at it for ages. |
Hello,
Thanks for the awesome library. One quick question - once i have the byte buffer after doing the encode(), how do I convert it to a string so that or "\x01" characters are converted to "^A" characters ? I tried various different ways to do this, like repr(byte_buffer) or (ord(x) in bye_buffer) etc. but could not.
My bytes array looks like below -
b'8=FIX.4.4\x019=65\x0135=0\x0152=20220809-21:37:06.893\x0149=TRADEWEB\x0156=ABFIXREPO\x01347=UTF-8\x0110=045\x01'
Any idea ? Thanks
The text was updated successfully, but these errors were encountered: