Skip to content

Commit 9540ce9

Browse files
authored
Always encode MessageHeader.Durable field (#341)
This allows sending an explicit false.
1 parent d426635 commit 9540ce9

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
* Fixed a rare race in `Conn.start` that could cause goroutines to be leaked if the provided context was canceld/expired.
1313

14+
### Other Changes
15+
16+
* The field `MessageHeader.Durable` is not omitted when it's `false`.
17+
1418
## 1.1.0 (2024-08-20)
1519

1620
### Features Added

message.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ type MessageHeader struct {
340340

341341
func (h *MessageHeader) Marshal(wr *buffer.Buffer) error {
342342
return encoding.MarshalComposite(wr, encoding.TypeCodeMessageHeader, []encoding.MarshalField{
343-
{Value: &h.Durable, Omit: !h.Durable},
343+
{Value: &h.Durable},
344344
{Value: &h.Priority, Omit: h.Priority == 4},
345345
{Value: (*encoding.Milliseconds)(&h.TTL), Omit: h.TTL == 0},
346346
{Value: &h.FirstAcquirer, Omit: !h.FirstAcquirer},

message_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package amqp
33
import (
44
"testing"
55

6+
"github.com/Azure/go-amqp/internal/buffer"
67
"github.com/google/go-cmp/cmp"
78
"github.com/google/go-cmp/cmp/cmpopts"
89
"github.com/stretchr/testify/require"
@@ -91,3 +92,14 @@ func TestMessageWithSequence(t *testing.T) {
9192
{"hello2", "world2", int64(21), int64(22), int64(23)},
9293
}, newM.Sequence)
9394
}
95+
96+
func TestMessageHeaderMarshal(t *testing.T) {
97+
header := MessageHeader{}
98+
buf := &buffer.Buffer{}
99+
err := header.Marshal(buf)
100+
require.NoError(t, err)
101+
b := buf.Detach()
102+
require.NotNil(t, b)
103+
// 0x42 is false for the Durable field
104+
require.Equal(t, []byte{0x0, 0x53, 0x70, 0xd0, 0x0, 0x0, 0x0, 0x7, 0x0, 0x0, 0x0, 0x2, 0x42, 0x50, 0x0}, b)
105+
}

0 commit comments

Comments
 (0)