Lines Matching +full:4 +full:- +full:data

10     HDR_LEN = 4  # sizeof(struct nlattr)
12 def __init__(self, nla_type, data): argument
20 self._data = data
28 return len(self._data) + 4
45 def _validate(data): argument
46 if len(data) < 4:
48 nla_len, nla_type = struct.unpack("@HH", data[:4])
49 if nla_len > len(data):
51 if nla_len < 4:
55 def _parse(cls, data): argument
56 nla_len, nla_type = struct.unpack("@HH", data[:4])
57 return cls(nla_type, data[4:])
60 def from_bytes(cls, data, attr_type_enum=None): argument
61 cls._validate(data)
62 attr = cls._parse(data)
66 def _to_bytes(self, data: bytes):
67 ret = data
69 ret = data + bytes(align4(len(ret)) - len(ret))
70 return struct.pack("@HH", len(data) + 4, self._nla_type) + ret
93 return align4(len(b"".join([bytes(nla) for nla in self.nla_list]))) + 4
126 def _validate(data): argument
127 assert len(data) == 8
128 nla_len, nla_type = struct.unpack("@HH", data[:4])
132 def _parse(cls, data): argument
133 nla_len, nla_type, val = struct.unpack("@HHI", data)
153 def _validate(data): argument
154 assert len(data) == 8
155 nla_len, nla_type = struct.unpack("@HH", data[:4])
159 def _parse(cls, data): argument
160 nla_len, nla_type, val = struct.unpack("@HHi", data)
180 def _validate(data): argument
181 assert len(data) == 6
182 nla_len, nla_type = struct.unpack("@HH", data[:4])
186 def _parse(cls, data): argument
187 nla_len, nla_type, val = struct.unpack("@HHH", data)
207 def _validate(data): argument
208 assert len(data) == 5
209 nla_len, nla_type = struct.unpack("@HH", data[:4])
213 def _parse(cls, data): argument
214 nla_len, nla_type, val = struct.unpack("@HHB", data)
231 def _validate(data): argument
232 nla_len, nla_type = struct.unpack("@HH", data[:4])
233 data_len = nla_len - 4
234 if data_len != 4 and data_len != 16:
247 return align4(len(self._data)) + 4
250 def _parse(cls, data): argument
251 nla_len, nla_type = struct.unpack("@HH", data[:4])
252 data_len = len(data) - 4
253 if data_len == 4:
254 addr = socket.inet_ntop(socket.AF_INET, data[4:8])
256 addr = socket.inet_ntop(socket.AF_INET6, data[4:20])
284 def _validate(data): argument
285 NlAttr._validate(data)
287 data[4:].decode("utf-8")
289 raise ValueError("wrong utf-8 string: {}".format(e))
296 def _parse(cls, data): argument
297 text = data[4:-1].decode("utf-8")
298 nla_len, nla_type = struct.unpack("@HH", data[:4])
302 return self._to_bytes(bytes(self.text, encoding="utf-8") + bytes(1))
314 def _validate(data): argument
315 NlAttr._validate(data)
317 data[4:].decode("utf-8")
319 raise ValueError("wrong utf-8 string: {}".format(e))
323 return len(self.text) + 4
326 def _parse(cls, data): argument
327 text = data[4:].decode("utf-8")
328 nla_len, nla_type = struct.unpack("@HH", data[:4])
332 return self._to_bytes(bytes(self.text, encoding="utf-8"))