<commit_before>package cn.jackq.messenger.network.protocol;

/**
 * Created on: 4/24/17.
 * Creator: <NAME> <<EMAIL>>
 */

public class PeerProtocol {
    public enum PackageType{

    }
    public static class PeerPackage{}

}<commit_msg>add peer protocol in Java<commit_after>package cn.jackq.messenger.network.protocol;

import android.support.annotation.NonNull;

import java.nio.ByteBuffer;

/**
 * Created on: 4/24/17.
 * Creator: <NAME> <<EMAIL>>
 */

public class PeerProtocol {

    public enum PackageType {
        U_SRV_ADDR(0xa1),
        U_SYN(0x01),
        U_ACK(0x02),
        U_DAT(0x03),
        U_END(0x04);

        public final byte value;

        PackageType(int value) {
            this.value = (byte) value;
        }
    }

    public enum DataType {
        AUDIO("audio");

        public final String value;

        DataType(String value) {
            this.value = value;
        }
    }

    public ByteBuffer packServerAddr(String sessionId, String connectId) {
        String header = sessionId + ":" + connectId;
        return getTypeStringBuffer(PackageType.U_SRV_ADDR, header);
    }

    public ByteBuffer packPeerData(String sessionId, DataType dataType, ByteBuffer data) {
        String header = sessionId + ':' + dataType.value + ':';
        ByteBuffer buffer = ByteBuffer.allocate(1 + header.length() + data.limit());
        buffer.put(PackageType.U_DAT.value);
        byte[] headerBytes = header.getBytes();
        buffer.put(headerBytes, 1, headerBytes.length);
        buffer.put(data);
        return buffer;
    }

    public ByteBuffer packPeerSync(String sessionId) {
        return getTypeStringBuffer(PackageType.U_SYN, sessionId);
    }

    public ByteBuffer packPeerAck(String sessionId) {
        return getTypeStringBuffer(PackageType.U_ACK, sessionId);
    }

    public ByteBuffer packPeerEnd(String sessionId) {
        return getTypeStringBuffer(PackageType.U_END, sessionId);
    }

    @NonNull
    private ByteBuffer getTypeStringBuffer(PackageType type, String sessionId) {
        ByteBuffer buffer = ByteBuffer.allocate(sessionId.length() + 1);
        buffer.put(type.value);
        buffer.put(sessionId.getBytes());
        return buffer;
    }

}
{'fraction_non_alphanumeric': 0.10656474820143885, 'fraction_numerical': 0.012140287769784174, 'mean_word_length': 2.752107925801012, 'pattern_counts': {'":': 1, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5110142', 'n_tokens_mistral': 691, 'n_tokens_neox': 656, 'n_words': 142}