當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Writer.writeZigZagInt方法代碼示例

本文整理匯總了TypeScript中yass.Writer.writeZigZagInt方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Writer.writeZigZagInt方法的具體用法?TypeScript Writer.writeZigZagInt怎麽用?TypeScript Writer.writeZigZagInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yass.Writer的用法示例。


在下文中一共展示了Writer.writeZigZagInt方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: assert

    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);
開發者ID:sneusi,項目名稱:yass,代碼行數:31,代碼來源:test.ts

示例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<");

})();
開發者ID:sushicutta,項目名稱:yass,代碼行數:92,代碼來源:test.ts


注:本文中的yass.Writer.writeZigZagInt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。