Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message properties that are optional need to be nil-able #93

Merged
merged 11 commits into from
Dec 7, 2021
Next Next commit
If something is optional then it should be nil-able.
Richard Park committed Nov 9, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 6388ef60ffaf0c2a94d23e5b0c3b4cc04552cc2e
31 changes: 17 additions & 14 deletions marshal_test.go
Original file line number Diff line number Diff line change
@@ -481,17 +481,17 @@ var (
Properties: &MessageProperties{
MessageID: "yo",
UserID: []byte("baz"),
To: "me",
Subject: "sup?",
ReplyTo: "you",
To: stringPtr("me"),
Subject: stringPtr("sup?"),
ReplyTo: stringPtr("you"),
CorrelationID: uint64(34513),
ContentType: "text/plain",
ContentEncoding: "UTF-8",
ContentType: stringPtr("text/plain"),
ContentEncoding: stringPtr("UTF-8"),
AbsoluteExpiryTime: time.Date(2018, 01, 13, 14, 24, 07, 0, time.UTC),
CreationTime: time.Date(2018, 01, 13, 14, 14, 07, 0, time.UTC),
GroupID: "fooGroup",
GroupID: stringPtr("fooGroup"),
GroupSequence: 89324,
ReplyToGroupID: "barGroup",
ReplyToGroupID: stringPtr("barGroup"),
},
ApplicationProperties: map[string]interface{}{
"baz": "foo",
@@ -515,17 +515,17 @@ var (
&MessageProperties{
MessageID: "yo",
UserID: []byte("baz"),
To: "me",
Subject: "sup?",
ReplyTo: "you",
To: stringPtr("me"),
Subject: stringPtr("sup?"),
ReplyTo: stringPtr("you"),
CorrelationID: uint64(34513),
ContentType: "text/plain",
ContentEncoding: "UTF-8",
ContentType: stringPtr("text/plain"),
ContentEncoding: stringPtr("UTF-8"),
AbsoluteExpiryTime: time.Date(2018, 01, 13, 14, 24, 07, 0, time.UTC),
CreationTime: time.Date(2018, 01, 13, 14, 14, 07, 0, time.UTC),
GroupID: "fooGroup",
GroupID: stringPtr("fooGroup"),
GroupSequence: 89324,
ReplyToGroupID: "barGroup",
ReplyToGroupID: stringPtr("barGroup"),
},
&encoding.StateReceived{
SectionNumber: 234,
@@ -651,3 +651,6 @@ func rcvSettle(m ReceiverSettleMode) *ReceiverSettleMode {
func uint32Ptr(u uint32) *uint32 {
return &u
}
func stringPtr(s string) *string {
return &s
}
28 changes: 14 additions & 14 deletions message.go
Original file line number Diff line number Diff line change
@@ -362,13 +362,13 @@ type MessageProperties struct {

// The to field identifies the node that is the intended destination of the message.
// On any given transfer this might not be the node at the receiving end of the link.
To string
To *string
richardpark-msft marked this conversation as resolved.
Show resolved Hide resolved

// A common field for summary information about the message content and purpose.
Subject string
Subject *string

// The address of the node to send replies to.
ReplyTo string
ReplyTo *string

// This is a client-specific id that can be used to mark or identify messages
// between clients.
@@ -385,7 +385,7 @@ type MessageProperties struct {
//
// When using an application-data section with a section code other than data,
// content-type SHOULD NOT be set.
ContentType string
ContentType *string

// The content-encoding property is used as a modifier to the content-type.
// When present, its value indicates what additional content encodings have been
@@ -410,7 +410,7 @@ type MessageProperties struct {
//
// Implementations SHOULD NOT specify multiple content-encoding values except as to
// be compatible with messages originally sent with other protocols, e.g. HTTP or SMTP.
ContentEncoding string
ContentEncoding *string

// An absolute time when this message is considered to be expired.
AbsoluteExpiryTime time.Time
@@ -419,31 +419,31 @@ type MessageProperties struct {
CreationTime time.Time

// Identifies the group the message belongs to.
GroupID string
GroupID *string

// The relative position of this message within its group.
GroupSequence uint32 // RFC-1982 sequence number

// This is a client-specific id that is used so that client can send replies to this
// message to a specific group.
ReplyToGroupID string
ReplyToGroupID *string
}

func (p *MessageProperties) Marshal(wr *buffer.Buffer) error {
return encoding.MarshalComposite(wr, encoding.TypeCodeMessageProperties, []encoding.MarshalField{
{Value: p.MessageID, Omit: p.MessageID == nil},
{Value: &p.UserID, Omit: len(p.UserID) == 0},
{Value: &p.To, Omit: p.To == ""},
{Value: &p.Subject, Omit: p.Subject == ""},
{Value: &p.ReplyTo, Omit: p.ReplyTo == ""},
{Value: p.To, Omit: p.To == nil},
{Value: p.Subject, Omit: p.Subject == nil},
{Value: p.ReplyTo, Omit: p.ReplyTo == nil},
{Value: p.CorrelationID, Omit: p.CorrelationID == nil},
{Value: (*encoding.Symbol)(&p.ContentType), Omit: p.ContentType == ""},
{Value: (*encoding.Symbol)(&p.ContentEncoding), Omit: p.ContentEncoding == ""},
{Value: (*encoding.Symbol)(p.ContentType), Omit: p.ContentType == nil},
{Value: (*encoding.Symbol)(p.ContentEncoding), Omit: p.ContentEncoding == nil},
{Value: &p.AbsoluteExpiryTime, Omit: p.AbsoluteExpiryTime.IsZero()},
{Value: &p.CreationTime, Omit: p.CreationTime.IsZero()},
{Value: &p.GroupID, Omit: p.GroupID == ""},
{Value: p.GroupID, Omit: p.GroupID == nil},
{Value: &p.GroupSequence},
{Value: &p.ReplyToGroupID, Omit: p.ReplyToGroupID == ""},
{Value: p.ReplyToGroupID, Omit: p.ReplyToGroupID == nil},
})
}