Skip to content

Commit 2e90092

Browse files
committed
Fix several bugs identified in PR review
- MessagePackMapper.version() now returns PackageVersion.VERSION instead of Version.unknownVersion(), consistent with factory and parser. - writeName(SerializableString): remove IllegalArgumentException for unknown implementations (fall back to writeName(getValue())); also fix missing writeContext.writeName() call for MessagePackSerializedString. - unpackString(): delegate to messageUnpacker.unpackString() instead of manual header-read + payload copy; removes tempBytes allocation. ~25% deserialization speedup on pojo benchmark (fewer copies). - Rename local variable 'scheme' -> 'schema' in test.
1 parent b087eb7 commit 2e90092

4 files changed

Lines changed: 7 additions & 20 deletions

File tree

msgpack-jackson3/src/main/java/org/msgpack/jackson/dataformat/MessagePackGenerator.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import tools.jackson.core.TokenStreamContext;
2828
import tools.jackson.core.base.GeneratorBase;
2929
import tools.jackson.core.io.IOContext;
30-
import tools.jackson.core.io.SerializedString;
3130
import org.msgpack.core.MessagePack;
3231
import org.msgpack.core.MessagePacker;
3332
import org.msgpack.core.annotations.Nullable;
@@ -569,14 +568,12 @@ public JsonGenerator writeName(String name) throws JacksonException
569568
@Override
570569
public JsonGenerator writeName(SerializableString name) throws JacksonException
571570
{
572-
if (name instanceof SerializedString) {
573-
writeName(name.getValue());
574-
}
575-
else if (name instanceof MessagePackSerializedString) {
571+
if (name instanceof MessagePackSerializedString) {
572+
writeContext.writeName(name.getValue());
576573
addKeyNode(((MessagePackSerializedString) name).getRawValue());
577574
}
578575
else {
579-
throw new IllegalArgumentException("Unsupported key: " + name);
576+
writeName(name.getValue());
580577
}
581578
return this;
582579
}

msgpack-jackson3/src/main/java/org/msgpack/jackson/dataformat/MessagePackMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,6 @@ public static Builder builder(MessagePackFactory f)
115115
@Override
116116
public Version version()
117117
{
118-
return Version.unknownVersion();
118+
return PackageVersion.VERSION;
119119
}
120120
}

msgpack-jackson3/src/main/java/org/msgpack/jackson/dataformat/MessagePackParser.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import java.io.InputStream;
4141
import java.math.BigDecimal;
4242
import java.math.BigInteger;
43-
import java.nio.charset.StandardCharsets;
4443

4544
public class MessagePackParser
4645
extends ParserMinimalBase
@@ -58,7 +57,6 @@ public class MessagePackParser
5857
private long currentPosition;
5958
private final IOContext ioContext;
6059
private ExtensionTypeCustomDeserializers extTypeCustomDesers;
61-
private final byte[] tempBytes = new byte[64];
6260

6361
private enum Type
6462
{
@@ -140,15 +138,7 @@ public Version version()
140138

141139
private String unpackString(MessageUnpacker messageUnpacker) throws IOException
142140
{
143-
int strLen = messageUnpacker.unpackRawStringHeader();
144-
if (strLen <= tempBytes.length) {
145-
messageUnpacker.readPayload(tempBytes, 0, strLen);
146-
return new String(tempBytes, 0, strLen, StandardCharsets.UTF_8);
147-
}
148-
else {
149-
byte[] bytes = messageUnpacker.readPayload(strLen);
150-
return new String(bytes, 0, strLen, StandardCharsets.UTF_8);
151-
}
141+
return messageUnpacker.unpackString();
152142
}
153143

154144
@Override

msgpack-jackson3/src/test/java/org/msgpack/jackson/dataformat/MessagePackDataformatForPojoTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ public void testSerializationWithoutSchema()
139139
.annotationIntrospector(new JsonArrayFormat())
140140
.build();
141141
byte[] bytes = objectMapper.writeValueAsBytes(complexPojo);
142-
String scheme = new String(bytes, Charset.forName("UTF-8"));
143-
assertThat(scheme, not(containsString("name")));
142+
String schema = new String(bytes, Charset.forName("UTF-8"));
143+
assertThat(schema, not(containsString("name")));
144144
ComplexPojo value = objectMapper.readValue(bytes, ComplexPojo.class);
145145
assertEquals("komamitsu", value.name);
146146
assertEquals(20, value.age);

0 commit comments

Comments
 (0)