All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.bechberger.ebpf.bpf.raw.bpf_devmap_val Maven / Gradle / Ivy

The newest version!
// Generated by jextract

package me.bechberger.ebpf.bpf.raw;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.nio.ByteOrder;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.MemoryLayout.PathElement.*;

/**
 * {@snippet lang=c :
 * struct bpf_devmap_val {
 *     __u32 ifindex;
 *     union {
 *         int fd;
 *         __u32 id;
 *     } bpf_prog;
 * }
 * }
 */
public class bpf_devmap_val {

    bpf_devmap_val() {
        // Should not be called directly
    }

    private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
        Lib.C_INT.withName("ifindex"),
        bpf_devmap_val.bpf_prog.layout().withName("bpf_prog")
    ).withName("bpf_devmap_val");

    /**
     * The layout of this struct
     */
    public static final GroupLayout layout() {
        return $LAYOUT;
    }

    private static final OfInt ifindex$LAYOUT = (OfInt)$LAYOUT.select(groupElement("ifindex"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * __u32 ifindex
     * }
     */
    public static final OfInt ifindex$layout() {
        return ifindex$LAYOUT;
    }

    private static final long ifindex$OFFSET = 0;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * __u32 ifindex
     * }
     */
    public static final long ifindex$offset() {
        return ifindex$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * __u32 ifindex
     * }
     */
    public static int ifindex(MemorySegment struct) {
        return struct.get(ifindex$LAYOUT, ifindex$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * __u32 ifindex
     * }
     */
    public static void ifindex(MemorySegment struct, int fieldValue) {
        struct.set(ifindex$LAYOUT, ifindex$OFFSET, fieldValue);
    }

    /**
     * {@snippet lang=c :
     * union {
     *     int fd;
     *     __u32 id;
     * }
     * }
     */
    public static class bpf_prog {

        bpf_prog() {
            // Should not be called directly
        }

        private static final GroupLayout $LAYOUT = MemoryLayout.unionLayout(
            Lib.C_INT.withName("fd"),
            Lib.C_INT.withName("id")
        ).withName("$anon$6460:2");

        /**
         * The layout of this union
         */
        public static final GroupLayout layout() {
            return $LAYOUT;
        }

        private static final OfInt fd$LAYOUT = (OfInt)$LAYOUT.select(groupElement("fd"));

        /**
         * Layout for field:
         * {@snippet lang=c :
         * int fd
         * }
         */
        public static final OfInt fd$layout() {
            return fd$LAYOUT;
        }

        private static final long fd$OFFSET = 0;

        /**
         * Offset for field:
         * {@snippet lang=c :
         * int fd
         * }
         */
        public static final long fd$offset() {
            return fd$OFFSET;
        }

        /**
         * Getter for field:
         * {@snippet lang=c :
         * int fd
         * }
         */
        public static int fd(MemorySegment union) {
            return union.get(fd$LAYOUT, fd$OFFSET);
        }

        /**
         * Setter for field:
         * {@snippet lang=c :
         * int fd
         * }
         */
        public static void fd(MemorySegment union, int fieldValue) {
            union.set(fd$LAYOUT, fd$OFFSET, fieldValue);
        }

        private static final OfInt id$LAYOUT = (OfInt)$LAYOUT.select(groupElement("id"));

        /**
         * Layout for field:
         * {@snippet lang=c :
         * __u32 id
         * }
         */
        public static final OfInt id$layout() {
            return id$LAYOUT;
        }

        private static final long id$OFFSET = 0;

        /**
         * Offset for field:
         * {@snippet lang=c :
         * __u32 id
         * }
         */
        public static final long id$offset() {
            return id$OFFSET;
        }

        /**
         * Getter for field:
         * {@snippet lang=c :
         * __u32 id
         * }
         */
        public static int id(MemorySegment union) {
            return union.get(id$LAYOUT, id$OFFSET);
        }

        /**
         * Setter for field:
         * {@snippet lang=c :
         * __u32 id
         * }
         */
        public static void id(MemorySegment union, int fieldValue) {
            union.set(id$LAYOUT, id$OFFSET, fieldValue);
        }

        /**
         * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
         * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
         */
        public static MemorySegment asSlice(MemorySegment array, long index) {
            return array.asSlice(layout().byteSize() * index);
        }

        /**
         * The size (in bytes) of this union
         */
        public static long sizeof() { return layout().byteSize(); }

        /**
         * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
         */
        public static MemorySegment allocate(SegmentAllocator allocator) {
            return allocator.allocate(layout());
        }

        /**
         * Allocate an array of size {@code elementCount} using {@code allocator}.
         * The returned segment has size {@code elementCount * layout().byteSize()}.
         */
        public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
            return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
        }

        /**
         * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
         * The returned segment has size {@code layout().byteSize()}
         */
        public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) {
            return reinterpret(addr, 1, arena, cleanup);
        }

        /**
         * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
         * The returned segment has size {@code elementCount * layout().byteSize()}
         */
        public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) {
            return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
        }
    }

    private static final GroupLayout bpf_prog$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("bpf_prog"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * union {
     *     int fd;
     *     __u32 id;
     * } bpf_prog
     * }
     */
    public static final GroupLayout bpf_prog$layout() {
        return bpf_prog$LAYOUT;
    }

    private static final long bpf_prog$OFFSET = 4;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * union {
     *     int fd;
     *     __u32 id;
     * } bpf_prog
     * }
     */
    public static final long bpf_prog$offset() {
        return bpf_prog$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * union {
     *     int fd;
     *     __u32 id;
     * } bpf_prog
     * }
     */
    public static MemorySegment bpf_prog(MemorySegment struct) {
        return struct.asSlice(bpf_prog$OFFSET, bpf_prog$LAYOUT.byteSize());
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * union {
     *     int fd;
     *     __u32 id;
     * } bpf_prog
     * }
     */
    public static void bpf_prog(MemorySegment struct, MemorySegment fieldValue) {
        MemorySegment.copy(fieldValue, 0L, struct, bpf_prog$OFFSET, bpf_prog$LAYOUT.byteSize());
    }

    /**
     * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
     * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
     */
    public static MemorySegment asSlice(MemorySegment array, long index) {
        return array.asSlice(layout().byteSize() * index);
    }

    /**
     * The size (in bytes) of this struct
     */
    public static long sizeof() { return layout().byteSize(); }

    /**
     * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
     */
    public static MemorySegment allocate(SegmentAllocator allocator) {
        return allocator.allocate(layout());
    }

    /**
     * Allocate an array of size {@code elementCount} using {@code allocator}.
     * The returned segment has size {@code elementCount * layout().byteSize()}.
     */
    public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
        return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
    }

    /**
     * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
     * The returned segment has size {@code layout().byteSize()}
     */
    public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) {
        return reinterpret(addr, 1, arena, cleanup);
    }

    /**
     * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
     * The returned segment has size {@code elementCount * layout().byteSize()}
     */
    public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) {
        return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy