Return a string containing the message in DNS compressed wire format. Additional keyword arguments are passed to the RRset ``to_wire()`` method. *origin*, a ``dns.name.Name`` or ``None``, the origin to be appended to any relative names. If ``None``, and the
(
self,
origin: dns.name.Name | None = None,
max_size: int = 0,
multi: bool = False,
tsig_ctx: Any | None = None,
prepend_length: bool = False,
prefer_truncation: bool = False,
**kw: Dict[str, Any],
)
| 559 | return len(f.getvalue()) |
| 560 | |
| 561 | def to_wire( |
| 562 | self, |
| 563 | origin: dns.name.Name | None = None, |
| 564 | max_size: int = 0, |
| 565 | multi: bool = False, |
| 566 | tsig_ctx: Any | None = None, |
| 567 | prepend_length: bool = False, |
| 568 | prefer_truncation: bool = False, |
| 569 | **kw: Dict[str, Any], |
| 570 | ) -> bytes: |
| 571 | """Return a string containing the message in DNS compressed wire |
| 572 | format. |
| 573 | |
| 574 | Additional keyword arguments are passed to the RRset ``to_wire()`` |
| 575 | method. |
| 576 | |
| 577 | *origin*, a ``dns.name.Name`` or ``None``, the origin to be appended |
| 578 | to any relative names. If ``None``, and the message has an origin |
| 579 | attribute that is not ``None``, then it will be used. |
| 580 | |
| 581 | *max_size*, an ``int``, the maximum size of the wire format |
| 582 | output; default is 0, which means "the message's request |
| 583 | payload, if nonzero, or 65535". |
| 584 | |
| 585 | *multi*, a ``bool``, should be set to ``True`` if this message is |
| 586 | part of a multiple message sequence. |
| 587 | |
| 588 | *tsig_ctx*, a ``dns.tsig.HMACTSig`` or ``dns.tsig.GSSTSig`` object, the |
| 589 | ongoing TSIG context, used when signing zone transfers. |
| 590 | |
| 591 | *prepend_length*, a ``bool``, should be set to ``True`` if the caller |
| 592 | wants the message length prepended to the message itself. This is |
| 593 | useful for messages sent over TCP, TLS (DoT), or QUIC (DoQ). |
| 594 | |
| 595 | *prefer_truncation*, a ``bool``, should be set to ``True`` if the caller |
| 596 | wants the message to be truncated if it would otherwise exceed the |
| 597 | maximum length. If the truncation occurs before the additional section, |
| 598 | the TC bit will be set. |
| 599 | |
| 600 | Raises ``dns.exception.TooBig`` if *max_size* was exceeded. |
| 601 | |
| 602 | Returns a ``bytes``. |
| 603 | """ |
| 604 | |
| 605 | if origin is None and self.origin is not None: |
| 606 | origin = self.origin |
| 607 | if max_size == 0: |
| 608 | if self.request_payload != 0: |
| 609 | max_size = self.request_payload |
| 610 | else: |
| 611 | max_size = 65535 |
| 612 | if max_size < 512: |
| 613 | max_size = 512 |
| 614 | elif max_size > 65535: |
| 615 | max_size = 65535 |
| 616 | r = dns.renderer.Renderer(self.id, self.flags, max_size, origin) |
| 617 | opt_reserve = self._compute_opt_reserve() |
| 618 | r.reserve(opt_reserve) |