Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8308967

Add a record mapper for mapping MemorySegments to Record instances

XMLWordPrintable

      Given a `GroupLayout`, the elements in the group are matched with `RecordComponent`s. This can be done for arbitrary element types of arbitrary depth. As a simple example, one can extract a `Point` like so:

      ```
          private static final GroupLayout POINT_LAYOUT = MemoryLayout.structLayout(
                  JAVA_INT.withName("x"),
                  JAVA_INT.withName("y"));

          MemorySegment segment = MemorySegment.ofArray(new int[]{3, 4});

          Point point = POINT_LAYOUT.recordMapper(Point.class)
                .apply(segment); // Point[x=3, y=4]

      ```

            pminborg Per-Ake Minborg
            pminborg Per-Ake Minborg
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: