Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: msgpack/msgpack-java
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7e59e496fc1c233d06f0172ceaceefd100469017
Choose a base ref
..
head repository: msgpack/msgpack-java
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 56ac516c03b35f61420ff8df3c0b2729c1d88090
Choose a head ref
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
* MessageBufferInput adapter for byte arrays
*/
public class ArrayBufferInput
implements MessageBufferInput
implements MessageBufferInput<byte[]>
{
private MessageBuffer buffer;
private boolean isEmpty;
@@ -66,9 +66,14 @@ public MessageBuffer reset(MessageBuffer buf)
return old;
}

public void reset(byte[] arr)
@Override
public byte[] reset(byte[] arr)
{
reset(MessageBuffer.wrap(checkNotNull(arr, "input array is null")));
final MessageBuffer messageBuffer = reset(MessageBuffer.wrap(checkNotNull(arr, "input array is null")));
if (messageBuffer == null) {
return null;
}
return messageBuffer.array();
}

public void reset(byte[] arr, int offset, int len)
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@
* {@link MessageBufferInput} adapter for {@link java.nio.ByteBuffer}
*/
public class ByteBufferInput
implements MessageBufferInput
implements MessageBufferInput<ByteBuffer>
{
private ByteBuffer input;
private boolean isRead = false;
@@ -39,6 +39,7 @@ public ByteBufferInput(ByteBuffer input)
* @param input new buffer
* @return the old buffer
*/
@Override
public ByteBuffer reset(ByteBuffer input)
{
ByteBuffer old = this.input;
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
* {@link MessageBufferInput} adapter for {@link java.nio.channels.ReadableByteChannel}
*/
public class ChannelBufferInput
implements MessageBufferInput
implements MessageBufferInput<ReadableByteChannel>
{
private ReadableByteChannel channel;
private final MessageBuffer buffer;
@@ -49,8 +49,8 @@ public ChannelBufferInput(ReadableByteChannel channel, int bufferSize)
* @param channel new channel
* @return the old resource
*/
@Override
public ReadableByteChannel reset(ReadableByteChannel channel)
throws IOException
{
ReadableByteChannel old = this.channel;
this.channel = channel;
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
* {@link MessageBufferInput} adapter for {@link InputStream}
*/
public class InputStreamBufferInput
implements MessageBufferInput
implements MessageBufferInput<InputStream>
{
private InputStream in;
private final byte[] buffer;
@@ -60,6 +60,7 @@ public InputStreamBufferInput(InputStream in, int bufferSize)
* @param in new stream
* @return the old resource
*/
@Override
public InputStream reset(InputStream in)
{
InputStream old = this.in;
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
* A MessageBufferInput implementation has control of lifecycle of the memory so that it can reuse previously
* allocated memory, use memory pools, or use memory-mapped files.
*/
public interface MessageBufferInput
public interface MessageBufferInput<T>
extends Closeable
{
/**
@@ -40,6 +40,8 @@ public interface MessageBufferInput
MessageBuffer next()
throws IOException;

T reset(T input);

/**
* Closes the input.
* <p>
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
* {@link MessageBufferInput} adapter for {@link MessageBufferInput} Enumeration
*/
public class SequenceMessageBufferInput
implements MessageBufferInput
implements MessageBufferInput<Void>
{
private Enumeration<? extends MessageBufferInput> sequence;
private MessageBufferInput input;
@@ -54,6 +54,11 @@ public MessageBuffer next() throws IOException
return buffer;
}

@Override
public Void reset(Void input) {
throw new UnsupportedOperationException("reset");
}

private void nextInput() throws IOException
{
if (input != null) {
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ import scala.jdk.CollectionConverters._
import scala.util.Random

object MessageUnpackerTest {
class SplitMessageBufferInput(array: Array[Array[Byte]]) extends MessageBufferInput {
class SplitMessageBufferInput(array: Array[Array[Byte]]) extends MessageBufferInput[Void] {
var cursor = 0
override def next(): MessageBuffer = {
if (cursor < array.length) {
@@ -41,6 +41,9 @@ object MessageUnpackerTest {
}
}


override def reset(input: Void): Void = throw new UnsupportedOperationException("reset")

override def close(): Unit = {}
}
}
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ class ByteStringTest extends AirSpec {
private val byteString = ByteString(createMessagePackData(_.packString(unpackedString)))

private def unpackString(messageBuffer: MessageBuffer) = {
val input = new MessageBufferInput {
val input = new MessageBufferInput[Void] {

private var isRead = false

@@ -38,6 +38,8 @@ class ByteStringTest extends AirSpec {
messageBuffer
}
override def close(): Unit = {}

override def reset(input: Void): Void = throw new UnsupportedOperationException("reset")
}

MessagePack.newDefaultUnpacker(input).unpackString()
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// MessagePack for Java
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.jackson.dataformat;

import org.msgpack.core.buffer.MessageBufferInput;

public interface MessageBufferInputLocator
{
MessageBufferInput get(Class clazz);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// MessagePack for Java
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.jackson.dataformat;

import org.msgpack.core.buffer.MessageBufferInput;

interface MessageBufferInputProvider
{
MessageBufferInput provide();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// MessagePack for Java
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.jackson.dataformat;

import org.msgpack.core.buffer.MessageBufferInput;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class MessageBufferInputRegistry implements MessageBufferInputLocator
{
private final Map<Class, MessageBufferInput> messageBufferInputMap = new HashMap<>(1);

@Override
public MessageBufferInput get(Class clazz)
{
return messageBufferInputMap.get(clazz);
}

public boolean register(Class clazz, MessageBufferInputProvider provider)
{
Objects.requireNonNull(clazz, "clazz");
Objects.requireNonNull(provider, "provider");

if (messageBufferInputMap.containsKey(clazz)) {
return false;
}

messageBufferInputMap.put(clazz, provider.provide());
return true;
}
}
Original file line number Diff line number Diff line change
@@ -40,8 +40,6 @@ public class MessagePackFactory
private final MessagePack.PackerConfig packerConfig;
private boolean reuseResourceInGenerator = true;
private boolean reuseResourceInParser = true;
private boolean reuseInputStreamBufferInput = true;

private ExtensionTypeCustomDeserializers extTypeCustomDesers;

public MessagePackFactory()
@@ -60,7 +58,6 @@ public MessagePackFactory(MessagePackFactory src)
this.packerConfig = src.packerConfig.clone();
this.reuseResourceInGenerator = src.reuseResourceInGenerator;
this.reuseResourceInParser = src.reuseResourceInParser;
this.reuseInputStreamBufferInput = src.reuseInputStreamBufferInput;
if (src.extTypeCustomDesers != null) {
this.extTypeCustomDesers = new ExtensionTypeCustomDeserializers(src.extTypeCustomDesers);
}
@@ -78,12 +75,6 @@ public MessagePackFactory setReuseResourceInParser(boolean reuseResourceInParser
return this;
}

public MessagePackFactory setReuseInputStreamBufferInput(boolean reuseInputStreamBufferInput)
{
this.reuseInputStreamBufferInput = reuseInputStreamBufferInput;
return this;
}

public MessagePackFactory setExtTypeCustomDesers(ExtensionTypeCustomDeserializers extTypeCustomDesers)
{
this.extTypeCustomDesers = extTypeCustomDesers;
@@ -176,12 +167,6 @@ boolean isReuseResourceInParser()
return reuseResourceInParser;
}

@VisibleForTesting
boolean isReuseInputStreamBufferInput()
{
return reuseInputStreamBufferInput;
}

@VisibleForTesting
ExtensionTypeCustomDeserializers getExtTypeCustomDesers()
{
Loading