This repository was archived by the owner on Apr 28, 2020. It is now read-only.
File tree Expand file tree Collapse file tree
src/main/java/org/dimdev/rift/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package org .dimdev .rift .util ;
2+
3+ import net .minecraft .nbt .NBTTagCompound ;
4+
5+ import javax .annotation .Nonnull ;
6+
7+ /**
8+ * Base interface for (de)serializable objects to serialize
9+ * themselves to and from {@link NBTTagCompound} tag compounds
10+ */
11+ public interface NBTSerializable {
12+ /**
13+ * Writes this object's data to the given compound
14+ * @param compound The tag compound to be written to
15+ * @return The written tag compound
16+ */
17+ @ Nonnull
18+ NBTTagCompound serialize (@ Nonnull NBTTagCompound compound );
19+
20+ /**
21+ * Reads this object's data from the given compound
22+ * @param compound The tag compound to be read from
23+ * @return The given tag compound
24+ */
25+ @ Nonnull
26+ NBTTagCompound deserialize (@ Nonnull NBTTagCompound compound );
27+
28+ /**
29+ * Writes this object's data to a new tag compound
30+ * @return The written tag compound
31+ */
32+ @ Nonnull
33+ default NBTTagCompound writeToNBT () {
34+ return this .serialize (new NBTTagCompound ());
35+ }
36+ }
Original file line number Diff line number Diff line change 1+ package org .dimdev .rift .util ;
2+
3+ import net .minecraft .nbt .NBTTagCompound ;
4+
5+ import javax .annotation .Nonnull ;
6+
7+ /**
8+ * Base interface for (de)serializing objects of type {@code T}
9+ * to and from {@link NBTTagCompound} tag compounds
10+ */
11+ public interface NBTSerializer <T > {
12+ /**
13+ * Writes an object {@code T} to the given compound
14+ * @param instance The instance to be serialized
15+ * @return The written tag compound
16+ */
17+ @ Nonnull
18+ NBTTagCompound serialize (@ Nonnull T instance );
19+
20+ /**
21+ * Reads an object {@code T} from the given compound
22+ * @param compound The tag compound to be read from
23+ * @return An instance of {@code T}
24+ */
25+ @ Nonnull
26+ T deserialize (@ Nonnull NBTTagCompound compound );
27+ }
You can’t perform that action at this time.
0 commit comments