// This file is auto-generated by alef — DO NOT EDIT.
// alef:hash:4e15143f4af1ae8bafbdb1506ef057da924484c66a19483966333558ad437e75
// To regenerate: alef generate
// To verify freshness: alef verify --exit-code
// Issues & docs: https://github.com/kreuzberg-dev/alef
package dev.kreuzberg;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

/**
 * Serialises {@code byte[]} as a JSON array of integers.
 *
 * <p>Jackson's default serialiser encodes {@code byte[]} as a base64 string, but
 * Rust's {@code serde} for {@code Vec<u8>} expects {@code [72, 101, 108, ...]}.
 * Annotate any {@code byte[]} field sent to the FFI layer with
 * {@code @JsonSerialize(using = ByteArrayToIntArraySerializer.class)}.
 */
public class ByteArrayToIntArraySerializer extends StdSerializer<byte[]> {
    /** Default constructor required by Jackson. */
    public ByteArrayToIntArraySerializer() {
        super(byte[].class);
    }

    @Override
    public void serialize(final byte[] value, final JsonGenerator gen,
            final SerializerProvider provider) throws java.io.IOException {
        gen.writeStartArray();
        for (byte b : value) {
            gen.writeNumber(b & 0xFF);
        }
        gen.writeEndArray();
    }
}
