okio icon indicating copy to clipboard operation
okio copied to clipboard

support 24bit numbers

Open codefromthecrypt opened this issue 11 years ago • 5 comments

Conceding this is an uncommon use case, http2 has a 24bit unsigned length field. It feel cleaner if okhttp could ask okio to read/writeMedium.

https://tools.ietf.org/html/draft-ietf-httpbis-http2-14#section-4.1

codefromthecrypt avatar Sep 07 '14 16:09 codefromthecrypt

I would not call this size number a medium. On Sep 7, 2014 12:26 PM, "Adrian Cole" [email protected] wrote:

Conceding this is an uncommon use case, http2 has a 24bit unsigned length field. It feel cleaner if okhttp could ask okio to read/writeMedium.

https://tools.ietf.org/html/draft-ietf-httpbis-http2-14#section-4.1

— Reply to this email directly or view it on GitHub https://github.com/square/okio/issues/74.

JakeWharton avatar Sep 07 '14 19:09 JakeWharton

Since there's no native type at this size and the use case is small I'm leaning toward not having this as a first-party API.

The alternative for consumers is a convenience method which does a readFully on a byte[3](or require%283%29 and 3x readByte) and converts to an int, right? On Sep 7, 2014 3:49 PM, "Jake Wharton" [email protected] wrote:

I would not call this size number a medium. On Sep 7, 2014 12:26 PM, "Adrian Cole" [email protected] wrote:

Conceding this is an uncommon use case, http2 has a 24bit unsigned length field. It feel cleaner if okhttp could ask okio to read/writeMedium.

https://tools.ietf.org/html/draft-ietf-httpbis-http2-14#section-4.1

— Reply to this email directly or view it on GitHub https://github.com/square/okio/issues/74.

JakeWharton avatar Sep 07 '14 19:09 JakeWharton

yeah I don't know a good name. Just netty calls it medium. http://netty.io/4.0/api/io/netty/buffer/ByteBuf.html#readMedium()

codefromthecrypt avatar Sep 07 '14 20:09 codefromthecrypt

Oh, nice. On Sep 7, 2014 4:09 PM, "Adrian Cole" [email protected] wrote:

yeah I don't know a good name. Just netty calls it medium. http://netty.io/4.0/api/io/netty/buffer/ByteBuf.html#readMedium()

— Reply to this email directly or view it on GitHub https://github.com/square/okio/issues/74#issuecomment-54758848.

JakeWharton avatar Sep 07 '14 20:09 JakeWharton

I have to admit that I don't regularly encounter 24-bit numbers. Then again, I haven't written a lot of binary protocol or encoding stuff either. Quick googling suggests http/2 (frame length) and BLE (CRC) are the hottest users of 24-bit numbers these days. http/2 has changed minds often, so maybe 24-bit ain't forever there.. So, I can see an argument against adding medium or similarly named.

If we don't, then yeah I think we can make a utility which requires 3 then reads the bytes and shifts them into an int.

codefromthecrypt avatar Sep 07 '14 20:09 codefromthecrypt