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

Fix some issues for chapter-13 #52

Open
wants to merge 1 commit into
base: 2.0-SNAPSHOT
Choose a base branch
from
Open

Fix some issues for chapter-13 #52

wants to merge 1 commit into from

Conversation

jerryoung
Copy link

    /**
     * Returns a slice of this buffer's sub-region. Modifying the content of
     * the returned buffer or this buffer affects each other's content while
     * they maintain separate indexes and marks.
     * This method does not modify {@code readerIndex} or {@code writerIndex} of
     * this buffer.
     * <p>
     * Also be aware that this method will NOT call {@link #retain()} and so the
     * reference count will NOT be increased.
     */
    public abstract ByteBuf slice(int index, int length);

This method does not modify readerIndex or writerIndex of this buffer.
So we should change from :

        String logMsg = data.slice(idx + 1,
            data.readableBytes()).toString(CharsetUtil.UTF_8);

to:

        String logMsg = data.slice(idx + 1,
            data.readableBytes() - idx - 1).toString(CharsetUtil.UTF_8);

data.readableBytes() - idx - 1 will slice a right length, it will work better.

```java
    /**
     * Returns a slice of this buffer's sub-region. Modifying the content of
     * the returned buffer or this buffer affects each other's content while
     * they maintain separate indexes and marks.
     * This method does not modify {@code readerIndex} or {@code writerIndex} of
     * this buffer.
     * <p>
     * Also be aware that this method will NOT call {@link #retain()} and so the
     * reference count will NOT be increased.
     */
    public abstract ByteBuf slice(int index, int length);
```
 This method does not modify readerIndex or writerIndex of this buffer.
So we should  change from 👍 
        String logMsg = data.slice(idx + 1,
            data.readableBytes()).toString(CharsetUtil.UTF_8);
to:
        String logMsg = data.slice(idx + 1,
            data.readableBytes() - idx - 1).toString(CharsetUtil.UTF_8);
data.readableBytes() - idx - 1 will slice a right length, it will work better.
@jerryoung jerryoung changed the title some issue found by here, about Bytebuf.slice Fix some issues for chapter-13 Feb 6, 2020
@good2luck
Copy link

nice, solved my problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants