I want to convert a string object to ByteString.I have tried to use ByteString.CopyFrom() function to convert,but the return value is always "{Google.ProtocolBuffers.ByteString}".Why? How can I do?
Asked
Active
Viewed 3.8k times
11
-
byte[] array = Encoding.ASCII.GetBytes(input); – Vivek Nuna Oct 09 '16 at 13:29
3 Answers
13
Your string
has been successfully converted to ByteStream
. If you see {Google.ProtocolBuffers.ByteString} in the watch window, it simply means that the ByteStream
does not override the ToString
method. In short, Visual Studio doesn't know how to display a ByteStream
, and therefore just display the type name instead.
That said, there is an overload of the CopyFrom
method that allows you to directly use a string:
var APP_DEF_TEA_KEY = ByteString.CopyFrom("e#>&*m16", Encoding.Unicode);

Kevin Gosse
- 38,392
- 3
- 78
- 94
2
You can use one of methods from ByteString class to convert string to ByteArray
ByteString.copyFromUtf8(stringText)
.

Maneesh K Bishnoi
- 131
- 1
- 7