1 // Generated by jextract
  2 
  3 package jdk.internal.ffi.generated.iouring;
  4 
  5 import java.lang.invoke.*;
  6 import java.lang.foreign.*;
  7 import java.nio.ByteOrder;
  8 import java.util.*;
  9 import java.util.function.*;
 10 import java.util.stream.*;
 11 
 12 import static java.lang.foreign.ValueLayout.*;
 13 import static java.lang.foreign.MemoryLayout.PathElement.*;
 14 
 15 /**
 16  * {@snippet lang=c :
 17  * struct sockaddr_in6 {
 18  *     sa_family_t sin6_family;
 19  *     in_port_t sin6_port;
 20  *     uint32_t sin6_flowinfo;
 21  *     struct in6_addr sin6_addr;
 22  *     uint32_t sin6_scope_id;
 23  * }
 24  * }
 25  */
 26 @SuppressWarnings("restricted") public class sockaddr_in6 {
 27 
 28     sockaddr_in6() {
 29         // Suppresses public default constructor, ensuring non-instantiability,
 30         // but allows generated subclasses in same package.
 31     }
 32 
 33     private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
 34         iouring_h.C_SHORT.withName("sin6_family"),
 35         iouring_h.C_SHORT.withName("sin6_port"),
 36         iouring_h.C_INT.withName("sin6_flowinfo"),
 37         in6_addr.$LAYOUT().withName("sin6_addr"),
 38         iouring_h.C_INT.withName("sin6_scope_id")
 39     ).withName("sockaddr_in6");
 40 
 41     public static final GroupLayout $LAYOUT() {
 42         return $LAYOUT;
 43     }
 44 
 45     private static final long sin6_family$OFFSET = 0;
 46     private static final OfShort sin6_family$LAYOUT = (OfShort)$LAYOUT.select(groupElement("sin6_family"));
 47 
 48     /**
 49      * Getter for field:
 50      * {@snippet lang=c :
 51      * sa_family_t sin6_family
 52      * }
 53      */
 54     public static short sin6_family(MemorySegment struct) {
 55         return struct.get(sin6_family$LAYOUT, sin6_family$OFFSET);
 56     }
 57 
 58     /**
 59      * Setter for field:
 60      * {@snippet lang=c :
 61      * sa_family_t sin6_family
 62      * }
 63      */
 64     public static void sin6_family(MemorySegment struct, short fieldValue) {
 65         struct.set(sin6_family$LAYOUT, sin6_family$OFFSET, fieldValue);
 66     }
 67 
 68     private static final long sin6_port$OFFSET = 2;
 69     private static final OfShort sin6_port$LAYOUT = ((OfShort)$LAYOUT.select(groupElement("sin6_port"))).withOrder(ByteOrder.BIG_ENDIAN);
 70 
 71     /**
 72      * Getter for field:
 73      * {@snippet lang=c :
 74      * in_port_t sin6_port
 75      * }
 76      */
 77     public static short sin6_port(MemorySegment struct) {
 78         return struct.get(sin6_port$LAYOUT, sin6_port$OFFSET);
 79     }
 80 
 81     /**
 82      * Setter for field:
 83      * {@snippet lang=c :
 84      * in_port_t sin6_port
 85      * }
 86      */
 87     public static void sin6_port(MemorySegment struct, short fieldValue) {
 88         struct.set(sin6_port$LAYOUT, sin6_port$OFFSET, fieldValue);
 89     }
 90 
 91     private static final long sin6_flowinfo$OFFSET = 4;
 92     private static final OfInt sin6_flowinfo$LAYOUT = (OfInt)$LAYOUT.select(groupElement("sin6_flowinfo"));
 93 
 94     /**
 95      * Getter for field:
 96      * {@snippet lang=c :
 97      * uint32_t sin6_flowinfo
 98      * }
 99      */
100     public static int sin6_flowinfo(MemorySegment struct) {
101         return struct.get(sin6_flowinfo$LAYOUT, sin6_flowinfo$OFFSET);
102     }
103 
104     /**
105      * Setter for field:
106      * {@snippet lang=c :
107      * uint32_t sin6_flowinfo
108      * }
109      */
110     public static void sin6_flowinfo(MemorySegment struct, int fieldValue) {
111         struct.set(sin6_flowinfo$LAYOUT, sin6_flowinfo$OFFSET, fieldValue);
112     }
113 
114     private static final long sin6_addr$OFFSET = 8;
115     private static final long sin6_addr$SIZE = 16;
116 
117     /**
118      * Getter for field:
119      * {@snippet lang=c :
120      * struct in6_addr sin6_addr
121      * }
122      */
123     public static MemorySegment sin6_addr(MemorySegment struct) {
124         return struct.asSlice(sin6_addr$OFFSET, sin6_addr$SIZE);
125     }
126 
127     /**
128      * Setter for field:
129      * {@snippet lang=c :
130      * struct in6_addr sin6_addr
131      * }
132      */
133     public static void sin6_addr(MemorySegment struct, MemorySegment fieldValue) {
134         MemorySegment.copy(fieldValue, 0L, struct, sin6_addr$OFFSET, sin6_addr$SIZE);
135     }
136 
137     private static final long sin6_scope_id$OFFSET = 24;
138     private static final OfInt sin6_scope_id$LAYOUT = (OfInt)$LAYOUT.select(groupElement("sin6_scope_id"));
139 
140     /**
141      * Getter for field:
142      * {@snippet lang=c :
143      * uint32_t sin6_scope_id
144      * }
145      */
146     public static int sin6_scope_id(MemorySegment struct) {
147         return struct.get(sin6_scope_id$LAYOUT, sin6_scope_id$OFFSET);
148     }
149 
150     /**
151      * Setter for field:
152      * {@snippet lang=c :
153      * uint32_t sin6_scope_id
154      * }
155      */
156     public static void sin6_scope_id(MemorySegment struct, int fieldValue) {
157         struct.set(sin6_scope_id$LAYOUT, sin6_scope_id$OFFSET, fieldValue);
158     }
159 
160     public static MemorySegment asSlice(MemorySegment array, long index) {
161         return array.asSlice($LAYOUT().byteSize() * index);
162     }
163 
164     public static long sizeof() { return $LAYOUT().byteSize(); }
165 
166     public static MemorySegment allocate(SegmentAllocator allocator) {
167         return allocator.allocate($LAYOUT());
168     }
169 
170     public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
171         return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, $LAYOUT()));
172     }
173 
174     public static MemorySegment reinterpret(MemorySegment addr, Arena scope, Consumer<MemorySegment> cleanup) {
175         return reinterpret(addr, 1, scope, cleanup);
176     }
177 
178     public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena scope, Consumer<MemorySegment> cleanup) {
179         return addr.reinterpret($LAYOUT().byteSize() * elementCount, scope, cleanup);
180     }
181 }
182