Skip to content
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(cbor): add encoding/decoding for new Map() instance #6252

Merged
merged 4 commits into from
Dec 12, 2024

Conversation

BlackAsLight
Copy link
Contributor

Closes: #6249

These changes adds support for accepting a Map instance in encodeCbor and returning it again from decodeCbor. It achieves this via the 259 tag number (Spec).

While the code is mostly the same for encoding and decoding Objects, it differs in the need for limiting keys to only strings. It also guarantees that the order isn't at risk of being changed due to encoding/decoding.

This pull request does not add support for accepting Map instances via the streaming methods of this library. The logistics for decoding that is a bit more trickier to figure out.

import { assertEquals } from "@std/assert";
import { type CborType, decodeCbor, encodeCbor } from "@std/cbor";

assertEquals(
  decodeCbor(encodeCbor(new Map([[ 1, 2 ], [ "3", 4 ], [ [5], { a: 6 } ]]))),
  new Map([[ 1, 2 ], [ "3", 4 ], [ [5], { a: 6 } ]])
);

@BlackAsLight BlackAsLight requested a review from kt3k as a code owner December 11, 2024 06:58
@github-actions github-actions bot added the cbor label Dec 11, 2024
Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 87.80488% with 10 lines in your changes missing coverage. Please review.

Project coverage is 96.51%. Comparing base (7480f35) to head (5a5a256).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
cbor/_common_decode.ts 88.00% 6 Missing ⚠️
cbor/_common_encode.ts 86.66% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6252      +/-   ##
==========================================
- Coverage   96.52%   96.51%   -0.02%     
==========================================
  Files         535      535              
  Lines       41030    41108      +78     
  Branches     6141     6161      +20     
==========================================
+ Hits        39606    39676      +70     
- Misses       1382     1390       +8     
  Partials       42       42              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

LGTM

@kt3k kt3k merged commit 283cf34 into denoland:main Dec 12, 2024
18 checks passed
@BlackAsLight BlackAsLight deleted the cbor_map branch December 12, 2024 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@std/cbor, maps don't work
2 participants