importuvm_compat_pkg::*;// Inside the task/function that packs the existing packet:uvm_compat_packerpacker=new();bitbits[];intnbits;nbits=packet.pack(bits,packer);
// - For queues, dynamic arrays, and associative arrays, pack 32 bits// indicating the size of the array prior to packing individual elements.bituse_metadata;// Variable: big_endian//// This bit determines the order that integral data is packed (using// <pack_field>, <pack_field_int>, <pack_time>, or <pack_real>) and how the// data is unpacked from the pack array (using <unpack_field>,// <unpack_field_int>, <unpack_time>, or <unpack_real>). When the bit is set,// data is associated msb to lsb; otherwise, it is associated lsb to msb. //// The following code illustrates how data can be associated msb to lsb and// lsb to msb:////| class mydata extends uvm_object;//|
//| d.pack(bits); // 'b0010110001001000//| endbitbig_endian=1;// variables and methods primarily for internal usestaticbitbitstream[];// local bits for (un)pack_bytesstaticbitfabitstream[];// field automation bits for (un)pack_bytesintcount;// used to count the number of packed bitsuvm_scope_stackscope=new;bitreverse_order;//flip the bit order aroundbytebyte_size=8;//set up bytesize for endianessintword_size=16;//set up worksize for endianessbitnopack;//only count packable bitsuvm_recursion_policy_enumpolicy=UVM_DEFAULT_POLICY;
// 16.5.1 of 1800.2-2020// @uvm-ieee 1800.2-2020 auto 16.5.1classuvm_packerextendsuvm_policy;// @uvm-ieee 1800.2-2020 auto 16.5.2.3`uvm_object_utils(uvm_packer)uvm_factorym_factory;localuvm_objectm_object_references[int];// Function -- NODOCS -- set_packed_*// Implementation of P1800.2 16.5.3.1//// The LRM specifies the set_packed_* methods as being// signed, whereas the <uvm_object::unpack> methods are specified// as unsigned. This is being tracked in Mantis 6423.//