-
Notifications
You must be signed in to change notification settings - Fork 13
Updated repository to Julia 0.7+ and 1.1+ #8
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
Conversation
elseif addntl_info == ADDNTL_INFO_FLOAT16 | ||
error("Decoding 16-bit floats isn't supported.") | ||
end | ||
|
||
bytes_consumed += float_byte_len | ||
const data = hex2num(bytes2hex( | ||
data = reinterpret(Float64,parse(UInt64,bytes2hex( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need to use bytes2hex
or parse
at all here. For example, you could just do:
reinterpret(Float64, ntoh(reinterpret(UInt64, bytes[(start_idx + 1):(start_idx + float_byte_len)])))
This could be made even more efficient (if you care) by eliminating the creation and reinterpretation of a array for the bytes
slice:
reinterpret(Float64, UInt64(bytes[start_idx + 1]) << 56 +
UInt64(bytes[start_idx + 2]) << 48 +
UInt64(bytes[start_idx + 3]) << 40 +
UInt64(bytes[start_idx + 4]) << 32 +
UInt64(bytes[start_idx + 5]) << 24 +
UInt64(bytes[start_idx + 6]) << 16 +
UInt64(bytes[start_idx + 7]) << 8 +
UInt64(bytes[start_idx + 8]))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if instead of working with bytes
arrays, you read directly from an IO
stream (or an IOBuffer
), you could just do:
ntoh(read(io, Float64))
(where the ntoh
is to fixe the byte order).
else | ||
const float_bytes = hex2bytes(num2hex(float)) | ||
float_bytes = hex2bytes(string(reinterpret(Unsigned,float),base=16,pad=sizeof(float)*2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If instead of using an array of bytes, you used an IO
stream (or an IOBuffer
), you could just write(io, hton(float))
.
By converting the value to a string, then parsing into an array of bytes, and then pushing the array of bytes to another array, you are probably at least an order of magnitude slower, as well as requiring much more code.
Oh woops, why do I never look into PRs when upgrading a package... |
Thanks for making progress on it, was hoping somebody would keep this package in order because I wanted to use it for one of my upcoming projects. How is it coming along at the moment? I see you have not merged anything yet |
#10 took this over |
This pull-request updates the CBOR repository to be compatible with Julia 0.7+ and 1.1+
This also resolves the issue discussed in #7 with @stevengj
Unfortunately, the tests are not all passing yet. Some more tweaks need to be made, but I am not familiar with what is causing the problem.
Could you please review this pull-request and see if you can fix the rest of the testing?