FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

add MessagePacker.clear() method to clear position by isopov · Pull Request #459 · msgpack/msgpack-java · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (3) .scala  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ private ArrayBufferOutput getArrayBufferOut()
return (ArrayBufferOutput) out;
}

/**
* Clears the written data.
*/
@Override
public void clear()
{
super.clear();
getArrayBufferOut().clear();
}

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ public long getTotalWrittenBytes()
return totalFlushBytes + position;
}

/**
* Clears the written data.
*/
public void clear()
{
position = 0;
}

/**
* Flushes internal buffer to the underlying output.
* <p>
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
public class ArrayBufferOutput
implements MessageBufferOutput
{
private List<MessageBuffer> list;
private final List<MessageBuffer> list;
private final int bufferSize;
private MessageBuffer lastBuffer;
private int bufferSize;

public ArrayBufferOutput()
{
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.msgpack.core

import java.io.ByteArrayOutputStream
import java.util.Arrays

import org.msgpack.value.ValueFactory._

Expand All @@ -32,5 +33,19 @@ class MessageBufferPackerTest extends MessagePackSpec {

packer1.toByteArray shouldBe stream.toByteArray
}

"clear unflushed" in {
val packer = MessagePack.newDefaultBufferPacker
packer.packInt(1);
packer.clear();
packer.packInt(2);

packer.toByteArray shouldBe Array(2)
val buffer = packer.toBufferList().get(0)
buffer.toByteArray() shouldBe Array(2)
val array = Arrays.copyOf(buffer.sliceAsByteBuffer().array(), buffer.size())
array shouldBe Array(2)
}

}
}

Back | FazBrowse Home | New Git URL