tech.ytsaurus.client.TableAttachmentSkiffReader Maven / Gradle / Ivy
The newest version!
package tech.ytsaurus.client;
import java.io.ByteArrayInputStream;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import tech.ytsaurus.client.rows.EntitySkiffSerializer;
import tech.ytsaurus.skiff.SkiffParser;
public class TableAttachmentSkiffReader extends TableAttachmentRowsetReader {
private final EntitySkiffSerializer serializer;
TableAttachmentSkiffReader(EntitySkiffSerializer serializer) {
this.serializer = serializer;
}
public EntitySkiffSerializer getSerializer() {
return serializer;
}
@Override
protected List parseMergedRow(ByteBuffer buffer, int size) {
byte[] data = new byte[size];
buffer.get(data);
var parser = new SkiffParser(new ByteArrayInputStream(data));
List deserializedObjects = new ArrayList<>();
while (parser.hasMoreData()) {
// only one entity schema is supported
parser.parseInt16();
deserializedObjects.add(serializer.deserialize(parser)
.orElseThrow(() -> new IllegalStateException("Cannot deserialize object")));
}
return deserializedObjects;
}
}