use of com.baidu.hugegraph.backend.serializer.BytesBuffer in project incubator-hugegraph by apache.
the class PageState method toBytes.
private byte[] toBytes() {
assert this.position.length > 0;
int length = 2 + this.position.length + 2 * BytesBuffer.INT_LEN;
BytesBuffer buffer = BytesBuffer.allocate(length);
buffer.writeBytes(this.position);
buffer.writeInt(this.offset);
buffer.writeInt(this.total);
return buffer.bytes();
}
use of com.baidu.hugegraph.backend.serializer.BytesBuffer in project incubator-hugegraph by apache.
the class IdUtil method writeBinString.
public static Object writeBinString(Id id) {
int len = id.edge() ? BytesBuffer.BUF_EDGE_ID : id.length() + 1;
BytesBuffer buffer = BytesBuffer.allocate(len).writeId(id);
buffer.forReadWritten();
return buffer.asByteBuffer();
}
use of com.baidu.hugegraph.backend.serializer.BytesBuffer in project incubator-hugegraph by apache.
the class PageInfo method toBytes.
public byte[] toBytes() {
byte[] pageState = PageState.toBytes(this.page);
int length = 2 + BytesBuffer.INT_LEN + pageState.length;
BytesBuffer buffer = BytesBuffer.allocate(length);
buffer.writeInt(this.offset);
buffer.writeBytes(pageState);
return buffer.bytes();
}
use of com.baidu.hugegraph.backend.serializer.BytesBuffer in project incubator-hugegraph by apache.
the class PageInfo method fromBytes.
public static PageInfo fromBytes(byte[] bytes) {
if (bytes.length == 0) {
// The first page
return new PageInfo(0, PAGE_NONE);
}
try {
BytesBuffer buffer = BytesBuffer.wrap(bytes);
int offset = buffer.readInt();
byte[] pageState = buffer.readBytes();
String page = PageState.toString(pageState);
return new PageInfo(offset, page);
} catch (Exception e) {
throw new HugeException("Invalid page: '0x%s'", e, Bytes.toHex(bytes));
}
}
use of com.baidu.hugegraph.backend.serializer.BytesBuffer in project incubator-hugegraph by apache.
the class HugeIndex method parseIndexId.
public static HugeIndex parseIndexId(HugeGraph graph, HugeType type, byte[] id) {
Object values;
IndexLabel indexLabel;
if (type.isStringIndex()) {
Id idObject = IdGenerator.of(id, IdType.STRING);
String[] parts = SplicingIdGenerator.parse(idObject);
E.checkState(parts.length == 2, "Invalid secondary index id");
Id label = IdGenerator.ofStoredString(parts[0], IdType.LONG);
indexLabel = IndexLabel.label(graph, label);
values = parts[1];
} else {
assert type.isRange4Index() || type.isRange8Index();
final int labelLength = 4;
E.checkState(id.length > labelLength, "Invalid range index id");
BytesBuffer buffer = BytesBuffer.wrap(id);
Id label = IdGenerator.of(buffer.readInt());
indexLabel = IndexLabel.label(graph, label);
List<Id> fields = indexLabel.indexFields();
E.checkState(fields.size() == 1, "Invalid range index fields");
DataType dataType = graph.propertyKey(fields.get(0)).dataType();
E.checkState(dataType.isNumber() || dataType.isDate(), "Invalid range index field type");
Class<?> clazz = dataType.isNumber() ? dataType.clazz() : DataType.LONG.clazz();
values = bytes2number(buffer.read(id.length - labelLength), clazz);
}
HugeIndex index = new HugeIndex(graph, indexLabel);
index.fieldValues(values);
return index;
}
Aggregations