Skip to content

Commit 825e418

Browse files
committed
Merge branch 'v07-develop' into v07-add-jackson-dataformat
2 parents 7c95a9e + d59d731 commit 825e418

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

msgpack-core/src/main/java/org/msgpack/value/impl/MapCursorImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void accept(ValueVisitor visitor) {
109109
@Override
110110
public MapValue toValue() {
111111
ensureNotTraversed();
112-
Value[] keyValueArray = new Value[mapSize];
112+
Value[] keyValueArray = new Value[mapSize * 2];
113113
int i = 0;
114114
while(hasNext()) {
115115
keyValueArray[i++] = nextKeyOrValue().toValue();

msgpack-core/src/test/scala/org/msgpack/core/MessagePackTest.scala

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package org.msgpack.core
22

3+
import org.msgpack.value.Value
4+
import org.msgpack.value.holder.ValueHolder
5+
6+
import scala.collection.mutable.ListBuffer
37
import scala.util.Random
48
import MessagePack.Code
59
import java.io.ByteArrayOutputStream
@@ -413,5 +417,36 @@ class MessagePackTest extends MessagePackSpec {
413417

414418
}
415419

420+
"pack/unpack maps in lists" in {
421+
val aMap = List(Map("f" -> "x"))
422+
423+
check(aMap, { packer =>
424+
packer.packArrayHeader(aMap.size)
425+
for (m <- aMap) {
426+
packer.packMapHeader(m.size)
427+
for ((k, v) <- m) {
428+
packer.packString(k)
429+
packer.packString(v)
430+
}
431+
}
432+
}, { unpacker =>
433+
val holder = new ValueHolder()
434+
unpacker.unpackValue(holder)
435+
val v = holder.get()
436+
437+
v.asArrayValue().toValueArray.map { m =>
438+
val mv = m.asMapValue()
439+
val kvs = mv.toKeyValueSeq
440+
441+
kvs.grouped(2).map({ kvp: Array[Value] =>
442+
val k = kvp(0)
443+
val v = kvp(1)
444+
445+
(k.asString().toString, v.asString().toString)
446+
}).toMap
447+
}.toList
448+
})
449+
}
450+
416451
}
417452
}

msgpack-core/src/test/scala/org/msgpack/value/CursorTest.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ class CursorTest extends MessagePackSpec {
5252
}
5353
}
5454

55+
"have map cursor" taggedAs("map") in {
56+
val packedData = createMessagePackData { packer =>
57+
packer packMapHeader(1) packString("f") packString("x")
58+
}
59+
60+
val cursor = mf.newUnpacker(packedData).getCursor
61+
val mapCursor = cursor.nextRef().getMapCursor
62+
mapCursor.size() shouldBe 1
63+
64+
val mapValue = mapCursor.toValue
65+
val data = mapValue.toKeyValueSeq
66+
67+
data should have length 2
68+
69+
data(0).asString().toString shouldBe "f"
70+
data(1).asString().toString shouldBe "x"
71+
}
72+
5573
"traverse ValueRef faster than traversing Value" taggedAs("ref") in {
5674
val N = 10000
5775
val data = binSeq(N)

0 commit comments

Comments
 (0)