本文整理匯總了TypeScript中flatbuffers.flatbuffers.Builder類的典型用法代碼示例。如果您正苦於以下問題:TypeScript flatbuffers.Builder類的具體用法?TypeScript flatbuffers.Builder怎麽用?TypeScript flatbuffers.Builder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了flatbuffers.Builder類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: codeFetch
export function codeFetch(
moduleSpecifier: string,
containingFile: string
): ModuleInfo {
util.log("os.ts codeFetch", moduleSpecifier, containingFile);
// Send CodeFetch message
const builder = new flatbuffers.Builder();
const moduleSpecifier_ = builder.createString(moduleSpecifier);
const containingFile_ = builder.createString(containingFile);
fbs.CodeFetch.startCodeFetch(builder);
fbs.CodeFetch.addModuleSpecifier(builder, moduleSpecifier_);
fbs.CodeFetch.addContainingFile(builder, containingFile_);
const msg = fbs.CodeFetch.endCodeFetch(builder);
fbs.Base.startBase(builder);
fbs.Base.addMsg(builder, msg);
fbs.Base.addMsgType(builder, fbs.Any.CodeFetch);
builder.finish(fbs.Base.endBase(builder));
const resBuf = deno.send(builder.asUint8Array());
// Process CodeFetchRes
const bb = new flatbuffers.ByteBuffer(new Uint8Array(resBuf));
const baseRes = fbs.Base.getRootAsBase(bb);
if (fbs.Any.NONE === baseRes.msgType()) {
throw Error(baseRes.error());
}
assert(fbs.Any.CodeFetchRes === baseRes.msgType());
const codeFetchRes = new fbs.CodeFetchRes();
assert(baseRes.msg(codeFetchRes) != null);
const r = {
moduleName: codeFetchRes.moduleName(),
filename: codeFetchRes.filename(),
sourceCode: codeFetchRes.sourceCode(),
outputCode: codeFetchRes.outputCode()
};
return r;
}
示例2: startMsg
function startMsg(cmdId: number): ArrayBuffer {
const builder = new flatbuffers.Builder();
const msg = fbs.Start.createStart(builder, 0);
fbs.Base.startBase(builder);
fbs.Base.addCmdId(builder, cmdId);
fbs.Base.addMsg(builder, msg);
fbs.Base.addMsgType(builder, fbs.Any.Start);
builder.finish(fbs.Base.endBase(builder));
return typedArrayToArrayBuffer(builder.asUint8Array());
}
示例3: startMsg
function startMsg(cmdId: number): Uint8Array {
const builder = new flatbuffers.Builder();
fbs.Start.startStart(builder);
const startOffset = fbs.Start.endStart(builder);
fbs.Base.startBase(builder);
fbs.Base.addCmdId(builder, cmdId);
fbs.Base.addMsg(builder, startOffset);
fbs.Base.addMsgType(builder, fbs.Any.Start);
builder.finish(fbs.Base.endBase(builder));
return builder.asUint8Array();
}
示例4: createSyntheticDictionaryIndexField
function createSyntheticDictionaryIndexField(field: Field, type: FieldType) {
let layouts = [];
let builder = new flatbuffers.Builder();
if (field.nullable()) {
VectorLayout.startVectorLayout(builder);
VectorLayout.addBitWidth(builder, 8);
VectorLayout.addType(builder, VectorType.VALIDITY);
builder.finish(VectorLayout.endVectorLayout(builder));
layouts.push(VectorLayout.getRootAsVectorLayout(builder.dataBuffer()));
builder = new flatbuffers.Builder();
}
VectorLayout.startVectorLayout(builder);
VectorLayout.addBitWidth(builder, type.bitWidth());
VectorLayout.addType(builder, VectorType.DATA);
builder.finish(VectorLayout.endVectorLayout(builder));
layouts.push(VectorLayout.getRootAsVectorLayout(builder.dataBuffer()));
return Object.create(field, {
layout: { value(i) { return layouts[i]; } },
layoutLength: { value() { return layouts.length; } }
});
}
示例5: codeCache
export function codeCache(
filename: string,
sourceCode: string,
outputCode: string
): void {
util.log("os.ts codeCache", filename, sourceCode, outputCode);
const builder = new flatbuffers.Builder();
const filename_ = builder.createString(filename);
const sourceCode_ = builder.createString(sourceCode);
const outputCode_ = builder.createString(outputCode);
fbs.CodeCache.startCodeCache(builder);
fbs.CodeCache.addFilename(builder, filename_);
fbs.CodeCache.addSourceCode(builder, sourceCode_);
fbs.CodeCache.addOutputCode(builder, outputCode_);
const msg = fbs.CodeCache.endCodeCache(builder);
fbs.Base.startBase(builder);
fbs.Base.addMsg(builder, msg);
fbs.Base.addMsgType(builder, fbs.Any.CodeCache);
builder.finish(fbs.Base.endBase(builder));
const resBuf = deno.send(builder.asUint8Array());
// Expect null or error.
if (resBuf != null) {
const bb = new flatbuffers.ByteBuffer(new Uint8Array(resBuf));
const baseRes = fbs.Base.getRootAsBase(bb);
assert(fbs.Any.NONE === baseRes.msgType());
throw Error(baseRes.error());
}
}
示例6: codeCache
export function codeCache(
filename: string,
sourceCode: string,
outputCode: string
): void {
const builder = new flatbuffers.Builder();
const filename_ = builder.createString(filename);
const sourceCode_ = builder.createString(sourceCode);
const outputCode_ = builder.createString(outputCode);
fbs.CodeCache.startCodeCache(builder);
fbs.CodeCache.addFilename(builder, filename_);
fbs.CodeCache.addSourceCode(builder, sourceCode_);
fbs.CodeCache.addOutputCode(builder, outputCode_);
const msg = fbs.CodeCache.endCodeCache(builder);
fbs.Base.startBase(builder);
fbs.Base.addMsg(builder, msg);
builder.finish(fbs.Base.endBase(builder));
// Maybe need to do another step?
// Base.finishBaseBuffer(builder, base);
const payload = typedArrayToArrayBuffer(builder.asUint8Array());
const resBuf = deno.send("x", payload);
assert(resBuf === null);
}
示例7: codeFetch
export function codeFetch(
moduleSpecifier: string,
containingFile: string
): ModuleInfo {
console.log("Hello from codeFetch");
// Send CodeFetch message
const builder = new flatbuffers.Builder();
const moduleSpecifier_ = builder.createString(moduleSpecifier);
const containingFile_ = builder.createString(containingFile);
fbs.CodeFetch.startCodeFetch(builder);
fbs.CodeFetch.addModuleSpecifier(builder, moduleSpecifier_);
fbs.CodeFetch.addContainingFile(builder, containingFile_);
const msg = fbs.CodeFetch.endCodeFetch(builder);
fbs.Base.startBase(builder);
fbs.Base.addMsg(builder, msg);
fbs.Base.addMsgType(builder, fbs.Any.CodeFetch);
builder.finish(fbs.Base.endBase(builder));
const payload = typedArrayToArrayBuffer(builder.asUint8Array());
const resBuf = deno.send("x", payload);
console.log("CodeFetch sent");
// Process CodeFetchRes
const bb = new flatbuffers.ByteBuffer(new Uint8Array(resBuf));
const baseRes = fbs.Base.getRootAsBase(bb);
assert(fbs.Any.CodeFetchRes === baseRes.msgType());
const codeFetchRes = new fbs.CodeFetchRes();
assert(baseRes.msg(codeFetchRes) != null);
return {
moduleName: codeFetchRes.moduleName(),
filename: codeFetchRes.filename(),
sourceCode: codeFetchRes.sourceCode(),
outputCode: codeFetchRes.outputCode()
};
}
示例8:
import {DOMBuffer} from './DOMBuffer.fbs'
import {flatbuffers} from 'flatbuffers'
var builder = new flatbuffers.Builder(1024)
DOMBuffer.ChangeText.startChangeText(builder)
DOMBuffer.ChangeText.addText(builder, builder.createString('Hello World'))
var node = DOMBuffer.ChangeText.endChangeText(builder)
DOMBuffer.Change.startChange(builder)
DOMBuffer.Change.addType(builder, DOMBuffer.ChangeType.Insert)
DOMBuffer.Change.addChange(builder, node)
var change = DOMBuffer.Change.endChange(builder)
builder.finish(change)
var bytes = builder.asUint8Array()
// Read
var buffer = new flatbuffers.ByteBuffer(bytes)
var diff = DOMBuffer.Change.getRootAsChange(buffer)
var changeType = diff.type()
var textNode = diff.change(new DOMBuffer.ChangeText)