forked from bsm/openrtb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
audio.go
68 lines (59 loc) · 2.61 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 []Protocol `json:"protocols,omitempty"` // Video bid response protocols
StartDelay StartDelay `json:"startdelay,omitempty"` // Indicates the start delay in seconds
Sequence int `json:"sequence,omitempty"` // Default: 1
BlockedAttrs []CreativeAttribute `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 []ContentDelivery `json:"delivery,omitempty"` // List of supported delivery methods
CompanionAds []Banner `json:"companionad,omitempty"`
APIs []APIFramework `json:"api,omitempty"`
CompanionTypes []CompanionType `json:"companiontype,omitempty"`
MaxSequence int `json:"maxseq,omitempty"` // The maximumnumber of ads that canbe played in an ad pod.
Feed FeedType `json:"feed,omitempty"` // Type of audio feed.
Stitched int `json:"stitched,omitempty"` // Indicates if the ad is stitched with audio content or delivered independently
VolumeNorm VolumeNorm `json:"nvol,omitempty"` // Volume normalization mode.
Ext json.RawMessage `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
}
}