|
|
@@ -789,6 +789,12 @@ func (m *Message) Unpack(msg []byte) error {
|
|
|
|
|
|
// Pack packs a full Message.
|
|
|
func (m *Message) Pack() ([]byte, error) {
|
|
|
+ return m.AppendPack(make([]byte, 0, packStartingCap))
|
|
|
+}
|
|
|
+
|
|
|
+// AppendPack is like Pack but appends the full Message to b and returns the
|
|
|
+// extended buffer.
|
|
|
+func (m *Message) AppendPack(b []byte) ([]byte, error) {
|
|
|
// Validate the lengths. It is very unlikely that anyone will try to
|
|
|
// pack more than 65535 of any particular type, but it is possible and
|
|
|
// we should fail gracefully.
|
|
|
@@ -813,9 +819,7 @@ func (m *Message) Pack() ([]byte, error) {
|
|
|
h.authorities = uint16(len(m.Authorities))
|
|
|
h.additionals = uint16(len(m.Additionals))
|
|
|
|
|
|
- msg := make([]byte, 0, packStartingCap)
|
|
|
-
|
|
|
- msg = h.pack(msg)
|
|
|
+ msg := h.pack(b)
|
|
|
|
|
|
// RFC 1035 allows (but does not require) compression for packing. RFC
|
|
|
// 1035 requires unpacking implementations to support compression, so
|