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


TypeScript Writer.writeByte方法代碼示例

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


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

示例1: opened

 protected opened(): void {
     log("session opened", this.isClosed());
     function doLog(context: yass.SimpleInterceptorContext, kind: string, data: any): void {
         log("logger:", kind, context.id, context.methodMapping.method, data);
     }
     const printer: yass.Interceptor<yass.SimpleInterceptorContext> = {
         entry(methodMapping: yass.MethodMapping, parameters: any[]): yass.SimpleInterceptorContext {
             const context = new yass.SimpleInterceptorContext(methodMapping, parameters);
             doLog(context, "entry", parameters);
             return context;
         },
         exit(context: yass.SimpleInterceptorContext, result: any): void {
             doLog(context, "exit", result);
         },
         exception(context: yass.SimpleInterceptorContext, exception: any): void {
             doLog(context, "exception", exception);
         },
         resolved(context: yass.SimpleInterceptorContext): void {
             doLog(context, "resolved", "");
         }
     };
     const instrumentService = this.proxy(contract.acceptor.instrumentService, printer);
     const priceEngine = this.proxy(contract.acceptor.priceEngine, printer);
     const echoService = this.proxy(contract.acceptor.echoService, printer);
     instrumentService.showOneWay(false, new IntegerImpl(123));
     echoService.echo(null).then(result => assert(result === null));
     echoService.echo(undefined).then(result => assert(result === null));
     echoService.echo(true).then(result => assert(result === true));
     echoService.echo(false).then(result => assert(result === false));
     const stock = new contract.instrument.stock.Stock;
     stock.id = new IntegerImpl(123);
     stock.name = null;
     stock.paysDividend = false;
     echoService.echo(stock).then(result => {
         assert(result.id.get() === 123);
         assert(result.name === undefined);
         assert(result.paysDividend === false);
     });
     echoService.echo(new IntegerImpl(12345678)).then(result =>  assert(result.get() === 12345678));
     echoService.echo(new IntegerImpl(-87654321)).then(result  => assert(result.get() === -87654321));
     echoService.echo(123.456e98).then(result => assert(result === 123.456e98));
     echoService.echo(-9.384762637432E-12).then(result => assert(result === -9.384762637432E-12));
     echoService.echo(new contract.Expiration(9, 8, 7)).then(expiration => {
         log("then", expiration);
         assert(expiration.year === 9);
         assert(expiration.month === 8);
         assert(expiration.day === 7);
     });
     const writer = new yass.Writer(1);
     writer.writeByte(123);
     writer.writeByte(0);
     writer.writeByte(210);
     echoService.echo(writer.getArray()).then(result => {
         const reader = new yass.Reader(toArrayBuffer(result));
         assert(reader.readByte() === 123);
         assert(reader.readByte() === 0);
         assert(reader.readByte() === 210);
         assert(reader.isEmpty());
     });
     priceEngine.subscribe([new IntegerImpl(987654321)]).catch(exception => log("subscribe failed with", exception));
     setTimeout(() => this.close(), 2000);
 }
開發者ID:sneusi,項目名稱:yass,代碼行數:62,代碼來源: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

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

示例4: serializerTest

(function serializerTest() {

    function copy(value: any): any {
        const writer = new yass.Writer(100);
        contract.SERIALIZER.write(value, writer);
        const reader = writer2reader(writer);
        const result = contract.SERIALIZER.read(reader);
        assert(reader.isEmpty());
        return result;
    }

    assert(copy(null) === null);
    assert(copy(true));
    assert(!copy(false));
    assert(copy(1234567) === 1234567);
    assert(copy(-1234567) === -1234567);
    assert(copy("") === "");
    assert(copy("blabli") === "blabli");
    assert(copy(PriceKind.ASK) === PriceKind.ASK);
    assert(copy(PriceKind.BID) === PriceKind.BID);
    assert(copy(new IntegerImpl(123456)).get() === 123456);
    assert(copy(new IntegerImpl(-987654)).get() === -987654);

    function compare(array1: any[], array2: any[]): boolean {
        if (array1.length !== array2.length) {
            return false;
        }
        for (let i = 0; i < array1.length; i++) {
            const e1 = array1[i];
            const e2 = array2[i];
            if (e1 instanceof IntegerImpl) {
                if (e1.get() !== e2.get()) {
                    return false;
                }
            } else if (e1 !== e2) {
                return false;
            }
        }
        return true;
    }

    assert(Array.isArray(copy([])));
    assert(copy([]).length === 0);
    assert(compare(copy([12]), [12]));
    assert(compare(copy([12, true, "bla"]), [12, true, "bla"]));

    let stock = new contract.instrument.stock.Stock;
    stock.id = new IntegerImpl(1344);
    stock.name = "IBM";
    stock.paysDividend = true;
    stock = copy(stock);
    assert(stock.id.get() === 1344);
    assert(stock.name === "IBM");
    assert(stock.paysDividend);
    stock.paysDividend = false;
    stock = copy(stock);
    assert(!stock.paysDividend);
    stock.paysDividend = null!;
    stock = copy(stock);
    assert(stock.paysDividend === undefined);

    let bond = new contract.instrument.Bond;
    bond.coupon = 3.5;
    bond.expiration = new contract.Expiration(2013, 2, 20);
    bond = copy(bond);
    assert(bond.coupon === 3.5);
    assert(bond.expiration.year === 2013);
    assert(bond.expiration.month === 2);
    assert(bond.expiration.day === 20);

    let e = new contract.UnknownInstrumentsException;
    e.instrumentIds = [new IntegerImpl(100), new IntegerImpl(200)];
    e = copy(e);
    assert(compare(e.instrumentIds, [new IntegerImpl(100), new IntegerImpl(200)]));

    let price = new contract.Price;
    price.instrumentId = new IntegerImpl(123);
    price.kind = PriceKind.ASK;
    price.value = new IntegerImpl(999);
    price = copy(price);
    assert(price.instrumentId.get() === 123);
    assert(price.kind === PriceKind.ASK);
    assert(price.value.get() === 999);

    let writer = new yass.Writer(1);
    writer.writeByte(123);
    writer.writeByte(0);
    writer.writeByte(210);
    let reader = new yass.Reader(copy(writer.getArray()));
    assert(reader.readByte() === 123);
    assert(reader.readByte() === 0);
    assert(reader.readByte() === 210);
    assert(reader.isEmpty());

    assert(new yass.Reader(copy(new yass.Writer(1).getArray())).isEmpty());

    let exception = new contract.UnknownInstrumentsException;
    exception.onlyNeededForTests1 = 123456;
    writer = new yass.Writer(1);
    writer.writeByte(121);
//.........這裏部分代碼省略.........
開發者ID:sushicutta,項目名稱:yass,代碼行數:101,代碼來源:test.ts


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