forked from bsm/openrtb
-
Notifications
You must be signed in to change notification settings - Fork 3
/
audio.go
68 lines (59 loc) · 2.4 KB
/
audio.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
package openrtb
import (
"encoding/json"
"errors"
)
// Validation errors
var (
ErrInvalidAudioNoMimes = errors.New("openrtb: audio has no mimes")
)
// Audio object must be included directly in the impression object
type Audio struct {
Mimes []string `json:"mimes"` // Content MIME types supported.
MinDuration int `json:"minduration,omitempty"` // Minimum video ad duration in seconds
MaxDuration int `json:"maxduration,omitempty"` // Maximum video ad duration in seconds
Protocols []int `json:"protocols,omitempty"` // Video bid response protocols
StartDelay int `json:"startdelay,omitempty"` // Indicates the start delay in seconds
Sequence int `json:"sequence,omitempty"` // Default: 1
BAttr []int `json:"battr,omitempty"` // Blocked creative attributes
MaxExtended int `json:"maxextended,omitempty"` // Maximum extended video ad duration
MinBitrate int `json:"minbitrate,omitempty"` // Minimum bit rate in Kbps
MaxBitrate int `json:"maxbitrate,omitempty"` // Maximum bit rate in Kbps
Delivery []int `json:"delivery,omitempty"` // List of supported delivery methods
CompanionAd []Banner `json:"companionad,omitempty"`
API []int `json:"api,omitempty"`
CompanionType []int `json:"companiontype,omitempty"`
MaxSequence int `json:"maxseq,omitempty"` // The maximumnumber of ads that canbe played in an ad pod.
Feed int `json:"feed,omitempty"` // Type of audio feed.
Stitched int `json:"stitched,omitempty"` // Indicates if the ad is stitched with audio content or delivered independently
NVol int `json:"nvol,omitempty"` // Volume normalization mode.
Ext Extension `json:"ext,omitempty"`
}
type jsonAudio Audio
// Validate the object
func (a *Audio) Validate() error {
if len(a.Mimes) == 0 {
return ErrInvalidAudioNoMimes
}
return nil
}
// MarshalJSON custom marshalling with normalization
func (a *Audio) MarshalJSON() ([]byte, error) {
a.normalize()
return json.Marshal((*jsonAudio)(a))
}
// UnmarshalJSON custom unmarshalling with normalization
func (a *Audio) UnmarshalJSON(data []byte) error {
var h jsonAudio
if err := json.Unmarshal(data, &h); err != nil {
return err
}
*a = (Audio)(h)
a.normalize()
return nil
}
func (a *Audio) normalize() {
if a.Sequence == 0 {
a.Sequence = 1
}
}