-
Notifications
You must be signed in to change notification settings - Fork 0
/
playlist-songs.go
95 lines (76 loc) · 2.18 KB
/
playlist-songs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package data
import (
"encoding/json"
"io"
"github.com/frizinak/homechat/server/channel"
)
type PlaylistSongsMessage struct {
Playlist string `json:"playlist"`
channel.NeverEqual
channel.NoClose
}
func (m PlaylistSongsMessage) Binary(w channel.BinaryWriter) error {
w.WriteString(m.Playlist, 16)
return w.Err()
}
func (m PlaylistSongsMessage) JSON(w io.Writer) error {
return json.NewEncoder(w).Encode(m)
}
func (m PlaylistSongsMessage) FromBinary(r channel.BinaryReader) (channel.Msg, error) {
return BinaryPlaylistSongsMessage(r)
}
func (m PlaylistSongsMessage) FromJSON(r io.Reader) (channel.Msg, io.Reader, error) {
return JSONPlaylistSongsMessage(r)
}
func BinaryPlaylistSongsMessage(r channel.BinaryReader) (PlaylistSongsMessage, error) {
c := PlaylistSongsMessage{}
c.Playlist = r.ReadString(16)
return c, r.Err()
}
func JSONPlaylistSongsMessage(r io.Reader) (PlaylistSongsMessage, io.Reader, error) {
c := PlaylistSongsMessage{}
nr, err := channel.JSON(r, &c)
return c, nr, err
}
type ServerPlaylistSongsMessage struct {
List []Song `json:"list"`
channel.NeverEqual
channel.NoClose
}
func (m ServerPlaylistSongsMessage) Binary(w channel.BinaryWriter) error {
w.WriteUint32(uint32(len(m.List)))
for _, p := range m.List {
if err := p.Binary(w); err != nil {
return err
}
}
return w.Err()
}
func (m ServerPlaylistSongsMessage) JSON(w io.Writer) error {
return json.NewEncoder(w).Encode(m)
}
func (m ServerPlaylistSongsMessage) FromBinary(r channel.BinaryReader) (channel.Msg, error) {
return BinaryServerPlaylistSongsMessage(r)
}
func (m ServerPlaylistSongsMessage) FromJSON(r io.Reader) (channel.Msg, io.Reader, error) {
return JSONServerPlaylistSongsMessage(r)
}
func BinaryServerPlaylistSongsMessage(r channel.BinaryReader) (ServerPlaylistSongsMessage, error) {
c := ServerPlaylistSongsMessage{}
n := r.ReadUint32()
c.List = make([]Song, n)
var i uint32
for ; i < n; i++ {
s, err := BinarySong(r)
if err != nil {
return c, err
}
c.List[i] = s
}
return c, r.Err()
}
func JSONServerPlaylistSongsMessage(r io.Reader) (ServerPlaylistSongsMessage, io.Reader, error) {
c := ServerPlaylistSongsMessage{}
nr, err := channel.JSON(r, &c)
return c, nr, err
}