-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
depend on r for even better packet registration
- Loading branch information
1 parent
bcd5d45
commit 4f3b010
Showing
8 changed files
with
54 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
common/src/main/java/me/mrnavastar/protoweaver/core/util/Furious.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package me.mrnavastar.protoweaver.core.util; | ||
|
||
import me.mrnavastar.r.R; | ||
import org.apache.fury.Fury; | ||
import org.apache.fury.ThreadSafeFury; | ||
import org.apache.fury.logging.LoggerFactory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Furious { | ||
|
||
private static final ThreadSafeFury FURY = Fury.builder().withJdkClassSerializableCheck(false).buildThreadSafeFury(); | ||
|
||
static { | ||
// Make fury be quiet | ||
LoggerFactory.disableLogging(); | ||
} | ||
|
||
private static void recursiveRegister(Class<?> type, List<Class<?>> registered) { | ||
if (type == null || registered.contains(type)) return; | ||
FURY.register(type); | ||
registered.add(type); | ||
|
||
List.of(type.getDeclaredFields()).forEach(field -> recursiveRegister(field.getType(), registered)); | ||
List.of(R.of(type).generics()).forEach(t -> recursiveRegister(t, registered)); | ||
recursiveRegister(type.getSuperclass(), registered); | ||
} | ||
|
||
public static void register(Class<?> type) { | ||
recursiveRegister(type, new ArrayList<>()); | ||
} | ||
|
||
public static byte[] serialize(Object object) { | ||
return FURY.serialize(object); | ||
} | ||
|
||
public static Object deserialize(byte[] bytes) { | ||
return FURY.deserialize(bytes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters