1package mpv
2
3import (
4 "encoding/json"
5 "io"
6)
7
8const noError = "success"
9
10type response struct {
11 Error string `json:"error"`
12 Data interface{} `json:"data"`
13 ReqID int32 `json:"request_id"`
14
15 // Additional fields used by observe events
16 ID int32 `json:"id"`
17 Event string `json:"event"`
18 PropertyName string `json:"name"`
19}
20
21type request struct {
22 Cmd []interface{} `json:"command"`
23 ID int32 `json:"request_id"`
24}
25
26func (r *request) Encode(w io.Writer) error {
27 enc := json.NewEncoder(w)
28
29 err := enc.Encode(r)
30 if err != nil {
31 return err
32 }
33
34 return nil
35}
36
37func (r *request) String() string {
38 data, err := json.Marshal(r)
39 if err != nil {
40 // This function is primarly intended for debugging
41 // purposes and therefore panics on error.
42 panic(err)
43 }
44
45 return string(data)
46}