microsoft / jacdac

Device and service catalogs for Jacdac.
https://aka.ms/jacdac
Creative Commons Attribution 4.0 International
66 stars 25 forks source link

jdpack max_bytes is too strict #260

Closed pelikhan closed 3 years ago

pelikhan commented 3 years ago

When applying the max_bytes constraint to a string, the jdpack format s[n] complains if the string is shorter than n characters.

    command send_string @ 0x80 {
        message: string { max_bytes=18 }
    }
mmoskal commented 3 years ago

Seems to work for me:

> jacdac.jdpack("s[18]", ["foo"])
[102, 111, 111, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
> jacdac.jdunpack( jacdac.jdpack("s[18]", ["foo"]), "s[18]" )
["foo"]