Protocol Buffer Messages via Akka IO and Sockets

牧云@^-^@ 提交于 2019-12-05 09:08:47

Try this:

val myByteArray = myByteString.toArray // converts to an Array[Byte]
val myMessage = MyMessage.defaultInstance.mergeFrom(myByteArray)

MyMessage is the ScalaBuff-compiler-generated class using your MyMessage.proto template. Note that the Google protobuf library has a separate ByteString class, make sure you don't mix the two.

UPDATE: Kevin's problem has been solved, basically the problem was the he was using the toString method of an Array[Byte] instead of wrapping the byte array in a new String(), which correctly converts the byte array to a String, to be used in a "%s".format call.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!