Use v2 of XDR package (auto generated)

This commit is contained in:
Jakob Borg
2016-02-02 12:44:33 +01:00
parent a08bbabd4d
commit 4feeaf1641
6 changed files with 743 additions and 1025 deletions

View File

@@ -7,37 +7,29 @@ import "github.com/calmh/xdr"
// 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...
type xdrWriter interface {
WriteUint32(uint32) (int, error)
WriteUint64(uint64) (int, error)
}
type xdrReader interface {
ReadUint32() uint32
ReadUint64() uint64
}
// EncodeXDRInto encodes the vector as an XDR object into the given XDR
// encoder.
func (v Vector) EncodeXDRInto(w xdrWriter) (int, error) {
w.WriteUint32(uint32(len(v)))
func (v Vector) MarshalXDRInto(m *xdr.Marshaller) error {
m.MarshalUint32(uint32(len(v)))
for i := range v {
w.WriteUint64(uint64(v[i].ID))
w.WriteUint64(v[i].Value)
m.MarshalUint64(uint64(v[i].ID))
m.MarshalUint64(v[i].Value)
}
return 4 + 16*len(v), nil
return m.Error
}
// DecodeXDRFrom decodes the XDR objects from the given reader into itself.
func (v *Vector) DecodeXDRFrom(r xdrReader) error {
l := int(r.ReadUint32())
func (v *Vector) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
l := int(u.UnmarshalUint32())
if l > 1e6 {
return xdr.ElementSizeExceeded("number of counters", l, 1e6)
}
n := make(Vector, l)
for i := range n {
n[i].ID = ShortID(r.ReadUint64())
n[i].Value = r.ReadUint64()
n[i].ID = ShortID(u.UnmarshalUint64())
n[i].Value = u.UnmarshalUint64()
}
*v = n
return nil
return u.Error
}
func (v Vector) XDRSize() int {
return 4 + 16*len(v)
}