Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,27 @@
//
package org.msgpack.core;

import org.msgpack.core.buffer.ArrayBufferOutput;
import org.msgpack.core.buffer.MessageBuffer;
import org.msgpack.core.buffer.MessageBufferOutput;
import org.msgpack.core.buffer.ArrayBufferOutput;

import java.io.IOException;
import java.util.List;

/**
* MessagePacker that is useful to produce byte array output
*/
public class MessageBufferPacker
extends MessagePacker
{
public MessageBufferPacker()
{
this(new ArrayBufferOutput());
}

public MessageBufferPacker(ArrayBufferOutput out)
public MessageBufferPacker(MessagePack.PackerConfig config)
{
super(out);
this(new ArrayBufferOutput(), config);
}

@Override
public MessageBufferPacker setSmallStringOptimizationThreshold(int bytes)
public MessageBufferPacker(ArrayBufferOutput out, MessagePack.PackerConfig config)
{
super.setSmallStringOptimizationThreshold(bytes);
return this;
super(out, config);
}

public MessageBufferOutput reset(MessageBufferOutput out)
Expand All @@ -51,23 +47,28 @@ public MessageBufferOutput reset(MessageBufferOutput out)
return super.reset(out);
}

private ArrayBufferOutput getArrayBufferOut()
{
return (ArrayBufferOutput) out;
}

public void clear()
{
((ArrayBufferOutput) out).clear();
getArrayBufferOut().clear();
}

public byte[] toByteArray()
{
return ((ArrayBufferOutput) out).toByteArray();
return getArrayBufferOut().toByteArray();
}

public MessageBuffer toMessageBuffer()
{
return ((ArrayBufferOutput) out).toMessageBuffer();
return getArrayBufferOut().toMessageBuffer();
}

public List<MessageBuffer> toBufferList()
{
return ((ArrayBufferOutput) out).toBufferList();
return getArrayBufferOut().toBufferList();
}
}
89 changes: 1 addition & 88 deletions msgpack-core/src/main/java/org/msgpack/core/MessageFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.msgpack.core.annotations.VisibleForTesting;
import org.msgpack.value.ValueType;
import org.msgpack.core.MessagePack.Code;

/**
* Describes the list of the message format types defined in the MessagePack specification.
Expand Down Expand Up @@ -65,94 +66,6 @@ public enum MessageFormat
MAP32(ValueType.MAP),
NEGFIXINT(ValueType.INTEGER);

/**
* The prefix code set of MessagePack. See also https://github.com/msgpack/msgpack/blob/master/spec.md for details.
*/
public static final class Code
{
public static final boolean isFixInt(byte b)
{
int v = b & 0xFF;
return v <= 0x7f || v >= 0xe0;
}

public static final boolean isPosFixInt(byte b)
{
return (b & POSFIXINT_MASK) == 0;
}

public static final boolean isNegFixInt(byte b)
{
return (b & NEGFIXINT_PREFIX) == NEGFIXINT_PREFIX;
}

public static final boolean isFixStr(byte b)
{
return (b & (byte) 0xe0) == Code.FIXSTR_PREFIX;
}

public static final boolean isFixedArray(byte b)
{
return (b & (byte) 0xf0) == Code.FIXARRAY_PREFIX;
}

public static final boolean isFixedMap(byte b)
{
return (b & (byte) 0xf0) == Code.FIXMAP_PREFIX;
}

public static final boolean isFixedRaw(byte b)
{
return (b & (byte) 0xe0) == Code.FIXSTR_PREFIX;
}

public static final byte POSFIXINT_MASK = (byte) 0x80;

public static final byte FIXMAP_PREFIX = (byte) 0x80;
public static final byte FIXARRAY_PREFIX = (byte) 0x90;
public static final byte FIXSTR_PREFIX = (byte) 0xa0;

public static final byte NIL = (byte) 0xc0;
public static final byte NEVER_USED = (byte) 0xc1;
public static final byte FALSE = (byte) 0xc2;
public static final byte TRUE = (byte) 0xc3;
public static final byte BIN8 = (byte) 0xc4;
public static final byte BIN16 = (byte) 0xc5;
public static final byte BIN32 = (byte) 0xc6;
public static final byte EXT8 = (byte) 0xc7;
public static final byte EXT16 = (byte) 0xc8;
public static final byte EXT32 = (byte) 0xc9;
public static final byte FLOAT32 = (byte) 0xca;
public static final byte FLOAT64 = (byte) 0xcb;
public static final byte UINT8 = (byte) 0xcc;
public static final byte UINT16 = (byte) 0xcd;
public static final byte UINT32 = (byte) 0xce;
public static final byte UINT64 = (byte) 0xcf;

public static final byte INT8 = (byte) 0xd0;
public static final byte INT16 = (byte) 0xd1;
public static final byte INT32 = (byte) 0xd2;
public static final byte INT64 = (byte) 0xd3;

public static final byte FIXEXT1 = (byte) 0xd4;
public static final byte FIXEXT2 = (byte) 0xd5;
public static final byte FIXEXT4 = (byte) 0xd6;
public static final byte FIXEXT8 = (byte) 0xd7;
public static final byte FIXEXT16 = (byte) 0xd8;

public static final byte STR8 = (byte) 0xd9;
public static final byte STR16 = (byte) 0xda;
public static final byte STR32 = (byte) 0xdb;

public static final byte ARRAY16 = (byte) 0xdc;
public static final byte ARRAY32 = (byte) 0xdd;

public static final byte MAP16 = (byte) 0xde;
public static final byte MAP32 = (byte) 0xdf;

public static final byte NEGFIXINT_PREFIX = (byte) 0xe0;
}

private static final MessageFormat[] formatTable = new MessageFormat[256];
private final ValueType valueType;

Expand Down
Loading