How to use the cbor.decodeFirst function in cbor

To help you get started, we’ve selected a few cbor 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 IoTKETI / Mobius / mobius / responder.js View on Github external
if(bodytype === 'xml') {
                var xml2js = require('xml2js');
                var parser = new xml2js.Parser({explicitArray: false});
                parser.parseString(message.utf8Data.toString(), function (err, jsonObj) {
                    if (err) {
                        console.log('[nonblocking-async-ws] xml2js parser error');
                    }
                    else {
                        console.log('----> [nonblocking-async-ws] response for notification through mqtt ' + res.headers['x-m2m-rsc']);
                        connection.close();
                    }
                });
            }
            else if(bodytype === 'cbor') {
                var encoded = message.utf8Data.toString();
                cbor.decodeFirst(encoded, function(err, jsonObj) {
                    if (err) {
                        console.log('[nonblocking-async-ws] cbor parser error');
                    }
                    else {
                        if (jsonObj.rsc == 2001 || jsonObj.rsc == 2000) {
                            console.log('----> [nonblocking-async-ws] response for notification through ws ' + jsonObj.rsc);
                            connection.close();
                        }
                    }
                });
            }
            else { // 'json'
                var jsonObj = JSON.parse(message.utf8Data.toString());

                try {
                    if (jsonObj.rsc == 2001 || jsonObj.rsc == 2000) {
github citelab / JAMScript / lib / jserver / jnode.js View on Github external
mserv.on('message', function(topic, buf) {

        cbor.decodeFirst(buf, function(error, msg) {

            switch (topic) {
                case '/admin/request/all':
                // Requests are published here by nodes under this broker
                    try {
                        adminService(msg, function(rmsg) {
                            var encode = cbor.encode(rmsg);
                            mserv.publish('/admin/announce/all', encode);
                        });
                    } catch (e) {
                        console.log("ERROR!: ", e);
                    }
                break;

                case '/level/func/request':
                // These are requests by the C nodes under this broker
github citelab / JAMScript / lib / jserver / OLD_VERSIONS / jserver-notworking.js View on Github external
rep.on('data', function(buf) {
	console.log("Buffer size " + Buffer.byteLength(buf));
	cbor.decodeFirst(buf, function(error, msg) {
		// if error != null .. it seems nanomsg is
		// receiving more bytes than what the C sent..
		// TODO: investigate this problem.
		//
		processMsg(rep, msg)
		console.log("Helllo");
	});
});
github citelab / JAMScript / lib / jserver / OLD_VERSIONS / temp2.js View on Github external
sock.on('data', function(buf) {
		console.log("In new service.. Buffer size " + Buffer.byteLength(buf));
		cbor.decodeFirst(buf, function(error, msg) {
			console.log(msg);
			if (msg["cmd"] == "PING") {
				msg["cmd"] = "PONG";
				var encode = cbor.encode(msg);
				sock.send(encode);

			}

		});
	});
github hyperledger / sawtooth-core / clients / javascript / spec / ecdsa_encryption_spec.js View on Github external
it('should produce output optionally as a cbor buffer', (done) => {
            let signedTxn =
                ecdsaEncryption.signUpdate(
                        '/my_txn_family',
                        {"x": 1, "y": 2},
                        TEST_WIF,
                        {output: "cbor"});

            assert.isTrue(Buffer.isBuffer(signedTxn));

            cbor.decodeFirst(signedTxn, (err, unmarshelled) => {
                assert.isNull(err);
                assert.equal(unmarshelled.__TYPE__, '/my_txn_family');
                assert.isNumber(unmarshelled.__NONCE__);
                assert.isNotNull(unmarshelled.__SIGNATURE__);

                assert.equal(unmarshelled.Transaction.x, 1);
                assert.equal(unmarshelled.Transaction.y, 2);
                assert.isNotNull(unmarshelled.Transaction.Signature);
                done();
            });
        });
    });
github citelab / JAMScript / lib / jserver / OLD_VERSIONS / ttserv.js View on Github external
sock.on('data', function(buf) {
		console.log("In new service.. Buffer size " + Buffer.byteLength(buf));
		cbor.decodeFirst(buf, function(error, msg) {
			console.log(msg);
		});
	});
github hyperledger / sawtooth-core / sdk / examples / intkey_javascript / integer_key_handler.js View on Github external
new Promise((resolve, reject) =>
              cbor.decodeFirst(buffer, (err, obj) => err ? reject(err) : resolve(obj)))
github citelab / JAMScript / lib / jserver / TEST_VERSIONS / jamlib2.js View on Github external
sock.on('data', function(buf) {
		cbor.decodeFirst(buf, function(error, msg) {
			if ((msg["cmd"] === "REXEC") &&
				(msg["opt"] === "SYN")) {
				runSyncCallback(sock, msg);
			}
			else
			if ((msg["cmd"] === "REXEC") &&
				(msg["opt"] === "ASY")) {
				runAsyncCallback(sock, msg);
			}
			else
			if ((msg["cmd"] === "REXEC-RES") &&
				(msg["opt"] === "GET")) {
				getResults(sock, msg);
			}
			else
			if ((msg["cmd"] === "REXEC-RDY") &&
github IoTKETI / Mobius / app.js View on Github external
request.headers.rootnm = Object.keys(body_Obj)[0];
                    request.bodyObj = body_Obj;
                    callback('1', body_Obj);
                }
            });
        }
        catch(e) {
            responder.error_result(request, response, 400, 4000, '[parse_to_json] do not parse xml body');
            callback('0', body_Obj);
            return '0';
        }
    }
    else if (request.usebodytype === 'cbor') {
        try {
            var encoded = request.body;
            cbor.decodeFirst(encoded, function(err, result) {
                if (err) {
                    responder.error_result(request, response, 400, 4000, '[parse_to_json] do not parse cbor body');
                    callback('0', body_Obj);
                    return '0';
                }
                else {
                    body_Obj = result;
                    make_short_nametype(body_Obj);
                    //make_json_arraytype(body_Obj);

                    request.headers.rootnm = Object.keys(body_Obj)[0];
                    request.bodyObj = body_Obj;
                    callback('1', body_Obj);
                }
            });
        }

cbor

Encode and parse data in the Concise Binary Object Representation (CBOR) data format (RFC8949).

MIT
Latest version published 3 months ago

Package Health Score

78 / 100
Full package analysis