akka/akka-core

ByteString byte order is not preserved or set when converting it to ByteBuffer

Open

#24,402 opened on Jan 24, 2018

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Scala (3,547 forks)batch import
1 - triagedhelp wantedt:core

Repository metrics

Stars
 (13,277 stars)
PR merge metrics
 (Avg merge 8d 19h) (10 merged PRs in 30d)

Description

As @ktoso suggested, creating this issue here.

When using ByteString.asByteBuffer it should set ByteOrder automatically. Having to set it as an implicit value as well as in ByteBuffer.order() seems too much work.

implicit val byteOrder: ByteOrder = ByteOrder.nativeOrder()
val bx = ByteString.createBuilder
bx.putInt(8)
val res = bx.result().asByteBuffer.duplicate()
res.order(byteOrder)
println(res.getInt) // prints 8 correctly

Contributor guide