package cn.jackq.messenger.network.protocol;

/**
 * Created on: 4/24/17.
 * Creator: Jack Q <qiaobo@outlook.com>
 */

public class PeerProtocol {
    public enum PackageType{

    }
    public static class PeerPackage{}

}

@@ -39,16 +39,89 @@
 tocol;%0A%0A
+import android.support.annotation.NonNull;%0A%0Aimport java.nio.ByteBuffer;%0A%0A
 /**%0A * C
@@ -213,16 +213,17 @@
 tocol %7B%0A
+%0A
     publ
@@ -245,53 +245,1713 @@
 Type
+ 
 %7B%0A
-%0A    %7D%0A    public static class PeerPackage%7B
+        U_SRV_ADDR(0xa1),%0A        U_SYN(0x01),%0A        U_ACK(0x02),%0A        U_DAT(0x03),%0A        U_END(0x04);%0A%0A        public final byte value;%0A%0A        PackageType(int value) %7B%0A            this.value = (byte) value;%0A        %7D%0A    %7D%0A%0A    public enum DataType %7B%0A        AUDIO(%22audio%22);%0A%0A        public final String value;%0A%0A        DataType(String value) %7B%0A            this.value = value;%0A        %7D%0A    %7D%0A%0A    public ByteBuffer packServerAddr(String sessionId, String connectId) %7B%0A        String header = sessionId + %22:%22 + connectId;%0A        return getTypeStringBuffer(PackageType.U_SRV_ADDR, header);%0A    %7D%0A%0A    public ByteBuffer packPeerData(String sessionId, DataType dataType, ByteBuffer data) %7B%0A        String header = sessionId + ':' + dataType.value + ':';%0A        ByteBuffer buffer = ByteBuffer.allocate(1 + header.length() + data.limit());%0A        buffer.put(PackageType.U_DAT.value);%0A        byte%5B%5D headerBytes = header.getBytes();%0A        buffer.put(headerBytes, 1, headerBytes.length);%0A        buffer.put(data);%0A        return buffer;%0A    %7D%0A%0A    public ByteBuffer packPeerSync(String sessionId) %7B%0A        return getTypeStringBuffer(PackageType.U_SYN, sessionId);%0A    %7D%0A%0A    public ByteBuffer packPeerAck(String sessionId) %7B%0A        return getTypeStringBuffer(PackageType.U_ACK, sessionId);%0A    %7D%0A%0A    public ByteBuffer packPeerEnd(String sessionId) %7B%0A        return getTypeStringBuffer(PackageType.U_END, sessionId);%0A    %7D%0A%0A    @NonNull%0A    private ByteBuffer getTypeStringBuffer(PackageType type, String sessionId) %7B%0A        ByteBuffer buffer = ByteBuffer.allocate(sessionId.length() + 1);%0A        buffer.put(type.value);%0A        buffer.put(sessionId.getBytes());%0A        return buffer;%0A    
 %7D%0A%0A%7D

add peer protocol in Java