UTILS(3)
π UTILS(3) π
okay bestie, sit down, hydrate, and let me tell you about packet.utils β the Pktt utilities module, chilling in utils 1.6. it's literally a glow-up for your basic data types and I'm obsessed. π¦β¨
πΈ NAME πΈ
packet.utils β Pktt utilities module. that's it, that's the name, no cap. π
π DESCRIPTION π
so the Packet trace utilities module has classes which augment functionality of basic data types β like displaying integers as their hex equivalent. it's giving "your ints but make it fashion". π
it also includes an Enum base class which displays the integer as its string representation given by a mapping dictionary. iconic behavior fr fr. β¨
there's also a class to be used as a base class for an RPC payload object. π
and this module also includes some module variables to change how certain objects are displayed. the way it just... customizes your whole vibe. π«Ά
π CLASSES π
class BitmapInval(builtins.Exception)
Exception for an invalid bit number π (yes, it's an exception, and yes, it's about a bad bit number, that's the whole lore).
class ByteHex(builtins.int)
Byte integer object which is displayed in hex π
Methods defined here:
__repr__ = __str__(self)__str__(self)β Returnstr(self).
class DateStr(builtins.float)
Floating point object which is displayed as a date π (floats but make it calendar energy)
Methods defined here:
__str__(self)β Returnstr(self).
class Enum(builtins.int)
Enum base object.
This should only be used as a base class where the class attributes should be initialized π
Methods defined here:
__repr__(self)β Official string representation, display value using the mapping dictionary provided as a class attribute whenENUM_REPRisFalse__str__(self)β Informal string representation, display value using the mapping dictionary provided as a class attribute
Static methods defined here:
__new__(cls, unpack)β Constructor which checks if integer is a valid enum value β
class EnumInval(builtins.Exception)
Exception for an invalid enum value π
class IntHex(builtins.int)
Integer object which is displayed in hex π
Methods defined here:
__repr__ = __str__(self)__str__(self)β Returnstr(self).
class LongHex(builtins.int)
Long integer object which is displayed in hex π
Methods defined here:
__repr__ = __str__(self)__str__(self)β Returnstr(self).
class OptionFlags(baseobj.BaseObj)
OptionFlags base object β¨
This base class is used to have a set of raw flags represented by an integer and splits every bit into an object attribute according to the class attribute _bitnames where the key is the bit number and the value is the attribute name. it's literally breaking your int down bit by bit, main character energy. π
This should only be used as a base class where the class attribute_bitnamesshould be initialized. The class attribute_reversedcan also be initialized to reverse the_bitnamesso the first bit becomes the last, e.g.,_reversed = 31, bits are reversed on a 32 bit integer so0becomes31,1becomes30, etc. π
Usage:
from packet.utils import OptionFlags
class MyFlags(OptionFlags):
_bitnames = {0:"bit0", 1:"bit1", 2:"bit2", 3:"bit3"}
x = MyFlags(10) # 10 = 0b1010
The attributes of object are:
x.rawflags = 10, # Original raw flags
x.bit0 = 0,
x.bit1 = 1,
x.bit2 = 0,
x.bit3 = 1,
Methods defined here:
__init__(self, options)β Initialize object's private data.options:Unsigned integer of raw flags
str_flags(self)β Display the flag names which are set, e.g., in the above example the output will be"bit1,bit3"(bit1=1,bit3=1). Use"__str__ = OptionFlags.str_flags"to have it as the default string representation π
class RDMAbase(baseobj.BaseObj)
RDMA base object π«
Base class for an RDMA reduced payload object having RDMA write chunks. An application having a DDP (direct data placement) item must inherit this class and use the rdma_opaque method as a dissecting function. π¬
Usage:
from packet.utils import RDMAbase
# For an original class definition with DDP items
class APPobj(BaseObj):
def __init__(self, unpack):
self.test = nfs_bool(unpack)
self.data = unpack.unpack_opaque()
# Class definition to access RDMA chunk writes
class APPobj(RDMAbase):
def __init__(self, unpack):
self.test = self.rdma_opaque(nfs_bool, unpack)
self.data = self.rdma_opaque(unpack.unpack_opaque)
Methods defined here:
rdma_opaque(self, func, *kwts, **kwds)β Dissecting method for a DDP item. The first positional argument is the original dissecting function to be called when there is no RDMA write chunks. The rest of the arguments (positional or named) are passed directly to the dissecting function. π§
Data and other attributes defined here:
rdma_write_chunks = []
class RPCload(baseobj.BaseObj)
RPC load base object.
This is used as a base class for an RPC payload object π«Ά
Methods defined here:
__str__(self)β Informal string representationmain_op(self)β Get the main NFS operationrpc_str(self, name=None)β Display RPC string
class ShortHex(builtins.int)
Short integer object which is displayed in hex π§‘
Methods defined here:
__repr__ = __str__(self)__str__(self)β Returnstr(self).
class StrHex(builtins.bytes)
String object which is displayed in hex π
Methods defined here:
__str__(self)β Returnstr(self).
β FUNCTIONS β
bitmap_info(unpack, bitmap, key_enum=None, func_map=None)
Returns a list of bits set on the bitmap or a dictionary where the key is the bit number given by bitmap and the value is the decoded value by evaluating the function used for that specific bit number. it's giving "tell me what bits are popping off". π₯
unpack:Unpack objectbitmap:Unsigned integer where a value must be decoded for every bit that is set, starting from the least significant bitkey_enum:UseEnumfor bit number so the key could be displayed as the bit name instead of the bit number [default:None]func_map:Dictionary which maps a bit number to the function to be used for decoding the value for that bit number. The function must have the"unpack"object as the only argument. If this isNonea list of bit attributes is returned instead [default:None]
π¦ SEE ALSO π¦
π BUGS π
No known bugs. (we stay winning, bestie π)
π AUTHOR π
Jorge Mora (mora@netapp.com)
and that's the whole page, babe. this was NFStest 3.2, dated 21 March 2023 β go forth and hex-ify your ints, you absolute icon. πβ¨π
π¦ where this page comes from
- debian trixie: nfstest 3.2-3
- fedora 43: NFStest 3.2-14.fc43 Β· GPL-2.0-or-later
- fedora 44: NFStest 3.2-16.fc44 Β· GPL-2.0-or-later
- ubuntu noble: nfstest 3.2-2
- ubuntu questing: nfstest 3.2-3
- ubuntu resolute: nfstest 3.2-3build1
- ubuntu stonking: nfstest 3.2-5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms