Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed Jul 18, 2024
1 parent 23c683f commit bca8d79
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.lionweb.lioncore.java.serialization;

import io.lionweb.lioncore.java.model.ClassifierInstance;
import io.lionweb.lioncore.java.serialization.data.MetaPointer;
import java.util.LinkedList;
import java.util.List;

public class BulkImport {

public static class AttachPoint {
public String container;
public MetaPointer containment;
public String rootId;
}

private List<AttachPoint> attachPoints = new LinkedList<>();
private List<ClassifierInstance<?>> nodes = new LinkedList<>();

public List<AttachPoint> getAttachPoints() {
return attachPoints;
}

public List<ClassifierInstance<?>> getNodes() {
return nodes;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -237,31 +237,41 @@ PBNode serializeNode(SerializedClassifierInstance n) {
}
}

public PBBulkImport serializeBulkImport(List<BulkImportElement> elements) {
public PBBulkImport serializeBulkImport(BulkImport bulkImport) {
PBBulkImport.Builder bulkImportBuilder = PBBulkImport.newBuilder();
ProtoBufSerialization.SerializeHelper serializeHelper =
new ProtoBufSerialization.SerializeHelper();

elements.forEach(
bulkImportElement -> {
PBBulkImportElement.Builder bulkImportElementBuilder = PBBulkImportElement.newBuilder();
bulkImportElementBuilder.setMetaPointerIndex(
serializeHelper.metaPointerIndexer(bulkImportElement.containment));
SerializedChunk serializedChunk =
serializeTreeToSerializationBlock(bulkImportElement.tree);
bulkImport
.getAttachPoints()
.forEach(
attachPoint -> {
PBAttachPoint.Builder attachPointBuilder = PBAttachPoint.newBuilder();
attachPointBuilder.setContainer(serializeHelper.stringIndexer(attachPoint.container));
attachPointBuilder.setRootId(serializeHelper.stringIndexer(attachPoint.rootId));
attachPointBuilder.setMetaPointerIndex(
serializeHelper.metaPointerIndexer(attachPoint.containment));
bulkImportBuilder.addAttachPoints(attachPointBuilder.build());
});

serializedChunk
.getClassifierInstances()
.forEach(n -> bulkImportElementBuilder.addTree(serializeHelper.serializeNode(n)));
SerializedChunk serializedChunk = serializeNodesToSerializationBlock(bulkImport.getNodes());

bulkImportBuilder.addElements(bulkImportElementBuilder.build());
});
serializedChunk
.getClassifierInstances()
.forEach(
serializedNode -> {
bulkImportBuilder.addNodes(serializeHelper.serializeNode(serializedNode));
});

serializeHelper.strings.entrySet().stream()
.sorted()
.forEach(entry -> bulkImportBuilder.addStringValues(entry.getKey()));

serializeHelper.metaPointers.entrySet().stream()
.sorted()
.forEach(
entry ->
bulkImportBuilder.addMetaPointerDefs(
bulkImportBuilder.addMetaPointers(
PBMetaPointer.newBuilder()
.setLanguage(serializeHelper.stringIndexer(entry.getKey().getLanguage()))
.setKey(serializeHelper.stringIndexer(entry.getKey().getKey()))
Expand Down
28 changes: 17 additions & 11 deletions core/src/main/proto/io/lionweb/lioncore/protobuf/Chunk.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@ option java_multiple_files = true;
option java_package = "io.lionweb.lioncore.protobuf";
option java_outer_classname = "ChunkProtos";

message PBBulkImport {
repeated PBMetaPointer metaPointerDefs = 1;
repeated PBBulkImportElement elements = 2;
}

message PBBulkImportElement {
string container = 1;
int32 metaPointerIndex = 2;
repeated PBNode tree = 3;
}

message PBChunk {
string serializationFormatVersion = 1;
// We use this mechanism both to save space and to represent nulls (identified by -1)
Expand Down Expand Up @@ -68,3 +57,20 @@ message PBReferenceValue {
/* Optional*/ int32 resolveInfo = 1;
/* Optional*/ int32 referred = 2;
}


/* Specific for Bulk Import */

message PBBulkImport {
// We use this mechanism both to save space and to represent nulls (identified by -1)
repeated string stringValues = 1;
repeated PBMetaPointer metaPointers= 2;
repeated PBAttachPoint attachPoints = 3;
repeated PBNode nodes = 4;
}

message PBAttachPoint {
int32 container = 1;
int32 metaPointerIndex = 2;
int32 rootId = 3;
}

0 comments on commit bca8d79

Please sign in to comment.