本文整理汇总了TypeScript中bser.dumpToBuffer函数的典型用法代码示例。如果您正苦于以下问题:TypeScript dumpToBuffer函数的具体用法?TypeScript dumpToBuffer怎么用?TypeScript dumpToBuffer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dumpToBuffer函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: sendSubscription
function sendSubscription(uid: string, root: string, files: FileChangeItem[]): void {
client.write(bser.dumpToBuffer({
subscription: uid,
root,
files
}))
}
开发者ID:illarionvk,项目名称:dotfiles,代码行数:7,代码来源:watchman.test.ts
示例2:
import * as bser from "bser";
import net from "net";
const obj = "sample data";
const bunser = new bser.BunserBuf();
bunser.on("value", obj => {
console.log("data from socket", obj);
});
const socket = net.connect("/socket");
socket.on("data", buf => {
bunser.append(buf);
});
socket.write(bser.dumpToBuffer(obj));
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:16,代码来源:sample3.ts
示例3: sendResponse
function sendResponse(data: any): void {
client.write(bser.dumpToBuffer(data))
}
开发者ID:illarionvk,项目名称:dotfiles,代码行数:3,代码来源:watchman.test.ts
示例4:
import * as bser from "bser";
const encoded = bser.dumpToBuffer(["hello"]);
console.log(bser.loadFromBuffer(encoded)); // ['hello']
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:4,代码来源:sample1.ts
示例5: roundtrip
function roundtrip(val: any) {
const encoded = bser.dumpToBuffer(val);
const decoded = bser.loadFromBuffer(encoded);
assert.deepStrictEqual(decoded, val);
}
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:5,代码来源:tests.ts
示例6:
const acc = new bser.Accumulator(8);
acc.append("hello");
assert.equal(acc.readAvail(), 5);
assert.equal(acc.readOffset, 0);
assert.equal(acc.readString(3), "hel");
assert.equal(acc.readOffset, 3);
assert.equal(acc.readAvail(), 2);
assert.equal(acc.writeAvail(), 3);
// This should trigger a shunt and not make the buffer bigger
acc.reserve(5);
assert.equal(acc.readOffset, 0, "shunted");
assert.equal(acc.readAvail(), 2, "still have 2 available to read");
assert.equal(acc.writeAvail(), 6, "2 left to read out of 8 total space");
assert.equal(acc.peekString(2), "lo", "have the correct remainder");
// Don't include keys that have undefined values
const res = bser.dumpToBuffer({ expression: undefined });
assert.deepStrictEqual(bser.loadFromBuffer(res), {});
// Dump numbers without fraction to integers
let buffer;
buffer = bser.dumpToBuffer(1);
assert.equal(buffer.toString("hex"), "000105020000000301");
buffer = bser.dumpToBuffer(1.0);
assert.equal(buffer.toString("hex"), "000105020000000301");
// Dump numbers with fraction to double
buffer = bser.dumpToBuffer(1.1);
assert.equal(buffer.toString("hex"), "00010509000000079a9999999999f13f");
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:30,代码来源:tests.ts
注:本文中的bser.dumpToBuffer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论