Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async getPathInfo(path: string): Promise {
const builder = new flatbuffers.Builder(256);
const pathOff = builder.createString(path);
sz.BrowseRequest.startBrowseRequest(builder);
sz.BrowseRequest.addPath(builder, pathOff);
sz.BrowseRequest.addRecursive(builder, toFbLong(1));
const off = sz.BrowseRequest.endBrowseRequest(builder);
builder.finish(off);
const requestPayload = builder.asUint8Array();
// Send the request
const r = await this.binaryRouter.post('files/getPathInfo', requestPayload);
const buf = new flatbuffers.ByteBuffer(r);
const response = sz.BrowseResponse.getRootAsBrowseResponse(buf);
const pathInfo = this.convert(response);
if (this.verboseResponseLog) {
this.logger.debug(`Browse: ${JSON.stringify(pathInfo, null, 4)}`);
}
return pathInfo;
}
sz.AddConnectionRequest.addCheckForCycles(builder, cycleDetection);
const off = sz.AddConnectionRequest.endAddConnectionRequest(builder);
builder.finish(off);
const requestPayload = builder.asUint8Array();
const result = await this.binaryRouter.post('graph/addConnection', requestPayload);
if (!result.length) {
// Succesfully added connection
this.logger.info(`Added connection: ['${source.id}' ⟶ '${target.id}'] from graph [id: '${graphId}']`);
return connection;
} else {
// Cycle detected, read the repsonse
const buf = new flatbuffers.ByteBuffer(result);
const response = sz.AddNodeResponse.getRootAsAddNodeResponse(buf);
throw new Error('Cycle detection not yet implemented!');
}
}
builder.finish(off);
const requestPayload = builder.asUint8Array();
const result = await this.binaryRouter.post('graph/addConnection', requestPayload);
if (!result.length) {
// Succesfully added connection
this.logger.info(
`Added connection: ['${source.idString}' ⟶ '${target.idString}'] from graph [id: '${graphId.toString()}']`
);
return connection;
} else {
// Cycle detected, read the repsonse
const buf = new flatbuffers.ByteBuffer(result);
const response = sz.AddNodeResponse.getRootAsAddNodeResponse(buf);
throw 'Cycle detection not yet implemented!';
}
}
export function deserialize(bytes: Uint8Array) {
if (!bytes.subarray(0, 7).every((v, i) => magicbytes[i] === v))
throw new Error('Not a FlatGeobuf file')
const bb = new flatbuffers.ByteBuffer(bytes)
const headerLength = bb.readUint32(magicbytes.length)
bb.setPosition(magicbytes.length + SIZE_PREFIX_LEN)
const header = Header.getRoot(bb)
const count = header.featuresCount().toFloat64()
const columns: ColumnMeta[] = []
for (let j = 0; j < header.columnsLength(); j++) {
const column = header.columns(j)
columns.push(new ColumnMeta(column.name(), column.type()))
}
const headerMeta = new HeaderMeta(header.geometryType(), columns)
let offset = magicbytes.length + SIZE_PREFIX_LEN + headerLength
const indexNodeSize = header.indexNodeSize()
if (indexNodeSize > 0)
encode(encoder: Encoder, init: buffer): Result {
const byteBuffer = new flatbuffers.ByteBuffer(this.data)
const chageLog = new ChangeLog()
ChangeLog.getRootAsChangeLog(byteBuffer, chageLog)
return ChangeLog.decode(chageLog, encoder, init)
}
public async getAllGraphTypeDescriptions(): Promise {
const result = await this.binaryRouter.get('general/getAllGraphTypeDescriptions');
let buf = new flatbuffers.ByteBuffer(result);
let response = sz.GetAllGraphTypeDescriptionsResponse.getRootAsGetAllGraphTypeDescriptionsResponse(buf);
this.logger.info(`Number of graph types: ${response.graphsTypesLength()}`);
let graphDesc: model.GraphTypeDescription[] = [];
for (let g = 0; g < response.graphsTypesLength(); ++g) {
graphDesc.push(conversions.toGraphTypeDescription(response.graphsTypes(g)));
}
if (this.verboseResponseLog) {
this.logger.debug(`GraphDescriptions: ${JSON.stringify(graphDesc)}`);
}
return graphDesc;
}
export async function* deserializeStream(
stream: ReadableStream) {
const reader = slice(stream)
let bytes = await reader.slice(8)
if (!bytes.every((v, i) => magicbytes[i] === v))
throw new Error('Not a FlatGeobuf file')
bytes = await reader.slice(4)
let bb = new flatbuffers.ByteBuffer(bytes)
const headerLength = bb.readUint32(0)
bytes = await reader.slice(headerLength)
bb = new flatbuffers.ByteBuffer(bytes)
const header = Header.getRoot(bb)
const count = header.featuresCount().toFloat64()
const columns: ColumnMeta[] = []
for (let j = 0; j < header.columnsLength(); j++) {
const column = header.columns(j)
columns.push(new ColumnMeta(column.name(), column.type()))
}
const headerMeta = new HeaderMeta(header.geometryType(), columns)
const indexNodeSize = header.indexNodeSize()
if (indexNodeSize > 0)
await reader.slice(tree.size(count, indexNodeSize) + (count * FEATURE_OFFSET_LEN))
public async execute(): Promise {
const result = await this.binaryRouter.post('graph/execute', this.createBinaryData(null));
const buf = new flatbuffers.ByteBuffer(result);
}
columns.push(new ColumnMeta(column.name(), column.type()))
}
const headerMeta = new HeaderMeta(header.geometryType(), columns)
const indexNodeSize = header.indexNodeSize()
if (indexNodeSize > 0)
await reader.slice(tree.size(count, indexNodeSize) + (count * FEATURE_OFFSET_LEN))
for (let i = 0; i < count; i++) {
bytes = await reader.slice(4)
bb = new flatbuffers.ByteBuffer(bytes)
const featureLength = bb.readUint32(0)
bytes = await reader.slice(featureLength)
const bytesAligned = new Uint8Array(featureLength + 4)
bytesAligned.set(bytes, 4)
bb = new flatbuffers.ByteBuffer(bytesAligned)
bb.setPosition(SIZE_PREFIX_LEN)
const feature = Feature.getRoot(bb)
yield fromFeature(feature, headerMeta, createGeometry, createFeature)
}
}
export function deserialize(
bytes: Uint8Array,
createGeometry: ICreateGeometry,
createFeature: ICreateFeature): IFeature[] {
if (!bytes.subarray(0, 7).every((v, i) => magicbytes[i] === v))
throw new Error('Not a FlatGeobuf file')
const bb = new flatbuffers.ByteBuffer(bytes)
const headerLength = bb.readUint32(magicbytes.length)
bb.setPosition(magicbytes.length + SIZE_PREFIX_LEN)
const header = Header.getRoot(bb)
const count = header.featuresCount().toFloat64()
const columns: ColumnMeta[] = []
for (let j = 0; j < header.columnsLength(); j++) {
const column = header.columns(j)
columns.push(new ColumnMeta(column.name(), column.type()))
}
const headerMeta = new HeaderMeta(header.geometryType(), columns)
let offset = magicbytes.length + SIZE_PREFIX_LEN + headerLength
const indexNodeSize = header.indexNodeSize()
if (indexNodeSize > 0)