akka/akka-core

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

Aberta

#24.402 aberto em 24 de jan. de 2018

 (1 comentário) (0 reação) (0 responsável)Scala (3.547 forks)batch import
1 - triagedhelp wantedt:core

Métricas do repositório

Stars
 (13.277 estrelas)
Métricas de merge de PR
 (Mesclagem média 8d 19h) (10 fundiu PRs em 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

Guia do colaborador