JSON-for-VHDL icon indicating copy to clipboard operation
JSON-for-VHDL copied to clipboard

Decoding odd-length strings

Open rhinton opened this issue 3 years ago • 2 comments

Function base16_decode in Encodings.pkg.vhdl fails on odd-length strings. Suggested correction:

  function base16_decode(constant str: string) return string is
    variable result: string (1 to (str'length + 1) / 2);
    variable str_i : string(1 to 2 * result'length);
  begin
    str_i := (others => ' ');
    str_i(1 to str'length) := str;
    for x in result'range loop
      result(x) := character'val(to_integer(
        to_unsigned(from_hex_string(
          str_i(2 * x - 1 to 2 * x),
          7, 0
        ), 8)
      ));
    end loop;
    return result;
  end function;

rhinton avatar Nov 27 '21 03:11 rhinton

LGTM! @rhinton, do you want to propose a PR?

/cc @Paebbels @LarsAsplund

umarcor avatar Nov 29 '21 17:11 umarcor

I would like to see the the init value of str_i being moved into the variable declaration to keep the function body clean.


@rhinton are you a user of this library? Do you use it in synthesis or simulation (or because of VUnit?)?

Paebbels avatar Nov 29 '21 19:11 Paebbels