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

Add convenience method for other java floating-point types(float, double) #202

Closed
lkishor opened this issue Apr 2, 2016 · 2 comments
Closed

Comments

@lkishor
Copy link

lkishor commented Apr 2, 2016

It would be great if BufferedSource & BufferedSink would have methods for reading and writing float & doubles as

float readFloat()
float readFloatLe()
double readDouble()
double readDoubleLe()

writeFloat(float v)
writeFloatLe(float v)
writeDouble(double v)
writeDoubleLe(float v)

I need these methods, as I am trying to read from a Persistent Socket connection which transfers byte[].
And now for reading a float I have to write
float val = ByteBuffer.wrap(data.readByteArray(4)).order(ByteOrder.LITTLE_ENDIAN).getFloat()

which at the least is a lot of code instead of data.readFloatLe()

and as per my understanding involves multiple copying of byte[] (memory allocation stuff), which is what I was trying to avoid by using OKIO

@JakeWharton
Copy link
Collaborator

Can you do Float.intBitsToFloat(data.readIntLe()) and
Double.longBitsToDouble(data.readLongLe()) ?

On Sat, Apr 2, 2016 at 2:37 AM Lal Kishor notifications@github.com wrote:

It would be great if BufferedSource & BufferedSink would have methods for
reading and writing float & doubles as

float readFloat()
float readFloatLe()
double readDouble()
double readDoubleLe()

writeFloat(float v)
writeFloatLe(float v)
writeDouble(double v)
writeDoubleLe(float v)

I need these methods, as I am trying to read from a Persistent Socket
connection which transfers byte[].
And now for reading a float I have to write
float val =
ByteBuffer.wrap(data.readByteArray(4)).order(ByteOrder.LITTLE_ENDIAN).getFloat()

which at the least is a lot of code instead of data.readFloatLe()

and as per my understanding involves multiple copying of byte[] (memory
allocation stuff), which is what I was trying to avoid by using OKIO


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#202

@lkishor
Copy link
Author

lkishor commented Apr 2, 2016

that's great, thank you for the quick response..

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