Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Alternative map sorting

Đang mở
#173 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
c
Lĩnh vực
embedded-iot

Hướng nghiên cứu

Bắt đầu tại cborvalidation.c khoảng dòng 475 và xem xét các flag hiện có về sắp xếp map và tính duy nhất. Làm rõ liệu việc sắp xếp thay thế nên thay thế hay bổ sung cho hành vi hiện tại, sau đó xác định thứ tự mong đợi, cách xử lý key và hành vi đối với các key trùng lặp; việc hoàn thành phụ thuộc vào thiết kế và phạm vi triển khai đã được thống nhất.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Hello,

I've been looking into the CBOR validator and how maps are considered as sorted or not. In another project, I have previously been using another serialization standard that strictly defines maps in another way. Such as keys must only be strings, keys must be stored in lexicographical order and that no duplicates are allowed. Now we are looking into changing to cbor.

The CBOR specification does not strictly specifies what an ordered map is, but recommends that they should also be sorted in length. Meaning that "aa" > "b".

The alternatives are:

  • Change sorting specification in our protocol (to order the fields like CBOR specification recommends)
  • Not having sorted maps
  • Finding/adapting a cbor library to allow for alternative sorting

Sorting is nice since is allows for linear parsing. Since we rely on this, we cannot directly swap to cbor. I would like to start a discussion of supporting an alternative sorting in tinycbor.

Wrote a short proof of concept for this (removes old sorting behavior) cborvalidation.c:475:

        if (flags & CborValidateMapIsSorted) {
            if (previous) {
                uint64_t len1, len2;
                const uint8_t *ptr;

                /* extract the two lengths */
                ptr = previous;
                _cbor_value_extract_number(&ptr, it->parser->end, &len1);
                ptr = current;
                _cbor_value_extract_number(&ptr, it->parser->end, &len2);


                size_t bytelen1 = (size_t)(previous_end - previous);
                size_t bytelen2 = (size_t)(it->ptr - current);

                /*
                 * Offset of actual key value (not including type information) is bytelenX - lenX??
                 * What if key value is indefinite??
                 */

                int r = memcmp(&previous[bytelen1 - len1], &current[bytelen2 - len2], len1 <= len2 ? len1 : len2);

                if (r == 0 && len1 != len2)
                    r = len1 < len2 ? -1 : +1;
                if (r > 0)
                    return CborErrorMapNotSorted;
                if (r == 0 && (flags & CborValidateMapKeysAreUnique) == CborValidateMapKeysAreUnique)
                    return CborErrorMapKeysNotUnique;

            }

Would it be possible to add a flag that would allow for this kind of sorting?

Ngôn ngữ chính
C
Star
632
Fork
222
Merge trung bình
1 ngày 25 phút
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của intel/tinycbor

Tất cả issue của intel/tinycbor

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.