hefeixia
2021-02-18 5b8c95c760840f09910730943b21391e47187315
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package chat.server;
 
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
 
import java.io.UnsupportedEncodingException;
 
import cn.wildfirechat.common.ErrorCode;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
 
public class Test {
 
    public static void main(String[] args) throws UnsupportedEncodingException {
        ByteBuf ackPayload = Unpooled.buffer(1);
        ErrorCode errorCode = ERROR_CODE_SUCCESS;
        ackPayload.ensureWritable(1).writeByte(errorCode.getCode());
        ackPayload.setByte(0, errorCode.getCode());
        
        byte[] bytes = ackPayload.array();
        String value = new String(bytes, "UTF-8");
        System.out.println(value);
    }
}