2015-03-20 08:58:32 +00:00
|
|
|
// Copyright (C) 2015 The Protocol Authors.
|
|
|
|
|
|
|
|
package protocol
|
|
|
|
|
2015-08-18 06:41:34 +00:00
|
|
|
import "github.com/calmh/xdr"
|
|
|
|
|
2015-03-20 08:58:32 +00:00
|
|
|
// This stuff is hacked up manually because genxdr doesn't support 'type
|
|
|
|
// Vector []Counter' declarations and it was tricky when I tried to add it...
|
|
|
|
|
2016-02-02 11:44:33 +00:00
|
|
|
func (v Vector) MarshalXDRInto(m *xdr.Marshaller) error {
|
|
|
|
m.MarshalUint32(uint32(len(v)))
|
2015-03-20 08:58:32 +00:00
|
|
|
for i := range v {
|
2016-02-02 11:44:33 +00:00
|
|
|
m.MarshalUint64(uint64(v[i].ID))
|
|
|
|
m.MarshalUint64(v[i].Value)
|
2015-03-20 08:58:32 +00:00
|
|
|
}
|
2016-02-02 11:44:33 +00:00
|
|
|
return m.Error
|
2015-03-20 08:58:32 +00:00
|
|
|
}
|
|
|
|
|
2016-02-02 11:44:33 +00:00
|
|
|
func (v *Vector) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
|
|
|
|
l := int(u.UnmarshalUint32())
|
2015-08-18 06:41:34 +00:00
|
|
|
if l > 1e6 {
|
|
|
|
return xdr.ElementSizeExceeded("number of counters", l, 1e6)
|
|
|
|
}
|
2015-03-20 08:58:32 +00:00
|
|
|
n := make(Vector, l)
|
|
|
|
for i := range n {
|
2016-02-02 11:44:33 +00:00
|
|
|
n[i].ID = ShortID(u.UnmarshalUint64())
|
|
|
|
n[i].Value = u.UnmarshalUint64()
|
2015-03-20 08:58:32 +00:00
|
|
|
}
|
|
|
|
*v = n
|
2016-02-02 11:44:33 +00:00
|
|
|
return u.Error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v Vector) XDRSize() int {
|
|
|
|
return 4 + 16*len(v)
|
2015-03-20 08:58:32 +00:00
|
|
|
}
|