From b40efdef0abe0f6d45e0d2b41429eff69f453593 Mon Sep 17 00:00:00 2001 From: yutopp Date: Fri, 21 Jul 2023 03:45:30 +0900 Subject: [PATCH] Fix decoding format of OnStatus --- message/body_decoder.go | 2 +- message/net_stream.go | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/message/body_decoder.go b/message/body_decoder.go index 8f341bb..e94533a 100644 --- a/message/body_decoder.go +++ b/message/body_decoder.go @@ -361,7 +361,7 @@ func DecodeBodyOnStatus(_ io.Reader, d AMFDecoder, v *AMFConvertible) error { if err := d.Decode(&commandObject); err != nil { return errors.Wrap(err, "Failed to decode 'OnStatus' args[0]") } - var infoObject NetStreamOnStatusInfoObject + var infoObject map[string]interface{} if err := d.Decode(&infoObject); err != nil { return errors.Wrap(err, "Failed to decode 'OnStatus' args[1]") } diff --git a/message/net_stream.go b/message/net_stream.go index 6c40eb6..a80cc6e 100644 --- a/message/net_stream.go +++ b/message/net_stream.go @@ -7,6 +7,8 @@ package message +import "errors" + type NetStreamPublish struct { CommandObject interface{} PublishingName string @@ -85,7 +87,32 @@ type NetStreamOnStatusInfoObject struct { func (t *NetStreamOnStatus) FromArgs(args ...interface{}) error { // args[0] is nil, ignore - t.InfoObject = args[1].(NetStreamOnStatusInfoObject) + + info, ok := args[1].(map[string]interface{}) + if !ok { + return errors.New("invalid type") // TODO: fix + } + if v, ok := info["level"]; ok { + level, ok := v.(string) + if !ok { + return errors.New("invalid type") // TODO: fix + } + t.InfoObject.Level = NetStreamOnStatusLevel(level) // TODO: type check + } + if v, ok := info["code"]; ok { + code, ok := v.(string) + if !ok { + return errors.New("invalid type") // TODO: fix + } + t.InfoObject.Code = NetStreamOnStatusCode(code) // TODO: type check + } + if v, ok := info["description"]; ok { + description, ok := v.(string) + if !ok { + return errors.New("invalid type") // TODO: fix + } + t.InfoObject.Description = description + } return nil }