当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript yass.Writer类代码示例

本文整理汇总了TypeScript中yass.Writer的典型用法代码示例。如果您正苦于以下问题:TypeScript Writer类的具体用法?TypeScript Writer怎么用?TypeScript Writer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Writer类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: utf8

 function utf8(bytes: number, value: string): void {
     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());
 }
开发者ID:sneusi,项目名称:yass,代码行数:8,代码来源:test.ts

示例2: 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

示例3: 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

示例4: Error

    throw new Error("test")
});

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);
开发者ID:sneusi,项目名称:yass,代码行数:31,代码来源:test.ts

示例5: 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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。