Add an internal value to a string Copy the network representation of field `val` (belonging to layer `pkt`) to the raw string packet `s`, and return the new string packet.
(self, pkt, s, val)
| 230 | return repr(self.i2h(pkt, x)) |
| 231 | |
| 232 | def addfield(self, pkt, s, val): |
| 233 | # type: (Packet, bytes, Optional[I]) -> bytes |
| 234 | """Add an internal value to a string |
| 235 | |
| 236 | Copy the network representation of field `val` (belonging to layer |
| 237 | `pkt`) to the raw string packet `s`, and return the new string packet. |
| 238 | """ |
| 239 | try: |
| 240 | return s + self.struct.pack(self.i2m(pkt, val)) |
| 241 | except struct.error as ex: |
| 242 | raise ValueError( |
| 243 | "Incorrect type of value for field %s:\n" % self.name + |
| 244 | "struct.error('%s')\n" % ex + |
| 245 | "To inject bytes into the field regardless of the type, " + |
| 246 | "use RawVal. See help(RawVal)" |
| 247 | ) |
| 248 | |
| 249 | def getfield(self, pkt, s): |
| 250 | # type: (Packet, bytes) -> Tuple[bytes, I] |
no test coverage detected