{"action":"opened","issue":{"url":"https://api.github.com/repos/netty/netty/issues/9422","repository_url":"https://api.github.com/repos/netty/netty","labels_url":"https://api.github.com/repos/netty/netty/issues/9422/labels{/name}","comments_url":"https://api.github.com/repos/netty/netty/issues/9422/comments","events_url":"https://api.github.com/repos/netty/netty/issues/9422/events","html_url":"https://github.com/netty/netty/issues/9422","id":476441520,"node_id":"MDU6SXNzdWU0NzY0NDE1MjA=","number":9422,"title":"LengthFieldPrepender.encode","user":{"login":"huyechao","id":12667568,"node_id":"MDQ6VXNlcjEyNjY3NTY4","avatar_url":"https://avatars1.githubusercontent.com/u/12667568?v=4","gravatar_id":"","url":"https://api.github.com/users/huyechao","html_url":"https://github.com/huyechao","followers_url":"https://api.github.com/users/huyechao/followers","following_url":"https://api.github.com/users/huyechao/following{/other_user}","gists_url":"https://api.github.com/users/huyechao/gists{/gist_id}","starred_url":"https://api.github.com/users/huyechao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huyechao/subscriptions","organizations_url":"https://api.github.com/users/huyechao/orgs","repos_url":"https://api.github.com/users/huyechao/repos","events_url":"https://api.github.com/users/huyechao/events{/privacy}","received_events_url":"https://api.github.com/users/huyechao/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-08-03T11:09:47Z","updated_at":"2019-08-03T11:09:47Z","closed_at":null,"author_association":"NONE","body":"### Why in the LengthFieldPrepender, memory copy must occur once for write length,I think I can provide a way to write the length to the specified position.\r\n\r\n\r\n\r\n@Override\r\n    protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {\r\n        int length = msg.readableBytes() + lengthAdjustment;\r\n        if (lengthIncludesLengthFieldLength) {\r\n            length += lengthFieldLength;\r\n        }\r\n\r\n        if (length < 0) {\r\n            throw new IllegalArgumentException(\r\n                    \"Adjusted frame length (\" + length + \") is less than zero\");\r\n        }\r\n\r\n        switch (lengthFieldLength) {\r\n        case 1:\r\n            if (length >= 256) {\r\n                throw new IllegalArgumentException(\r\n                        \"length does not fit into a byte: \" + length);\r\n            }\r\n            out.writeByte((byte) length);\r\n            break;\r\n        case 2:\r\n            if (length >= 65536) {\r\n                throw new IllegalArgumentException(\r\n                        \"length does not fit into a short integer: \" + length);\r\n            }\r\n            out.writeShort((short) length);\r\n            break;\r\n        case 3:\r\n            if (length >= 16777216) {\r\n                throw new IllegalArgumentException(\r\n                        \"length does not fit into a medium integer: \" + length);\r\n            }\r\n            out.writeMedium(length);\r\n            break;\r\n        case 4:\r\n            out.writeInt(length);\r\n            break;\r\n        case 8:\r\n            out.writeLong(length);\r\n            break;\r\n        default:\r\n            throw new Error(\"should not reach here\");\r\n        }\r\n\r\n        out.writeBytes(msg, msg.readerIndex(), msg.readableBytes());\r\n    }\r\n\r\n\r\n"}}
{"actor":{"display_login":"huyechao"}}