-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add initial CBOR codec support #958
Conversation
I have tested and it indeed works. I have used the following script const { Servient, Helpers } = require("@node-wot/core");
const { CoapClientFactory } = require("@node-wot/binding-coap");
const { HttpClientFactory } = require("@node-wot/binding-http");
// create Servient and add CoAP binding
const servient = new Servient();
servient.addClientFactory(new CoapClientFactory());
servient.addClientFactory(new HttpClientFactory());
const td = {
"@context": "https://www.w3.org/2022/wot/td/v1.1",
title: "CborTestThing",
securityDefinitions: {
nosec_sc: { scheme: "nosec" },
},
security: "nosec_sc",
properties: {
test1: {
forms: [
{
href: "coap://californium.eclipseprojects.io/multi-format",
contentType: "application/cbor",
"cov:accept": 60,
},
],
},
test2: {
forms: [
{
href: "coap://californium.eclipseprojects.io/multi-format",
contentType: "application/json",
"cov:accept": 50,
},
],
},
test3: {
forms: [
{
href: "http://plugfest.thingweb.io:8083/testthing/properties/bool",
contentType: "application/json",
},
],
},
},
};
const wotHelper = new Helpers(servient);
async function main() {
const WoT = await servient.start();
const thing = await WoT.consume(td);
// read property
const read1 = await thing.readProperty("test1");
console.log("value1 is: ", await read1.value());
const read2 = await thing.readProperty("test2");
console.log("value2 is: ", await read2.value());
const read3 = await thing.readProperty("test3");
console.log("value3 is: ", await read3.value());
}
main() I get:
|
@JKRhb could you also change the readme at https://github.com/eclipse/thingweb.node-wot/blob/master/README.md?plain=1#L79 |
Thank you for testing! :)
Done in 1e3e895 :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! 🥳
Corresponding with #953, this PR adds initial support for CBOR encoding and decoding. For now, the Codec is added to the
core
package, but as discussed in the issue, it should probably be moved to its owncodec-cbor
package, either in this PR or a follow-up.Future additions to the codec should include support for custom tag encoding/decoding1, but for now, at least all basic JavaScript data types should be supported (via the cbor package).
Footnotes
See RFC 8949, section 3.4 for more information on CBOR tags (sorry for confusing the purpose of tags a bit at the community meetup on Thursday 😅). ↩