-
Notifications
You must be signed in to change notification settings - Fork 95
/
feat_tag.go
51 lines (39 loc) · 1.08 KB
/
feat_tag.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
package iotago
import (
"bytes"
"cmp"
"github.com/iotaledger/hive.go/serializer/v2"
)
// TagFeature is a feature which allows to additionally tag an output by a user defined value.
type TagFeature struct {
Tag []byte `serix:",lenPrefix=uint8,minLen=1,maxLen=64"`
}
func (s *TagFeature) Clone() Feature {
return &TagFeature{Tag: append([]byte(nil), s.Tag...)}
}
func (s *TagFeature) StorageScore(storageScoreStruct *StorageScoreStructure, f StorageScoreFunc) StorageScore {
if f != nil {
return f(storageScoreStruct)
}
return 0
}
func (s *TagFeature) WorkScore(_ *WorkScoreParameters) (WorkScore, error) {
return 0, nil
}
func (s *TagFeature) Compare(other Feature) int {
return cmp.Compare(s.Type(), other.Type())
}
func (s *TagFeature) Equal(other Feature) bool {
otherFeat, is := other.(*TagFeature)
if !is {
return false
}
return bytes.Equal(s.Tag, otherFeat.Tag)
}
func (s *TagFeature) Type() FeatureType {
return FeatureTag
}
func (s *TagFeature) Size() int {
// FeatureType + Tag
return serializer.SmallTypeDenotationByteSize + serializer.OneByte + len(s.Tag)
}