Skip to content

Commit

Permalink
cbor serde implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed May 16, 2024
1 parent 1bb19ca commit b38fa63
Show file tree
Hide file tree
Showing 4 changed files with 566 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@smithy/smithy-client": "workspace:^",
"@smithy/types": "workspace:^",
"@smithy/util-middleware": "workspace:^",
"@smithy/util-utf8": "workspace:^",
"tslib": "^2.6.2"
},
"engines": {
Expand Down
31 changes: 31 additions & 0 deletions packages/core/src/submodules/cbor/cbor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { cbor } from "./cbor";

const toBytes = (string) => {
const bytes = [] as number[];
string.replace(/../g, function (pair) {
bytes.push(parseInt(pair, 16));
});
return new Uint8Array(bytes);
};

describe("cbor", () => {
it("should", async () => {
const encoded = toBytes(
"A663696E74FB41DFFFFFFFC66666666E6567696E742065666C6F6174F9FC00636D6170A2666E6567696E742065666C6F6174C2F93E006474727565F56566616C73659F01F4FF"
);
console.log("encoded", encoded);

const decoded = cbor.deserialize(encoded);
console.log("decoded", decoded);

const reencoded = cbor.serialize(decoded);
console.log("reencoded", reencoded);

const redecoded = cbor.deserialize(reencoded);
console.log("redecoded", redecoded);

const badobj = {} as any;
badobj.a = badobj;
cbor.serialize(badobj);
});
});
Loading

0 comments on commit b38fa63

Please sign in to comment.