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

Fix decoding of publish command, publishing type is optional #59

Merged
merged 1 commit into from Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion message/body_decoder.go
Expand Up @@ -200,7 +200,12 @@
}
var publishingType string
if err := d.Decode(&publishingType); err != nil {
return errors.Wrap(err, "Failed to decode 'publish' args[2]")
// value is optional
if errors.Is(err, io.EOF) {
publishingType = "live"
} else {
return errors.Wrap(err, "Failed to decode 'publish' args[2]")

Check warning on line 207 in message/body_decoder.go

View check run for this annotation

Codecov / codecov/patch

message/body_decoder.go#L207

Added line #L207 was not covered by tests
}
}

var cmd NetStreamPublish
Expand Down
19 changes: 19 additions & 0 deletions message/body_decoder_test.go
Expand Up @@ -112,6 +112,25 @@ func TestDecodeCmdMessagePublish(t *testing.T) {
}, v)
}

func TestDecodeCmdMessagePublishWithoutPublishingType(t *testing.T) {
bin := []byte{
// nil
0x05,
// string: abc
0x02, 0x00, 0x03, 0x61, 0x62, 0x63,
}
r := bytes.NewReader(bin)
d := amf0.NewDecoder(r)

var v AMFConvertible
err := CmdBodyDecoderFor("publish", 42)(r, d, &v)
require.Nil(t, err)
require.Equal(t, &NetStreamPublish{
PublishingName: "abc",
PublishingType: "live",
}, v)
}

func TestDecodeCmdMessagePlay(t *testing.T) {
bin := []byte{
// nil
Expand Down