class BeatsEncoder {

    public byte[] encode(final BeatsFrame frame) {
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream();

        // Writes the version
        buffer.write(frame.getVersion());

        // Writes the frameType
        buffer.write(frame.getFrameType());

        // Writes the sequence number
        try {
            buffer.write(frame.getPayload());
        } catch (IOException e) {
            throw new BeatsFrameException("Error decoding Beats frame: " + e.getMessage(), e);
        }

        return buffer.toByteArray();
    }

}