package com.hyd.ssdb.protocol;

import com.hyd.ssdb.util.Bytes;
import java.nio.charset.Charset;

/**
 * 一个区块。当发送区块时，按照 '长度\n内容\n' 的格式发送
 * created at 15-11-30
 *
 * @author Yiding
 */
public class Block {

    private byte[] data;

    public Block(byte[] data) {
        this.data = data;
    }

    /**
     * 生成要发送的字节串
     *
     * @return 要发送的字节串
     */
    public byte[] toBytes() {
        byte[] length = (data.length + "\n").getBytes();
        return Bytes.concat(length, data, new byte[]{'\n'});
    }

    public byte[] getData() {
        return data;
    }

    public String toString(Charset charset) {
        return new String(this.data, charset);
    }
}

@@ -93,16 +93,59 @@
 harset;%0D
+%0Aimport java.nio.charset.StandardCharsets;%0D
 %0A%0D%0A/**%0D%0A
@@ -744,12 +744,118 @@
 %0D%0A    %7D%0D
+%0A%0D%0A    @Override%0D%0A    public String toString() %7B%0D%0A        return toString(StandardCharsets.UTF_8);%0D%0A    %7D%0D
 %0A%7D%0D%0A

add toString() to Block