FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix a bug when creating nested maps and arrays by xerial · Pull Request #152 · msgpack/msgpack-java · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (2) .sbt  (1) .scala  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayDeque;

import static org.msgpack.core.MessagePackException.UNREACHABLE;

Expand All @@ -24,8 +25,8 @@ public class ValueHolder {
private FloatHolder floatHolder = new FloatHolder();
private RawHolder rawHolder = new RawHolder();
private ExtHolder extHolder = new ExtHolder();
private ArrayCursorImpl arrayCursor = new ArrayCursorImpl(this);
private MapCursorImpl mapCursor = new MapCursorImpl(this);
private ArrayCursorImpl arrayCursor;
private MapCursorImpl mapCursor;
private ValueRef currentRef;

public ValueRef getRef() {
Expand Down Expand Up @@ -108,12 +109,18 @@ public void setExt(int extType, MessageBuffer b) {

public void prepareArrayCursor(MessageUnpacker unpacker) throws IOException {
vt = ValueType.ARRAY;

// TODO reusing cursor instances
arrayCursor = new ArrayCursorImpl(new ValueHolder());
arrayCursor.reset(unpacker);
currentRef = arrayCursor;
}

public void prepareMapCursor(MessageUnpacker unpacker) throws IOException {
vt = ValueType.MAP;

// TODO reusing cursor instances
mapCursor = new MapCursorImpl(new ValueHolder());
mapCursor.reset(unpacker);
currentRef = mapCursor;
}
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.msgpack.value.impl;

import org.msgpack.core.MessageFormatException;
import org.msgpack.core.MessagePacker;
import org.msgpack.core.MessageTypeException;
import org.msgpack.core.MessageUnpacker;
import org.msgpack.core.*;
import org.msgpack.value.*;
import org.msgpack.value.holder.ValueHolder;

Expand Down Expand Up @@ -50,7 +47,7 @@ public boolean hasNext() {
@Override
public ValueRef nextKeyOrValue() {
try {
unpacker.unpackValue(valueHolder);
MessageFormat f = unpacker.unpackValue(valueHolder);
cursor++;
return valueHolder.getRef();
}
Expand Down Expand Up @@ -78,7 +75,7 @@ public void skipAll() {

private void ensureNotTraversed() {
if(cursor != 0)
throw UNSUPPORTED("ArrayCursor is already traversed");
throw UNSUPPORTED("MapCursor is already traversed");
}


Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
//
package org.msgpack.value

import java.io.ByteArrayInputStream

import org.msgpack.core.{MessagePack, MessageUnpacker, MessagePackSpec}
import ValueFactory._
import scala.util.Random
import org.msgpack.value.holder.IntegerHolder
import org.msgpack.value.holder.{ValueHolder, IntegerHolder}

/**
* Created on 6/13/14.
Expand Down Expand Up @@ -142,8 +144,54 @@ class CursorTest extends MessagePackSpec {
}
}

}

"create immutable map" taggedAs("im-map") in {

val m = createMessagePackData { packer =>
packer.packMapHeader(3)

// A -> [1, "leo"]
packer.packString("A")
packer.packArrayHeader(2)
packer.packInt(1)
packer.packString("leo")

// B -> 10
packer.packString("B")
packer.packInt(10)

// C -> {a -> 1.0f, b -> 5, c -> {cc->1}}
packer.packString("C")
packer.packMapHeader(3)
packer.packString("a")
packer.packFloat(1.0f)
packer.packString("b")
packer.packInt(5)

packer.packString("c")
packer.packMapHeader(1)
packer.packString("cc")
packer.packInt(1)

}

val unpacker = msgpack.newUnpacker(m)
val vh = new ValueHolder
unpacker.unpackValue(vh)
val mapValue = vh.get().asMapValue()

val map = mapValue.toMap
map.size shouldBe 3

val arr = map.get(ValueFactory.newString("A")).asArrayValue()
arr.size shouldBe 2

val cmap = map.get(ValueFactory.newString("C")).asMapValue()
cmap.size shouldBe 3
cmap.toMap.get(ValueFactory.newString("c")).asMapValue().size() shouldBe 1

info(mapValue)
}


Expand Down
2 changes: 1 addition & 1 deletion version.sbt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "0.7.0-M6-SNAPSHOT"
version in ThisBuild := "0.7.0-p2"

Back | FazBrowse Home | New Git URL