Repository navigation
provides set of fixes and test for tuple byte buffs #739
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
176 changes: 176 additions & 0 deletions
176
rsocket-core/src/main/java/io/rsocket/buffer/AbstractReadOnlyReferenceCountedByteBuf.java
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 |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| package io.rsocket.buffer; | ||
|
|
||
| import io.netty.buffer.AbstractReferenceCountedByteBuf; | ||
| import io.netty.buffer.ByteBuf; | ||
| import java.io.InputStream; | ||
| import java.nio.ByteBuffer; | ||
| import java.nio.ReadOnlyBufferException; | ||
| import java.nio.channels.FileChannel; | ||
| import java.nio.channels.ScatteringByteChannel; | ||
|
|
||
| abstract class AbstractReadOnlyReferenceCountedByteBuf extends AbstractReferenceCountedByteBuf { | ||
|
|
||
| AbstractReadOnlyReferenceCountedByteBuf(int maxCapacity) { | ||
| super(maxCapacity); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isReadOnly() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isWritable() { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isWritable(int numBytes) { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public int ensureWritable(int minWritableBytes, boolean force) { | ||
| return 1; | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuf ensureWritable(int minWritableBytes) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuf discardReadBytes() { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuf setBytes(int index, byte[] src, int srcIndex, int length) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuf setBytes(int index, ByteBuffer src) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuf setByte(int index, int value) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void _setByte(int index, int value) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuf setShort(int index, int value) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void _setShort(int index, int value) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuf setShortLE(int index, int value) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void _setShortLE(int index, int value) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuf setMedium(int index, int value) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void _setMedium(int index, int value) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuf setMediumLE(int index, int value) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void _setMediumLE(int index, int value) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuf setInt(int index, int value) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void _setInt(int index, int value) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuf setIntLE(int index, int value) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void _setIntLE(int index, int value) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuf setLong(int index, long value) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void _setLong(int index, long value) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuf setLongLE(int index, long value) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void _setLongLE(int index, long value) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| public int setBytes(int index, InputStream in, int length) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| public int setBytes(int index, ScatteringByteChannel in, int length) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| public int setBytes(int index, FileChannel in, long position, int length) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuf capacity(int newCapacity) { | ||
| throw new ReadOnlyBufferException(); | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuf asReadOnly() { | ||
| return this; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The netty docs deprecated similar classes and suggest using Unpooled.wrappedUnmodifiableBuffer. Also the docs call out slice as an issue, how is this handled?
https://netty.io/4.1/api/io/netty/buffer/Unpooled.html#wrappedUnmodifiableBuffer-io.netty.buffer.ByteBuf...-
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is deprecated but there are no other options to extend. TupledByteBuf designed to be readOnly and I don't wanna create few more objects to runtime just in order to use what netty gives. therefore I mimic the same what readonly bytebuf does