Giter VIP home page Giter VIP logo

Comments (6)

NYBACHOK avatar NYBACHOK commented on July 20, 2024 1

I resolved issue with my code so thanks you again

from data-encoding.

ia0 avatar ia0 commented on July 20, 2024

Hi, thanks for reaching out!

Could you provide me a bit more information about what you're trying to do exactly? Ideally with code pointers and example data input and output. In particular, which tag number of CBOR are you concerned about? 21, 22, 33, and 34 seem to be the relevant ones.

Thanks!

from data-encoding.

NYBACHOK avatar NYBACHOK commented on July 20, 2024

Thanks for fast reply!

I want to write tests checks if CBOR/RFC 8949 implementation correct. As I understand bytes in writter is correct and issue when I'm creating hex representation.

#[test]
    fn check_unsigned_int()
    {
        // Examples come from RFC8949, Appendix A
        let var = 
        [
            ( 0_u64, "00" ),
            ( 1, "01" ),
            ( 10, "0a"),
            ( 23, "17"),
            ( 24, "1818"),
            ( 25, "1819"),
            ( 100, "1864" ),
            ( 1000, "1903e8"),
            ( 1000000, "1a000f4240"),
            ( 1000000000000, "1b000000e8d4a51000"),
            ( 18446744073709551615, "1bffffffffffffffff" ),
        ];

        validate_result( var )
    }
    
     fn validate_result<T : Cbor>(value : impl IntoIterator<Item = (T, &'static str)>)
    {
        for ( i, expected ) in value
        {
            let mut buf = Vec::new();

            i.encode(&mut buf).expect(&format!( "Failed to write buffer for {}", i));

            let hex = data_encoding::HEXLOWER.encode( &buf );

            assert_eq!( &hex, expected );
        }
    }
    assertion `left == right` failed
  left: "1900000000000003e8"
 right: "1903e8"

from data-encoding.

ia0 avatar ia0 commented on July 20, 2024

Thanks for the code. This looks to me like a problem in the CBOR encoding. You can see it by comparing at the byte level instead of the hexadecimal representation.

-let hex = data_encoding::HEXLOWER.encode( &buf );
-assert_eq!( &hex, expected );
+let expected = data_encoding::HEXLOWER.decode(expected.as_bytes()).unwrap();
+assert_eq!(buf, expected, "{buf:02x?} != {expected:02x?}");

from data-encoding.

NYBACHOK avatar NYBACHOK commented on July 20, 2024

I forget that I may compare bytes representation. Thanks for that!

from data-encoding.

ia0 avatar ia0 commented on July 20, 2024

Perfect, thanks a lot for the feedback!

from data-encoding.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.