Skip to content

Commit

Permalink
ControlSyncRequest Encode: cookie optionality (#459)
Browse files Browse the repository at this point in the history
In SyncRequest cookie is optional, so do not add cookie if empty
  • Loading branch information
zeslava authored Aug 17, 2023
1 parent bbc2f21 commit 7f97b82
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions v3/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,9 +928,12 @@ func (c *ControlSyncRequest) GetControlType() string {
func (c *ControlSyncRequest) Encode() *ber.Packet {
_mode := int64(c.Mode)
mode := ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagEnumerated, _mode, "Mode")
cookie := ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, nil, "Cookie")
cookie.Value = c.Cookie
cookie.Data.Write(c.Cookie)
var cookie *ber.Packet
if len(c.Cookie) > 0 {
cookie = ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, nil, "Cookie")
cookie.Value = c.Cookie
cookie.Data.Write(c.Cookie)
}
reloadHint := ber.NewBoolean(ber.ClassUniversal, ber.TypePrimitive, ber.TagBoolean, c.ReloadHint, "Reload Hint")

packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control")
Expand All @@ -940,7 +943,9 @@ func (c *ControlSyncRequest) Encode() *ber.Packet {
val := ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, nil, "Control Value (Sync Request)")
seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Sync Request Value")
seq.AppendChild(mode)
seq.AppendChild(cookie)
if cookie != nil {
seq.AppendChild(cookie)
}
seq.AppendChild(reloadHint)
val.AppendChild(seq)

Expand Down

0 comments on commit 7f97b82

Please sign in to comment.