How to use the protobufjs.ByteBuffer.fromHex function in protobufjs

To help you get started, we’ve selected a few protobufjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openchain / openchain-js / tests / encoding.js View on Github external
it("decodeString", function () {
        var result = openchain.encoding.decodeString(ByteBuffer.fromHex("414243"));
        assert.equal(result, "ABC");
    });
github openchain / openchain-js / tests / encoding.js View on Github external
it("decodeInt64", function () {
        var result1 = openchain.encoding.decodeInt64(ByteBuffer.fromHex("00000000000061a8"));
        var result2 = openchain.encoding.decodeInt64(ByteBuffer.fromHex(""));
        
        assert.deepEqual(result1, Long.fromString("25000", false));
        assert.deepEqual(result2, Long.fromString("0", false));
    });
});
github openchain / openchain-js / tests / recordkey.js View on Github external
it("parse ByteBuffer", function () {
        var result = RecordKey.parse(ByteBuffer.fromHex("2f6163636f756e742f706174682f3a4143433a2f61737365742f706174682f"));
        
        assert.equal(result.path.toString(), "/account/path/");
        assert.equal(result.recordType, "ACC");
        assert.equal(result.name, "/asset/path/");
    });
github openchain / openchain-js / tests / apiclient.js View on Github external
it('getDataRecord with version', function () {
        return client.getDataRecord("/", "info", ByteBuffer.fromHex("")).then(function (result) {
            assert.equal(result.key.toHex(), "2f3a444154413a696e666f");
            assert.equal(result.value.toHex(), "");
            assert.equal(result.version.toHex(), "");
            assert.equal(result.data, null);
        });
    });
github openchain / openchain-js / tests / transactionbuilder.js View on Github external
it("addRecord", function () {
        var builder = new TransactionBuilder(new ApiClientMock());
        
        builder.addRecord(ByteBuffer.fromHex("ab"), ByteBuffer.fromHex("cd"), ByteBuffer.fromHex("ef"));
        builder.addRecord(ByteBuffer.fromHex("12"), null, ByteBuffer.fromHex("34"));
        
        assert.deepEqual(builder.records, [
            { "key": ByteBuffer.fromHex("ab"), "value": { "data": ByteBuffer.fromHex("cd") }, "version": ByteBuffer.fromHex("ef") },
            { "key": ByteBuffer.fromHex("12"), "value": null, "version": ByteBuffer.fromHex("34") }
        ]);
    });
github openchain / openchain-js / tests / apiclient.js View on Github external
it('getRecord fail', function () {
        return client.getRecord("/:DATA:info", ByteBuffer.fromHex("abcd")).then(function (result) {
            assert.fail();
        }, function (err) {
            assert.equal(404, err.statusCode);
        });
    });
github openchain / openchain-js / tests / apiclient.js View on Github external
it('getRecord ByteBuffer', function () {
        return client.getRecord(ByteBuffer.fromHex("0000")).then(function (result) {
            assert.equal(result.key.toHex(), "0000");
            assert.equal(result.value.toHex(), "");
            assert.equal(result.version.toHex(), "");
        });
    });
github openchain / openchain-js / tests / transactionbuilder.js View on Github external
it("build", function () {
        var builder = new TransactionBuilder(new ApiClientMock());
        
        builder.addRecord(ByteBuffer.fromHex("ab"), ByteBuffer.fromHex("cd"), ByteBuffer.fromHex("ef"));
        builder.addRecord(ByteBuffer.fromHex("12"), null, ByteBuffer.fromHex("34"));
        builder.setMetadata({ "hello": "world" });
        
        var result = builder.build();
        
        assert.equal(result.toHex(), "0a03abcdef120b0a01ab12030a01cd1a01ef12060a01121a01341a117b2268656c6c6f223a22776f726c64227d");
    });
github openchain / openchain-js / tests / transactionbuilder.js View on Github external
this.getDataRecord = function (path, recordName) {
        var key = new RecordKey(path, "DATA", recordName).toByteBuffer();
        
        var result;
        if (recordName == "goto" && _this.gotoRecords[path]) {
            result = _this.gotoRecords[path];
        }
        else {
            result = null;
        }
        
        return q.resolve({ data: result, key: key, version: ByteBuffer.fromHex("aaaa") });
    };
github openchain / openchain-js / lib / apiclient.js View on Github external
return this.getInfo().then(function (result) {
        _this.namespace = ByteBuffer.fromHex(result.namespace);
    });
};