class SimpleStructConverter implements StructConverter {

    @Override
    public final byte[] convert(final Struct struct) {

        // using output stream resources, serialize the specified struct
        try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream)) {

            // obtain the struct elements definition
            StructElements structElements = struct.getClass().getAnnotation(StructElements.class);

            // ensure that the class is properly documented
            if (structElements == null) {
                throw new StructConversionException(String.format(
                        "%s does not have the proper @StructElements definition on the class "
                                + "type. Please see documentation on Struct interface",
                        struct.getClass().getSimpleName()));
            }

            // iterate over the defined elements
            for (String fieldName : structElements.elements()) {

                // grab the field
                Field field = struct.getClass().getDeclaredField(fieldName);

                // ensure the field is accessible
                field.setAccessible(true);

                // obtain the value from the field
                final Object value = FieldUtils.readField(field, struct);

                // process the field according to its type
                if (Struct.class.isAssignableFrom(field.getType())) {
                    if (value == null) {
                        continue;
                    }
                    dataOutputStream.write(convert((Struct) value));
                } else if (int.class.isAssignableFrom(field.getType())) {
                    dataOutputStream.writeInt((int) value);
                } else if (short.class.isAssignableFrom(field.getType())) {
                    dataOutputStream.writeShort((short) value);
                } else if (byte[].class.isAssignableFrom(field.getType())) {
                    dataOutputStream.write((byte[]) value);
                } else if (byte.class.isAssignableFrom(field.getType())) {
                    dataOutputStream.writeByte((byte) value);
                } else {
                    throw new StructConversionException(
                            "Unsupported field type for element or length: " + field.getType());
                }

                // re-enforce the access checking
                field.setAccessible(false);
            }

            // flush out the stream
            dataOutputStream.flush();

            // return the written byte array
            return byteArrayOutputStream.toByteArray();

        } catch (IOException | IllegalAccessException | NoSuchFieldException e) {
            throw new StructConversionException(
                    String.format("Unexpected error converting %s into a struct: %s",
                            struct.getClass().getSimpleName(), e.getMessage()), e);
        }

    }

}