// Path: copybook4java/src/main/java/com/nordea/oss/ByteUtils.java
// public class ByteUtils {
// 
//     public static boolean allEquals(byte[] array, byte value, int offset, int maxLength) {
//         maxLength = Math.min(offset + maxLength, array.length);
//         for(int i = offset; i < maxLength; i++) {
//             if(array[i] != value) {
//                 return false;
//             }
//         }
//         return true;
//     }
// 
//     public static int indexOf(byte[] array, byte needle, int offset, int maxLength) {
//         int result = -1;
//         maxLength = Math.min(offset + maxLength, array.length);
//         for(int i = offset; i < maxLength; i++) {
//             if(array[i] == needle) {
//                 result = i;
//                 break;
//             }
//         }
//         return result;
//     }
// 
//     public static byte[] trim(byte[] src, byte padding, boolean right, int minLength) {
//         if(src.length < minLength) {
//             throw new RuntimeException("src array is smaller than minLength: " + src.length + " < " + minLength);
//         }
//         if(right) {
//             int offset;
//             for (offset = src.length - 1; offset > minLength - 1; offset--) {  // [44, 32]
//                 if(padding != src[offset]) {
//                     break;
//                 }
//             }
//             if(offset < 0) {
//                 return new byte[0];
//             } else if (offset < src.length - 1){
//                 return Arrays.copyOfRange(src, 0, offset + 1);
//             }
// 
//         } else {
//             int offset;
//             for (offset = 0; offset < src.length - minLength; offset++) {
//                 if(padding != src[offset]) {
//                     break;
//                 }
//             }
//             if(offset == src.length) {
//                 return new byte[0];
//             } else if(offset > 0) {
//                 return Arrays.copyOfRange(src, offset, src.length);
//             }
//         }
// 
//         return src;
//     }
// 
//     public static byte[] toByteArray(InputStream inputStream) throws IOException {
//         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// 
//         byte[] buf = new byte[8192];
//         while(true) {
//             int r = inputStream.read(buf);
//             if(r == -1) {
//                 break;
//             }
//             outputStream.write(buf, 0, r);
//         }
// 
//         return outputStream.toByteArray();
//     }
// }
// 
// Path: copybook4java/src/main/java/com/nordea/oss/copybook/exceptions/CopyBookException.java
// public class CopyBookException extends RuntimeException {
//     private static final long serialVersionUID = 28118369047109260L;
//     public CopyBookException(String message) {
//         super(message);
//     }
// 
//     public CopyBookException(String message, TypeConverterException ex) {
//         super(message + ": " + ex.getClass().getSimpleName() + " :" + ex.getMessage());
//     }
// 
//     public CopyBookException(String message, Exception ex) {
//         super(message + ": " + ex.getClass().getSimpleName() + " :" + ex.getMessage());
//     }
// }


import com.nordea.oss.ByteUtils;
import com.nordea.oss.copybook.exceptions.CopyBookException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.List;
                writeField(buffer, field, field.getObject(rootObj), last);
            }
        }
    }

    private void writeField(PackedBuffer buffer, CopyBookField field, Object valueObj, boolean last) {
        if(field.getLevel() == 0) {
            buffer.put(field.getBytes(null, valueObj, false), true); // No padding with separator

        } else if(last) {
            byte[] valueBytes = field.getBytes(null, valueObj, false); // Don't pad if it's the last field
            if(valueBytes == null) {
                valueBytes = field.getBytes(null, valueObj, true); // Except if it's null
            }
            buffer.put(valueBytes, true); // With separator

        } else {
            buffer.put(field.getBytes(null, valueObj, true), false); // With padding without separator
        }
    }

    @Override
    public <T> T deserialize(byte[] bytes, Class<T> type) {
        try {
            T obj = type.newInstance();
            PackedBuffer buffer = new PackedBuffer(bytes, this.maxBitmapSize, this.bitmapBlockSize, this.separatorByte);
            readFields(this.fields, buffer, obj, true);
            return obj;

        } catch (IllegalAccessException | InstantiationException e) {
// Path: copybook4java/src/main/java/com/nordea/oss/ByteUtils.java
// public class ByteUtils {
// 
//     public static boolean allEquals(byte[] array, byte value, int offset, int maxLength) {
//         maxLength = Math.min(offset + maxLength, array.length);
//         for(int i = offset; i < maxLength; i++) {
//             if(array[i] != value) {
//                 return false;
//             }
//         }
//         return true;
//     }
// 
//     public static int indexOf(byte[] array, byte needle, int offset, int maxLength) {
//         int result = -1;
//         maxLength = Math.min(offset + maxLength, array.length);
//         for(int i = offset; i < maxLength; i++) {
//             if(array[i] == needle) {
//                 result = i;
//                 break;
//             }
//         }
//         return result;
//     }
// 
//     public static byte[] trim(byte[] src, byte padding, boolean right, int minLength) {
//         if(src.length < minLength) {
//             throw new RuntimeException("src array is smaller than minLength: " + src.length + " < " + minLength);
//         }
//         if(right) {
//             int offset;
//             for (offset = src.length - 1; offset > minLength - 1; offset--) {  // [44, 32]
//                 if(padding != src[offset]) {
//                     break;
//                 }
//             }
//             if(offset < 0) {
//                 return new byte[0];
//             } else if (offset < src.length - 1){
//                 return Arrays.copyOfRange(src, 0, offset + 1);
//             }
// 
//         } else {
//             int offset;
//             for (offset = 0; offset < src.length - minLength; offset++) {
//                 if(padding != src[offset]) {
//                     break;
//                 }
//             }
//             if(offset == src.length) {
//                 return new byte[0];
//             } else if(offset > 0) {
//                 return Arrays.copyOfRange(src, offset, src.length);
//             }
//         }
// 
//         return src;
//     }
// 
//     public static byte[] toByteArray(InputStream inputStream) throws IOException {
//         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// 
//         byte[] buf = new byte[8192];
//         while(true) {
//             int r = inputStream.read(buf);
//             if(r == -1) {
//                 break;
//             }
//             outputStream.write(buf, 0, r);
//         }
// 
//         return outputStream.toByteArray();
//     }
// }
// 
// Path: copybook4java/src/main/java/com/nordea/oss/copybook/exceptions/CopyBookException.java
// public class CopyBookException extends RuntimeException {
//     private static final long serialVersionUID = 28118369047109260L;
//     public CopyBookException(String message) {
//         super(message);
//     }
// 
//     public CopyBookException(String message, TypeConverterException ex) {
//         super(message + ": " + ex.getClass().getSimpleName() + " :" + ex.getMessage());
//     }
// 
//     public CopyBookException(String message, Exception ex) {
//         super(message + ": " + ex.getClass().getSimpleName() + " :" + ex.getMessage());
//     }
// }


// Path: copybook4java/src/main/java/com/nordea/oss/copybook/serializers/PackedFirstLevelMapper.java
import com.nordea.oss.ByteUtils;
import com.nordea.oss.copybook.exceptions.CopyBookException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.List;

                writeField(buffer, field, field.getObject(rootObj), last);
            }
        }
    }

    private void writeField(PackedBuffer buffer, CopyBookField field, Object valueObj, boolean last) {
        if(field.getLevel() == 0) {
            buffer.put(field.getBytes(null, valueObj, false), true); // No padding with separator

        } else if(last) {
            byte[] valueBytes = field.getBytes(null, valueObj, false); // Don't pad if it's the last field
            if(valueBytes == null) {
                valueBytes = field.getBytes(null, valueObj, true); // Except if it's null
            }
            buffer.put(valueBytes, true); // With separator

        } else {
            buffer.put(field.getBytes(null, valueObj, true), false); // With padding without separator
        }
    }

    @Override
    public <T> T deserialize(byte[] bytes, Class<T> type) {
        try {
            T obj = type.newInstance();
            PackedBuffer buffer = new PackedBuffer(bytes, this.maxBitmapSize, this.bitmapBlockSize, this.separatorByte);
            readFields(this.fields, buffer, obj, true);
            return obj;

        } catch (IllegalAccessException | InstantiationException e) {
            throw new CopyBookException("Failed to create new object", e);