Convert a class instance to/from dynamic byte array and viceversa

I would like to convert a class object to/from unbound byte array.

typedef enum {data_transaction, control_transaction} tr_type_en;
typedef byte dynamic_array_t[];
class transaction;
  tr_type_en              tr_type;
  logic                        ctrl1;
  logic       [1023:0] data;
  // methods
 function dynamic_array_t to_bytes();
    dynamic_array_t arr = new[1];
    arr = dynamic_array'(this);
    return arr;
endfunction
endclass

The code fails complaining that
Cadence XCelium 20.09

  1. A class type is not currently supported as source type in bit stream casting.
    Any ideas why it doesn’t work?

Questa 2021 seems to work fine.
OK, probably not supported yet, though bitstreaming classes is in the 2017 LRM.

You have a typo in your statement: arr = dynamic_array'(this); which should be arr = dynamic_array_t'(this); That works on 2 out of 4 simulators on EDAPlayground. The other 2 give “not currently supported” message means the code is recognized as a legal feature by the tool, but it has yet to be implemented. If you change to the streaming operator arr = {>>{this}};, then 3 out of 4 simulators support it.

This Mentor/Siemens EDA sponsored public forum is not for discussing tool specific usage or issues. Please read your tool’s user manual or contact your tool vendor directly for support.