-
Notifications
You must be signed in to change notification settings - Fork 3
/
pospecific.go
53 lines (46 loc) · 1.46 KB
/
pospecific.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
package bw2bind
import (
"fmt"
"time"
)
type MetadataTuple struct {
Value string `msgpack:"val"`
Timestamp int64 `msgpack:"ts"`
}
func (m *MetadataTuple) Time() time.Time {
return time.Unix(0, m.Timestamp)
}
func (m *MetadataTuple) NewerThan(t time.Time) bool {
return m.Time().After(t)
}
//StringPayloadObject implements 64.0.1.0/32 : String
func CreateStringPayloadObject(v string) TextPayloadObject {
return CreateTextPayloadObject(FromDotForm("64.0.1.0"), v)
}
type MetadataPayloadObject interface {
PayloadObject
Value() *MetadataTuple
}
type MetadataPayloadObjectImpl struct {
MsgPackPayloadObjectImpl
}
func LoadMetadataPayloadObject(ponum int, contents []byte) (*MetadataPayloadObjectImpl, error) {
bpl, _ := LoadMsgPackPayloadObject(ponum, contents)
return &MetadataPayloadObjectImpl{*bpl}, nil
}
func LoadMetadataPayloadObjectPO(ponum int, contents []byte) (PayloadObject, error) {
return LoadMetadataPayloadObject(ponum, contents)
}
func CreateMetadataPayloadObject(tup *MetadataTuple) *MetadataPayloadObjectImpl {
mp, _ := CreateMsgPackPayloadObject(PONumSMetadata, tup)
return &MetadataPayloadObjectImpl{*mp}
}
func (po *MetadataPayloadObjectImpl) TextRepresentation() string {
return fmt.Sprintf("PO %s len %d (metadata) @%s:\n%s\n", PONumDotForm(po.ponum),
len(po.contents), time.Unix(0, po.Value().Timestamp), po.Value().Value)
}
func (po *MetadataPayloadObjectImpl) Value() *MetadataTuple {
mt := MetadataTuple{}
po.ValueInto(&mt)
return &mt
}