Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move msgpack value classes to another project msgpack-value #571

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 25 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@ lazy val root = Project(id = "msgpack-java", base = file("."))
)
.aggregate(msgpackCore, msgpackJackson)

lazy val msgpackValue = Project(id = "msgpack-value", base = file("msgpack-value"))
.enablePlugins(SbtOsgi)
.settings(
buildSettings,
description := "Value classes of the MessagePack for Java",
OsgiKeys.bundleSymbolicName := "org.msgpack.msgpack-value",
OsgiKeys.exportPackage := Seq(
// TODO enumerate used packages automatically
"org.msgpack.core",
"org.msgpack.value",
),
libraryDependencies ++= Seq(
// msgpack-value should have no external dependencies
junitInterface,
"org.scalatest" %% "scalatest" % "3.0.3" % "test",
"org.scalacheck" %% "scalacheck" % "1.13.5" % "test",
"org.xerial" %% "xerial-core" % "3.6.0" % "test",
"org.msgpack" % "msgpack" % "0.6.12" % "test",
"commons-codec" % "commons-codec" % "1.10" % "test",
"com.typesafe.akka" %% "akka-actor" % "2.5.7" % "test"
)
)

lazy val msgpackCore = Project(id = "msgpack-core", base = file("msgpack-core"))
.enablePlugins(SbtOsgi)
.settings(
Expand All @@ -75,7 +98,7 @@ lazy val msgpackCore = Project(id = "msgpack-core", base = file("msgpack-core"))
),
testFrameworks += new TestFramework("wvlet.airspec.Framework"),
libraryDependencies ++= Seq(
// msgpack-core should have no external dependencies
// msgpack-core should have no external dependencies except for msgpack-value
junitInterface,
"org.wvlet.airframe" %% "airframe-json" % AIRFRAME_VERSION % "test",
"org.wvlet.airframe" %% "airspec" % AIRFRAME_VERSION % "test",
Expand All @@ -88,6 +111,7 @@ lazy val msgpackCore = Project(id = "msgpack-core", base = file("msgpack-core"))
"org.scala-lang.modules" %% "scala-collection-compat" % "2.4.3" % "test"
)
)
.dependsOn(msgpackValue)

lazy val msgpackJackson =
Project(id = "msgpack-jackson", base = file("msgpack-jackson"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* usually needs to copy contents of the buffer.
*/
public class MessageBufferPacker
extends MessagePacker
extends MessagePackerImpl
{
protected MessageBufferPacker(MessagePack.PackerConfig config)
{
Expand Down
141 changes: 72 additions & 69 deletions msgpack-core/src/main/java/org/msgpack/core/MessagePack.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.msgpack.core.buffer.MessageBufferInput;
import org.msgpack.core.buffer.MessageBufferOutput;
import org.msgpack.core.buffer.OutputStreamBufferOutput;
import org.msgpack.value.MessagePackCode;

import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -55,9 +56,9 @@
* <table>
* <tr><th>Output type</th><th>Factory method</th><th>Return type</th></tr>
* <tr><td>byte[]</td><td>{@link #newDefaultBufferPacker()}</td><td>{@link MessageBufferPacker}</td><tr>
* <tr><td>OutputStream</td><td>{@link #newDefaultPacker(OutputStream)}</td><td>{@link MessagePacker}</td></tr>
* <tr><td>WritableByteChannel</td><td>{@link #newDefaultPacker(WritableByteChannel)}</td><td>{@link MessagePacker}</td></tr>
* <tr><td>{@link org.msgpack.core.buffer.MessageBufferOutput}</td><td>{@link #newDefaultPacker(MessageBufferOutput)}</td><td>{@link MessagePacker}</td></tr>
* <tr><td>OutputStream</td><td>{@link #newDefaultPacker(OutputStream)}</td><td>{@link MessagePackerImpl}</td></tr>
* <tr><td>WritableByteChannel</td><td>{@link #newDefaultPacker(WritableByteChannel)}</td><td>{@link MessagePackerImpl}</td></tr>
* <tr><td>{@link org.msgpack.core.buffer.MessageBufferOutput}</td><td>{@link #newDefaultPacker(MessageBufferOutput)}</td><td>{@link MessagePackerImpl}</td></tr>
* </table>
*
*/
Expand All @@ -70,7 +71,7 @@ public class MessagePack
public static final Charset UTF8 = Charset.forName("UTF-8");

/**
* Configuration of a {@link MessagePacker} used by {@link #newDefaultPacker(MessageBufferOutput)} and {@link #newDefaultBufferPacker()} methods.
* Configuration of a {@link MessagePackerImpl} used by {@link #newDefaultPacker(MessageBufferOutput)} and {@link #newDefaultBufferPacker()} methods.
*/
public static final PackerConfig DEFAULT_PACKER_CONFIG = new PackerConfig();

Expand All @@ -81,92 +82,94 @@ public class MessagePack

/**
* The prefix code set of MessagePack format. See also https://github.com/msgpack/msgpack/blob/master/spec.md for details.
*
* @deprecated It is here only for compatibility. Use {@link org.msgpack.value.MessagePackCode} instead.
*/
@Deprecated
public static final class Code
{
public static final boolean isFixInt(byte b)
{
int v = b & 0xFF;
return v <= 0x7f || v >= 0xe0;
return MessagePackCode.isFixInt(b);
}

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

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

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

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

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

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

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

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 FIXMAP_PREFIX = MessagePackCode.FIXMAP_PREFIX;
public static final byte FIXARRAY_PREFIX = MessagePackCode.FIXARRAY_PREFIX;
public static final byte FIXSTR_PREFIX = MessagePackCode.FIXSTR_PREFIX;

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 NIL = MessagePackCode.NIL;
public static final byte NEVER_USED = MessagePackCode.NEVER_USED;
public static final byte FALSE = MessagePackCode.FALSE;
public static final byte TRUE = MessagePackCode.TRUE;
public static final byte BIN8 = MessagePackCode.BIN8;
public static final byte BIN16 = MessagePackCode.BIN16;
public static final byte BIN32 = MessagePackCode.BIN32;
public static final byte EXT8 = MessagePackCode.EXT8;
public static final byte EXT16 = MessagePackCode.EXT16;
public static final byte EXT32 = MessagePackCode.EXT32;
public static final byte FLOAT32 = MessagePackCode.FLOAT32;
public static final byte FLOAT64 = MessagePackCode.FLOAT64;
public static final byte UINT8 = MessagePackCode.UINT8;
public static final byte UINT16 = MessagePackCode.UINT16;
public static final byte UINT32 = MessagePackCode.UINT32;
public static final byte UINT64 = MessagePackCode.UINT64;

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 INT8 = MessagePackCode.INT8;
public static final byte INT16 = MessagePackCode.INT16;
public static final byte INT32 = MessagePackCode.INT32;
public static final byte INT64 = MessagePackCode.INT64;

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 FIXEXT1 = MessagePackCode.FIXEXT1;
public static final byte FIXEXT2 = MessagePackCode.FIXEXT2;
public static final byte FIXEXT4 = MessagePackCode.FIXEXT4;
public static final byte FIXEXT8 = MessagePackCode.FIXEXT8;
public static final byte FIXEXT16 = MessagePackCode.FIXEXT16;

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 STR8 = MessagePackCode.STR8;
public static final byte STR16 = MessagePackCode.STR16;
public static final byte STR32 = MessagePackCode.STR32;

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

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

public static final byte NEGFIXINT_PREFIX = (byte) 0xe0;
public static final byte NEGFIXINT_PREFIX = MessagePackCode.NEGFIXINT_PREFIX;

public static final byte EXT_TIMESTAMP = (byte) -1;
public static final byte EXT_TIMESTAMP = MessagePackCode.EXT_TIMESTAMP;
}

private MessagePack()
Expand All @@ -178,31 +181,31 @@ private MessagePack()
* Creates a packer that serializes objects into the specified output.
* <p>
* {@link org.msgpack.core.buffer.MessageBufferOutput} is an interface that lets applications customize memory
* allocation of internal buffer of {@link MessagePacker}. You may prefer {@link #newDefaultBufferPacker()},
* allocation of internal buffer of {@link MessagePackerImpl}. You may prefer {@link #newDefaultBufferPacker()},
* {@link #newDefaultPacker(OutputStream)}, or {@link #newDefaultPacker(WritableByteChannel)} methods instead.
* <p>
* This method is equivalent to <code>DEFAULT_PACKER_CONFIG.newPacker(out)</code>.
*
* @param out A MessageBufferOutput that allocates buffer chunks and receives the buffer chunks with packed data filled in them
* @return A new MessagePacker instance
* @return A new MessagePackerImpl instance
*/
public static MessagePacker newDefaultPacker(MessageBufferOutput out)
public static MessagePackerImpl newDefaultPacker(MessageBufferOutput out)
{
return DEFAULT_PACKER_CONFIG.newPacker(out);
}

/**
* Creates a packer that serializes objects into the specified output stream.
* <p>
* Note that you don't have to wrap OutputStream in BufferedOutputStream because MessagePacker has buffering
* Note that you don't have to wrap OutputStream in BufferedOutputStream because MessagePackerImpl has buffering
* internally.
* <p>
* This method is equivalent to <code>DEFAULT_PACKER_CONFIG.newPacker(out)</code>.
*
* @param out The output stream that receives sequence of bytes
* @return A new MessagePacker instance
* @return A new MessagePackerImpl instance
*/
public static MessagePacker newDefaultPacker(OutputStream out)
public static MessagePackerImpl newDefaultPacker(OutputStream out)
{
return DEFAULT_PACKER_CONFIG.newPacker(out);
}
Expand All @@ -213,9 +216,9 @@ public static MessagePacker newDefaultPacker(OutputStream out)
* This method is equivalent to <code>DEFAULT_PACKER_CONFIG.newPacker(channel)</code>.
*
* @param channel The output channel that receives sequence of bytes
* @return A new MessagePacker instance
* @return A new MessagePackerImpl instance
*/
public static MessagePacker newDefaultPacker(WritableByteChannel channel)
public static MessagePackerImpl newDefaultPacker(WritableByteChannel channel)
{
return DEFAULT_PACKER_CONFIG.newPacker(channel);
}
Expand Down Expand Up @@ -331,7 +334,7 @@ public static MessageUnpacker newDefaultUnpacker(ByteBuffer contents)
}

/**
* MessagePacker configuration.
* MessagePackerImpl configuration.
*/
public static class PackerConfig
implements Cloneable
Expand Down Expand Up @@ -389,26 +392,26 @@ public boolean equals(Object obj)
* Creates a packer that serializes objects into the specified output.
* <p>
* {@link org.msgpack.core.buffer.MessageBufferOutput} is an interface that lets applications customize memory
* allocation of internal buffer of {@link MessagePacker}.
* allocation of internal buffer of {@link MessagePackerImpl}.
*
* @param out A MessageBufferOutput that allocates buffer chunks and receives the buffer chunks with packed data filled in them
* @return A new MessagePacker instance
* @return A new MessagePackerImpl instance
*/
public MessagePacker newPacker(MessageBufferOutput out)
public MessagePackerImpl newPacker(MessageBufferOutput out)
{
return new MessagePacker(out, this);
return new MessagePackerImpl(out, this);
}

/**
* Creates a packer that serializes objects into the specified output stream.
* <p>
* Note that you don't have to wrap OutputStream in BufferedOutputStream because MessagePacker has buffering
* Note that you don't have to wrap OutputStream in BufferedOutputStream because MessagePackerImpl has buffering
* internally.
*
* @param out The output stream that receives sequence of bytes
* @return A new MessagePacker instance
* @return A new MessagePackerImpl instance
*/
public MessagePacker newPacker(OutputStream out)
public MessagePackerImpl newPacker(OutputStream out)
{
return newPacker(new OutputStreamBufferOutput(out, bufferSize));
}
Expand All @@ -417,9 +420,9 @@ public MessagePacker newPacker(OutputStream out)
* Creates a packer that serializes objects into the specified writable channel.
*
* @param channel The output channel that receives sequence of bytes
* @return A new MessagePacker instance
* @return A new MessagePackerImpl instance
*/
public MessagePacker newPacker(WritableByteChannel channel)
public MessagePackerImpl newPacker(WritableByteChannel channel)
{
return newPacker(new ChannelBufferOutput(channel, bufferSize));
}
Expand Down Expand Up @@ -453,7 +456,7 @@ public int getSmallStringOptimizationThreshold()
}

/**
* When the next payload size exceeds this threshold, MessagePacker will call
* When the next payload size exceeds this threshold, MessagePackerImpl will call
* {@link org.msgpack.core.buffer.MessageBufferOutput#flush()} before writing more data (default: 8192).
*/
public PackerConfig withBufferFlushThreshold(int bytes)
Expand Down
Loading