Encode int values into C strings. Values are stored in base 10 and separated by 0 bytes.
(values: dict[int, int])
| 234 | |
| 235 | |
| 236 | def _encode_int_values(values: dict[int, int]) -> list[bytes]: |
| 237 | """Encode int values into C strings. |
| 238 | |
| 239 | Values are stored in base 10 and separated by 0 bytes. |
| 240 | """ |
| 241 | value_by_index = {index: value for value, index in values.items()} |
| 242 | result = [] |
| 243 | line: list[bytes] = [] |
| 244 | line_len = 0 |
| 245 | for i in range(len(values)): |
| 246 | value = value_by_index[i] |
| 247 | encoded = b"%d" % value |
| 248 | if line_len > 0 and line_len + len(encoded) > 70: |
| 249 | result.append(format_int(len(line)) + b"\0".join(line)) |
| 250 | line = [] |
| 251 | line_len = 0 |
| 252 | line.append(encoded) |
| 253 | line_len += len(encoded) |
| 254 | if line: |
| 255 | result.append(format_int(len(line)) + b"\0".join(line)) |
| 256 | result.append(b"") |
| 257 | return result |
| 258 | |
| 259 | |
| 260 | def float_to_c(x: float) -> str: |
searching dependent graphs…