本文整理汇总了TypeScript中yass.Writer.writeInt方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Writer.writeInt方法的具体用法?TypeScript Writer.writeInt怎么用?TypeScript Writer.writeInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yass.Writer
的用法示例。
在下文中一共展示了Writer.writeInt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: toArrayBuffer
function toArrayBuffer(byteArray: Uint8Array): ArrayBuffer {
const arrayBuffer = new ArrayBuffer(byteArray.length);
new Uint8Array(arrayBuffer).set(byteArray);
return arrayBuffer;
}
function writer2reader(writer: yass.Writer): yass.Reader {
return new yass.Reader(toArrayBuffer(writer.getArray()));
}
namespace ioTest {
let writer = new yass.Writer(1);
writer.writeByte(123);
writer.writeByte(210);
writer.writeInt(0);
writer.writeInt(21);
writer.writeInt(25658);
writer.writeInt(-13);
writer.writeInt(-344554);
writer.writeInt(2147483647);
writer.writeInt(-2147483648);
writer.writeVarInt(0);
writer.writeVarInt(21);
writer.writeVarInt(25658);
writer.writeVarInt(-13);
writer.writeVarInt(-344554);
writer.writeVarInt(2147483647);
writer.writeVarInt(-2147483648);
writer.writeZigZagInt(0);
writer.writeZigZagInt(21);
示例2: ioTest
(function ioTest(): void {
let writer = new yass.Writer(1);
writer.writeByte(123);
writer.writeByte(210);
writer.writeInt(0);
writer.writeInt(21);
writer.writeInt(25658);
writer.writeInt(-13);
writer.writeInt(-344554);
writer.writeInt(2147483647);
writer.writeInt(-2147483648);
writer.writeVarInt(0);
writer.writeVarInt(21);
writer.writeVarInt(25658);
writer.writeVarInt(-13);
writer.writeVarInt(-344554);
writer.writeVarInt(2147483647);
writer.writeVarInt(-2147483648);
writer.writeZigZagInt(0);
writer.writeZigZagInt(21);
writer.writeZigZagInt(25658);
writer.writeZigZagInt(-13);
writer.writeZigZagInt(-344554);
writer.writeZigZagInt(2147483647);
writer.writeZigZagInt(-2147483648);
assert(writer.getArray().length === 74);
let reader = writer2reader(writer);
assert(!reader.isEmpty());
assert(reader.readByte() === 123);
assert(reader.readByte() === 210);
assert(reader.readInt() === 0);
assert(reader.readInt() === 21);
assert(reader.readInt() === 25658);
assert(reader.readInt() === -13);
assert(reader.readInt() === -344554);
assert(reader.readInt() === 2147483647);
assert(reader.readInt() === -2147483648);
assert(reader.readVarInt() === 0);
assert(reader.readVarInt() === 21);
assert(reader.readVarInt() === 25658);
assert(reader.readVarInt() === -13);
assert(reader.readVarInt() === -344554);
assert(reader.readVarInt() === 2147483647);
assert(reader.readVarInt() === -2147483648);
assert(reader.readZigZagInt() === 0);
assert(reader.readZigZagInt() === 21);
assert(reader.readZigZagInt() === 25658);
assert(reader.readZigZagInt() === -13);
assert(reader.readZigZagInt() === -344554);
assert(reader.readZigZagInt() === 2147483647);
assert(reader.readZigZagInt() === -2147483648);
assert(reader.isEmpty());
assertThrown(function () {
reader.readByte();
});
writer = new yass.Writer(100);
writer.writeByte(128);
writer.writeByte(128);
writer.writeByte(128);
writer.writeByte(128);
writer.writeByte(128);
reader = writer2reader(writer);
assertThrown(function () {
reader.readVarInt();
});
function utf8(bytes: number, value: string): void {
assert(yass.Writer.calcUtf8bytes(value) === bytes);
const writer = new yass.Writer(100);
writer.writeUtf8(value);
assert(writer.getArray().length === bytes);
const reader = writer2reader(writer);
assert(reader.readUtf8(bytes) === value);
assert(reader.isEmpty());
}
utf8(2, "><");
utf8(3, ">\u0000<");
utf8(3, ">\u0001<");
utf8(3, ">\u0012<");
utf8(3, ">\u007F<");
utf8(4, ">\u0080<");
utf8(4, ">\u0234<");
utf8(4, ">\u07FF<");
utf8(5, ">\u0800<");
utf8(5, ">\u4321<");
utf8(5, ">\uFFFF<");
})();