Skip to content

Commit e800df4

Browse files
committed
Removed packBinary helper methods since it can be written as packBinaryHeader(xx).writePayload(...)
1 parent b3ef0ab commit e800df4

3 files changed

Lines changed: 21 additions & 41 deletions

File tree

msgpack-core/src/main/java/org/msgpack/core/MessagePack.java

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

3+
import org.msgpack.core.buffer.ArrayBufferInput;
4+
35
import java.nio.charset.Charset;
46
import java.nio.charset.CodingErrorAction;
57

@@ -13,6 +15,12 @@ public class MessagePack {
1315

1416
public static final Charset UTF8 = Charset.forName("UTF-8");
1517

18+
public static MessageUnpacker newUnpacker(byte[] src) {
19+
return new MessageUnpacker(new ArrayBufferInput(src));
20+
}
21+
22+
23+
1624
/**
1725
* Message packer/unpacker configuration object
1826
*/

msgpack-core/src/main/java/org/msgpack/core/MessagePacker.java

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -409,65 +409,41 @@ public MessagePacker packMapHeader(int mapSize) throws IOException {
409409
return this;
410410
}
411411

412-
public MessagePacker pack(Value v) throws IOException {
412+
public MessagePacker packValue(Value v) throws IOException {
413413
v.writeTo(this);
414414
return this;
415415
}
416416

417-
public MessagePacker packExtendedType(int extType, byte[] src, int offset, int len) throws IOException {
418-
return packExtendedTypeHeader(extType, len).writePayload(src, offset, len);
419-
}
420-
421-
public MessagePacker packExtendedType(int extType, byte[] src) throws IOException {
422-
return packExtendedType(extType, src, 0, src.length);
423-
}
424-
425-
public MessagePacker packExtendedType(int extType, ByteBuffer src) throws IOException {
426-
return packExtendedTypeHeader(extType, src.remaining()).writePayload(src);
427-
}
428-
429-
public MessagePacker packExtendedTypeHeader(int extType, int dataLen) throws IOException {
430-
if(dataLen < (1 << 8)) {
431-
if(dataLen > 0 && (dataLen & (dataLen - 1)) == 0) { // check whether dataLen == 2^x
432-
if(dataLen == 1) {
417+
public MessagePacker packExtendedTypeHeader(int extType, int payloadLen) throws IOException {
418+
if(payloadLen < (1 << 8)) {
419+
if(payloadLen > 0 && (payloadLen & (payloadLen - 1)) == 0) { // check whether dataLen == 2^x
420+
if(payloadLen == 1) {
433421
writeByteAndByte(FIXEXT1, (byte) extType);
434-
} else if(dataLen == 2){
422+
} else if(payloadLen == 2){
435423
writeByteAndByte(FIXEXT2, (byte) extType);
436-
} else if(dataLen == 4) {
424+
} else if(payloadLen == 4) {
437425
writeByteAndByte(FIXEXT4, (byte) extType);
438-
} else if(dataLen == 8) {
426+
} else if(payloadLen == 8) {
439427
writeByteAndByte(FIXEXT8, (byte) extType);
440428
} else {
441429
writeByteAndByte(FIXEXT16, (byte) extType);
442430
}
443431
} else {
444-
writeByteAndByte(EXT8, (byte) dataLen);
432+
writeByteAndByte(EXT8, (byte) payloadLen);
445433
writeByte((byte) extType);
446434
}
447-
} else if(dataLen < (1 << 16)) {
448-
writeByteAndShort(EXT16, (short) dataLen);
435+
} else if(payloadLen < (1 << 16)) {
436+
writeByteAndShort(EXT16, (short) payloadLen);
449437
writeByte((byte) extType);
450438
} else {
451-
writeByteAndInt(EXT32, dataLen);
439+
writeByteAndInt(EXT32, payloadLen);
452440
writeByte((byte) extType);
453441

454442
// TODO support dataLen > 2^31 - 1
455443
}
456444
return this;
457445
}
458446

459-
public MessagePacker packBinary(byte[] src) throws IOException {
460-
return packBinary(src, 0, src.length);
461-
}
462-
463-
public MessagePacker packBinary(byte[] src, int offset, int len) throws IOException {
464-
return packBinaryHeader(len).writePayload(src, offset, len);
465-
}
466-
467-
public MessagePacker packBinary(ByteBuffer src) throws IOException {
468-
return packBinaryHeader(src.remaining()).writePayload(src);
469-
}
470-
471447
public MessagePacker packBinaryHeader(int len) throws IOException {
472448
if(len < (1 << 8)) {
473449
writeByteAndByte(BIN8, (byte) len);
@@ -479,10 +455,6 @@ public MessagePacker packBinaryHeader(int len) throws IOException {
479455
return this;
480456
}
481457

482-
public MessagePacker packRawString(ByteBuffer src) throws IOException {
483-
return packRawStringHeader(src.remaining()).writePayload(src);
484-
}
485-
486458
public MessagePacker packRawStringHeader(int len) throws IOException {
487459
if(len < (1 << 5)) {
488460
writeByte((byte) (FIXSTR_PREFIX | len));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CursorTest extends MessagePackSpec {
3030
val len = Random.nextInt(256)
3131
val b = new Array[Byte](len)
3232
Random.nextBytes(b)
33-
packer.packBinary(b)
33+
packer.packBinaryHeader(b.length).writePayload(b)
3434
}
3535
}
3636

0 commit comments

Comments
 (0)