private byte[] writeField(TKey<?, ?> key, List<QualifiedValue<?>> values) {
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        CodedOutputStream output = CodedOutputStream.newInstance(bout);
        try {
            Integer id = converterFactory.getEncodedKey(key);
            if (id != null) {
                output.writeString(FIELD_KEY, id.toString());
            } else {
                output.writeString(FIELD_KEY, key.toString());
            }

            for (QualifiedValue<?> value : values) {
                byte[] bytes = writeEntry(value);
                ByteString b = ByteString.copyFrom(bytes);
                output.writeBytes(FIELD_ENTRY, b);
            }
            output.flush();
        } catch (IOException e) {
            throw new RuntimeException("Could not write key '" + key.getFullName()
                    + "' to byte array!", e);
        } finally {
            try {
                bout.close();
            } catch (IOException e) {
                throw new RuntimeException("Could not close output stream!", e);
            }
        }
        return bout.toByteArray();
    }