Skip to content

Commit

Permalink
Support registering custom layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
danielperano committed Jan 12, 2024
1 parent e046acb commit d2e3c03
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/src/main/java/com/myworldvw/buoy/NativeMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ public MemoryLayout makePadding(long structSize, MemoryLayout element){
return remainder != 0 ? MemoryLayout.paddingLayout(element.byteAlignment() - remainder) : null;
}

public <T> NativeMapper register(Class<T> targetType, MemoryLayout customLayout){
layouts.put(targetType, customLayout);
return this;
}

public <T> NativeMapper register(Class<T> targetType){
return register(targetType, false);
}
Expand Down Expand Up @@ -404,8 +409,7 @@ public <T> NativeMapper register(Class<T> targetType, ObjectHandlers<T> handlers
}

public <T extends Enum<?>> NativeMapper registerEnum(Class<T> enumeration){
layouts.put(enumeration, ValueLayout.JAVA_INT);
return this;
return register(enumeration, ValueLayout.JAVA_INT);
}

public boolean isRegistered(Class<?> targetType){
Expand Down

0 comments on commit d2e3c03

Please sign in to comment.