refactor: switch to using new intParse method

This commit is contained in:
Derrick Hammer 2024-03-01 03:21:31 -05:00
parent 1b950bae08
commit 05522522bf
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 28 additions and 15 deletions

View File

@ -91,24 +91,19 @@ func (mmd *MediaFormat) DecodeMsgpack(dec *msgpack.Decoder) error {
case 4: case 4:
mmd.Ext = value.(string) mmd.Ext = value.(string)
case 10: case 10:
mmd.Height = value.(int) mmd.Height = intParse(value)
case 11: case 11:
mmd.Width = value.(int) mmd.Width = intParse(value)
case 12: case 12:
mmd.Languages = value.([]string) mmd.Languages = value.([]string)
case 13: case 13:
mmd.Asr = int(value.(uint16)) mmd.Asr = intParse(value)
case 14: case 14:
mmd.Fps = value.(int) mmd.Fps = intParse(value)
case 15: case 15:
switch value.(type) { mmd.Bitrate = intParse(value)
case uint16:
mmd.Bitrate = int(value.(uint16))
case uint32:
mmd.Bitrate = int(value.(uint32))
}
case 18: case 18:
mmd.AudioChannels = int(value.(int8)) mmd.AudioChannels = intParse(value)
case 19: case 19:
mmd.Vcodec = value.(string) mmd.Vcodec = value.(string)
case 20: case 20:
@ -122,13 +117,13 @@ func (mmd *MediaFormat) DecodeMsgpack(dec *msgpack.Decoder) error {
case 24: case 24:
mmd.Value = value.([]byte) mmd.Value = value.([]byte)
case 25: case 25:
mmd.Duration = value.(int) mmd.Duration = intParse(value)
case 26: case 26:
mmd.Rows = value.(int) mmd.Rows = intParse(value)
case 27: case 27:
mmd.Columns = value.(int) mmd.Columns = intParse(value)
case 28: case 28:
mmd.Index = value.(int) mmd.Index = intParse(value)
case 29: case 29:
mmd.InitRange = value.(string) mmd.InitRange = value.(string)
case 30: case 30:
@ -140,3 +135,21 @@ func (mmd *MediaFormat) DecodeMsgpack(dec *msgpack.Decoder) error {
return nil return nil
} }
func intParse(value interface{}) int {
switch value.(type) {
case int:
return value.(int)
case uint:
return int(value.(uint))
case uint16:
return int(value.(uint16))
case uint32:
return int(value.(uint32))
case int16:
return int(value.(int16))
case int8:
return int(value.(int8))
}
return 0
}