-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exposing just a single Persistance.Reference abstraction (#10117)
* Exposing just a single Persistance.Reference abstraction * Reference.of(obj, deferredWrite) * Encapsulating Reference serde in PerReferencePeristance
- Loading branch information
1 parent
f0e9ffa
commit 3f8e144
Showing
14 changed files
with
387 additions
and
110 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
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
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
39 changes: 39 additions & 0 deletions
39
lib/java/persistance/src/main/java/org/enso/persist/PerReferencePersistance.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,39 @@ | ||
package org.enso.persist; | ||
|
||
import static org.enso.persist.PerGenerator.INLINED_REFERENCE_ID; | ||
|
||
import java.io.IOException; | ||
import org.enso.persist.Persistance.Reference; | ||
|
||
final class PerReferencePeristance extends Persistance<Reference> { | ||
static final Persistance<Reference> INSTANCE = new PerReferencePeristance(); | ||
|
||
private PerReferencePeristance() { | ||
super(Reference.class, true, 4320); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
protected void writeObject(Reference ref, Output out) throws IOException { | ||
if (ref.isDeferredWrite()) { | ||
var refId = PerGenerator.registerReference(out, ref); | ||
out.writeInt(refId); | ||
} else { | ||
out.writeInt(INLINED_REFERENCE_ID); | ||
var obj = ref.get(Object.class); | ||
out.writeObject(obj); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
protected Reference readObject(Input in) throws IOException, ClassNotFoundException { | ||
var refId = in.readInt(); | ||
if (refId != INLINED_REFERENCE_ID) { | ||
return PerInputImpl.findReference(in, refId); | ||
} else { | ||
var ref = in.readReference(Object.class); | ||
return ref; | ||
} | ||
} | ||
} |
Oops, something went wrong.