本文整理匯總了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<");
})();