Skip to content

Add cbor encode decode#293

Merged
spring1843 merged 5 commits intomainfrom
add-cbor-encode-decode
Apr 20, 2026
Merged

Add cbor encode decode#293
spring1843 merged 5 commits intomainfrom
add-cbor-encode-decode

Conversation

@spring1843
Copy link
Copy Markdown
Owner

  • Add CBOR, JSON encode/decode

Copilot AI review requested due to automatic review settings April 20, 2026 04:56
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 20, 2026

Deploy Preview for freedevtool ready!

Name Link
🔨 Latest commit 1725d6c
🔍 Latest deploy log https://app.netlify.com/projects/freedevtool/deploys/69e5b687a5bb7300094a5a66
😎 Deploy Preview https://deploy-preview-293--freedevtool.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new CBOR encoder/decoder tool to FreeDevTool.App, including core CBOR encode/decode helpers, byte formatting utilities (hex/base64), and automated coverage (unit + Playwright e2e) to validate behavior.

Changes:

  • Add CBOR encode/decode + Uint8Array↔hex/base64 utilities to the shared encoders library.
  • Introduce a new “CBOR Encoder/Decoder” tool page, wire it into routing, defaults, and the tools registry.
  • Add unit tests for CBOR + byte conversion helpers and an e2e test for the new tool.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
client/src/lib/encoders.ts Adds CBOR encode/decode and hex/base64 conversion helpers.
client/src/pages/tools/cbor-encoder.tsx New CBOR tool UI with encode/decode actions and hex/base64 output tabs.
client/src/data/defaults.ts Adds default JSON example for the CBOR tool.
client/src/data/tools.ts Registers the new CBOR tool (metadata, shortcut, explanations).
client/src/App.tsx Adds lazy import + route for /tools/cbor-encoder.
tests/lib/encoders.test.ts Adds unit tests for CBOR and byte conversion helpers.
tests/e2e/tools/cbor-encoder.spec.ts Adds Playwright coverage for page load, tab switching, and invalid JSON error handling.
package.json Adds cbor-x dependency.
package-lock.json Locks cbor-x and its optional/native deps.

Comment thread client/src/pages/tools/cbor-encoder.tsx Outdated
Comment on lines +95 to +99
const jsonBytes = new TextEncoder().encode(jsonInput).length;
const cborBytes = cborHex
? Math.floor(cborHex.replace(/\s+/g, "").length / 2)
: 0;
const savings =
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cborBytes (and the size/savings display) is derived from cborHex only. When the Base64 tab is active (or if hex is empty but base64 has data), the byte count and savings indicator will be missing or inaccurate. Consider computing the CBOR byte length from the active output tab (decode hex/base64 to bytes) or tracking the last encoded byte array length in state.

Copilot uses AI. Check for mistakes.
Comment on lines +242 to +246
it("should produce output smaller than or similar in size to JSON for typical objects", () => {
const json =
'{"name":"Alice","role":"admin","active":true,"score":9999,"tags":["a","b","c"]}';
const bytes = encodeToCBOR(json);
expect(bytes.length).toBeLessThan(json.length);
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test compares bytes.length to json.length (character count) and asserts CBOR is strictly smaller. CBOR is not guaranteed to be smaller for all payloads, and json.length can differ from UTF-8 byte size for non-ASCII. To avoid a fragile test, compare against new TextEncoder().encode(json).length and consider relaxing/removing the strict “smaller than JSON” assertion (keep round-trip correctness as the main guarantee).

Suggested change
it("should produce output smaller than or similar in size to JSON for typical objects", () => {
const json =
'{"name":"Alice","role":"admin","active":true,"score":9999,"tags":["a","b","c"]}';
const bytes = encodeToCBOR(json);
expect(bytes.length).toBeLessThan(json.length);
it("should produce a valid CBOR payload with a size comparable to UTF-8 JSON bytes for typical objects", () => {
const json =
'{"name":"Alice","role":"admin","active":true,"score":9999,"tags":["a","b","c"]}';
const bytes = encodeToCBOR(json);
const jsonByteLength = new TextEncoder().encode(json).length;
expect(bytes).toBeInstanceOf(Uint8Array);
expect(bytes.length).toBeGreaterThan(0);
expect(bytes.length).toBeLessThanOrEqual(jsonByteLength * 2);

Copilot uses AI. Check for mistakes.
Comment thread client/src/lib/encoders.ts Outdated
spring1843 and others added 3 commits April 19, 2026 22:03
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@spring1843 spring1843 merged commit e545755 into main Apr 20, 2026
4 of 5 checks passed
@spring1843 spring1843 deleted the add-cbor-encode-decode branch April 20, 2026 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants