forked from fiorix/go-diameter
/
enum.go
44 lines (35 loc) · 999 Bytes
/
enum.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
// Copyright 2013-2015 go-diameter authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package datatype
import "fmt"
// Enumerated data type.
type Enumerated Integer32
// DecodeEnumerated decodes an Enumerated data type from byte array.
func DecodeEnumerated(b []byte) (Type, error) {
v, err := DecodeInteger32(b)
if err != nil {
return nil, err
}
return Enumerated(v.(Integer32)), nil
}
// Serialize implements the Type interface.
func (n Enumerated) Serialize() []byte {
return Integer32(n).Serialize()
}
// Len implements the Type interface.
func (n Enumerated) Len() int {
return 4
}
// Padding implements the Type interface.
func (n Enumerated) Padding() int {
return 0
}
// Type implements the Type interface.
func (n Enumerated) Type() TypeID {
return EnumeratedType
}
// String implements the Type interface.
func (n Enumerated) String() string {
return fmt.Sprintf("Enumerated{%d}", n)
}