msgpack-java icon indicating copy to clipboard operation
msgpack-java copied to clipboard

Convert Type to Value (org.msgpack.value.Value), if one exists

Open chintan-mishra opened this issue 7 years ago • 4 comments

How can I convert an Array to ArrayValue?

For instance

String[] myStringArray = {"abc", "def", "ghi"}
// now I want to pack it in MessageBufferPacker
// I don't want to use a loop(really big array 200 elements) to read
// each value followed by packString

messageBufferPacker.packValue(myStringArray.asArrayValue)
// This doesn't work.

What should I do?

chintan-mishra avatar Feb 21 '18 08:02 chintan-mishra

@chintan-mishra Try using https://static.javadoc.io/org.msgpack/msgpack-core/0.8.14/org/msgpack/value/ValueFactory.html

import static ValueFactory.*
newArray(newString("abc"), ...) 

xerial avatar Feb 21 '18 17:02 xerial

I still have to iterate over a large number of elements.

chintan-mishra avatar Feb 22 '18 07:02 chintan-mishra

If that's the case, directly calling packArrayHeader(n), packString(x_1),..., packString(x_n) is better .

xerial avatar Feb 22 '18 17:02 xerial

I will make do with this for now.

chintan-mishra avatar Feb 24 '18 03:02 chintan-mishra