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

MCP-5632 - Added MarshallJSON and UnMarshallJSON to marshal private a… #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package m3u8

import (
"bytes"
"encoding/json"
"io"
"time"
)
Expand Down Expand Up @@ -124,6 +125,64 @@ type MediaPlaylist struct {
WV *WV // Widevine related tags outside of M3U8 specs
}

/*
Implements a special Marshall/UnMarshall functions to handle private/unexported parameters
*/
func (m *MediaPlaylist) MarshalJSON() ([]byte, error) {
type Alias MediaPlaylist
return json.Marshal(&struct {
*Alias
DurationAsInt bool
Keyformat int
Winsize uint
Capacity uint
Head uint
Tail uint
Count uint
Ver uint8
}{
Alias: (*Alias)(m),
DurationAsInt: m.durationAsInt,
Keyformat: m.keyformat,
Winsize: m.winsize,
Capacity: m.capacity,
Head: m.head,
Tail: m.tail,
Count: m.count,
Ver: m.ver,
})
}

func (m *MediaPlaylist) UnmarshalJSON(data []byte) error {
type Alias MediaPlaylist
aux := &struct {
*Alias
DurationAsInt bool
Keyformat int
Winsize uint
Capacity uint
Head uint
Tail uint
Count uint
Ver uint8
}{
Alias: (*Alias)(m),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
m.durationAsInt = aux.DurationAsInt
m.keyformat = aux.Keyformat
m.winsize = aux.Winsize
m.capacity = aux.Capacity
m.head = aux.Head
m.tail = aux.Tail
m.count = aux.Count
m.ver = aux.Ver
m.buf.Reset()
return nil
}

/*
This structure represents a master playlist which combines media playlists for multiple bitrates.
URI lines in the playlist identify media playlists.
Expand Down