/
subscription.go
138 lines (117 loc) · 4.38 KB
/
subscription.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
* MIT License
*
* Copyright (c) 2017 - 2018 CNES
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package mal
import ()
// ################################################################################
// Defines MAL Subscription type
// ################################################################################
type Subscription struct {
SubscriptionId Identifier
Entities EntityRequestList
}
var (
NullSubscription *Subscription = nil
)
func NewSubscription() *Subscription {
return new(Subscription)
}
// ================================================================================
// Defines MAL Subscription type as a MAL Composite
func (subs *Subscription) Composite() Composite {
return subs
}
// ================================================================================
// Defines MAL Subscription type as a MAL Element
// Registers MAL Subscription type for polymorpsism handling
func init() {
RegisterMALElement(MAL_SUBSCRIPTION_SHORT_FORM, NullSubscription)
}
const MAL_SUBSCRIPTION_TYPE_SHORT_FORM Integer = 0x17
const MAL_SUBSCRIPTION_SHORT_FORM Long = 0x1000001000017
// Returns the absolute short form of the element type.
func (*Subscription) GetShortForm() Long {
return MAL_SUBSCRIPTION_SHORT_FORM
}
// Returns the number of the area this element type belongs to.
func (*Subscription) GetAreaNumber() UShort {
return MAL_ATTRIBUTE_AREA_NUMBER
}
// Returns the version of the area this element type belongs to.
func (*Subscription) GetAreaVersion() UOctet {
return MAL_ATTRIBUTE_AREA_VERSION
}
// Returns the number of the service this element type belongs to.
func (*Subscription) GetServiceNumber() UShort {
return MAL_ATTRIBUTE_AREA_SERVICE_NUMBER
}
// Returns the relative short form of the element type.
func (*Subscription) GetTypeShortForm() Integer {
return MAL_SUBSCRIPTION_TYPE_SHORT_FORM
}
// Encodes this element using the supplied encoder.
// @param encoder The encoder to use, must not be null.
func (subs *Subscription) Encode(encoder Encoder) error {
err := encoder.EncodeIdentifier(&subs.SubscriptionId)
if err != nil {
return err
}
// return (&subs.Entities).Encode(encoder)
return subs.Entities.Encode(encoder)
}
// Decodes an instance of this element type using the supplied decoder.
// @param decoder The decoder to use, must not be null.
// @return the decoded instance, may be not the same instance as this Element.
func (subs *Subscription) Decode(decoder Decoder) (Element, error) {
return DecodeSubscription(decoder)
}
// Decodes an instance of EntityRequest using the supplied decoder.
// @param decoder The decoder to use, must not be null.
// @return the decoded EntityRequest instance.
func DecodeSubscription(decoder Decoder) (*Subscription, error) {
subscriptionId, err := decoder.DecodeIdentifier()
if err != nil {
return nil, err
}
entities, err := decoder.DecodeElement(NullEntityRequestList)
if err != nil {
return nil, err
}
var subs = Subscription{
SubscriptionId: *subscriptionId,
Entities: *entities.(*EntityRequestList),
}
return &subs, nil
}
// The method allows the creation of an element in a generic way, i.e., using the MAL Element polymorphism.
func (*Subscription) CreateElement() Element {
// TODO (AF):
// return new(Subscription)
return NewSubscription()
}
func (subs *Subscription) IsNull() bool {
return subs == nil
}
func (*Subscription) Null() Element {
return NullSubscription
}