Does do_unpack_ints works?

Hi,

I was trying to do simple user defined “unpack”, I have tried to do “unpack_ints”.
Issue is unpack didn’t happen. I am not sure what I have missed. But when I tried changed
input array type to “byte” and used “unpack_bytes” it worked as per expectation. I am not
sure why “unpack_ints” didn’t work.

Code:

`include "uvm_macros.svh" 
package my_pkg;
import uvm_pkg::*;
class Packet extends uvm_sequence_item; 
rand bit [7:0] length; 
rand bit [7:0] da; 
rand bit [7:0] sa; 
rand bit [7:0] data[]; 

function new(string name = ""); 
super.new(name); 
endfunction : new 

function void do_unpack(uvm_packer packer); 
int sz; 
super.do_pack(packer); 

da = packer.unpack_field_int($bits(da)); 
sa = packer.unpack_field_int($bits(sa)); 
length = packer.unpack_field_int($bits(length)); 

data.delete(); 
data = new[length]; 
foreach(data[i]) 
data[i] = packer.unpack_field_int(8); 
endfunction : do_unpack 

endclass : Packet 
endpackage: my_pkg

module test; 
  import uvm_pkg::*;
  import my_pkg::*;
  Packet pkt2 = new("pkt2"); 
  int unsigned pkdbytes[]; 
initial
begin
repeat(1) 
  pkdbytes = new[9]; 
  $display("Size of pkd bits %d",pkdbytes.size()); 
  for(int i=0; i < pkdbytes.size(); i++)
  begin
      pkdbytes[0] = 'hFF;
  end
  pkt2.unpack_ints(pkdbytes); 
  pkt2.print();
  $display("pkt2.da:%0h, pkt2.sa:%0h",pkt2.da,pkt2.sa);
end 
endmodule 

Output:

Size of pkd bits 9

Name Type Size Value

pkt2 uvm_sequence_item - @456

pkt2.da:0, pkt2.sa:0

Thanks,
Karthik

In reply to govindarajan.karthik:
unpack_int is working fine. The problem is how you initialized pkdbytes. Take a good look at it.