Update xdr; handle marshalling errors

This commit is contained in:
Jakob Borg
2014-10-21 08:40:05 +02:00
parent 1e915a2903
commit f2adfde1a8
16 changed files with 781 additions and 170 deletions

View File

@@ -289,7 +289,8 @@ func ldbReplaceWithDelete(db *leveldb.DB, folder, device []byte, fs []protocol.F
Flags: tf.Flags | protocol.FlagDeleted,
Modified: tf.Modified,
}
batch.Put(dbi.Key(), f.MarshalXDR())
bs, _ := f.MarshalXDR()
batch.Put(dbi.Key(), bs)
ldbUpdateGlobal(db, batch, folder, device, deviceKeyName(dbi.Key()), f.Version)
return ts
}
@@ -362,7 +363,7 @@ func ldbInsert(batch dbWriter, folder, device []byte, file protocol.FileInfo) ui
name := []byte(file.Name)
nk := deviceKey(folder, device, name)
batch.Put(nk, file.MarshalXDR())
batch.Put(nk, file.MustMarshalXDR())
return file.LocalVersion
}
@@ -416,7 +417,7 @@ func ldbUpdateGlobal(db dbReader, batch dbWriter, folder, device, file []byte, v
fl.versions = append(fl.versions, nv)
done:
batch.Put(gk, fl.MarshalXDR())
batch.Put(gk, fl.MustMarshalXDR())
return true
}
@@ -453,7 +454,7 @@ func ldbRemoveFromGlobal(db dbReader, batch dbWriter, folder, device, file []byt
if len(fl.versions) == 0 {
batch.Delete(gk)
} else {
batch.Put(gk, fl.MarshalXDR())
batch.Put(gk, fl.MustMarshalXDR())
}
}

View File

@@ -42,15 +42,23 @@ func (o fileVersion) EncodeXDR(w io.Writer) (int, error) {
return o.encodeXDR(xw)
}
func (o fileVersion) MarshalXDR() []byte {
func (o fileVersion) MarshalXDR() ([]byte, error) {
return o.AppendXDR(make([]byte, 0, 128))
}
func (o fileVersion) AppendXDR(bs []byte) []byte {
func (o fileVersion) MustMarshalXDR() []byte {
bs, err := o.MarshalXDR()
if err != nil {
panic(err)
}
return bs
}
func (o fileVersion) AppendXDR(bs []byte) ([]byte, error) {
var aw = xdr.AppendWriter(bs)
var xw = xdr.NewWriter(&aw)
o.encodeXDR(xw)
return []byte(aw)
_, err := o.encodeXDR(xw)
return []byte(aw), err
}
func (o fileVersion) encodeXDR(xw *xdr.Writer) (int, error) {
@@ -102,15 +110,23 @@ func (o versionList) EncodeXDR(w io.Writer) (int, error) {
return o.encodeXDR(xw)
}
func (o versionList) MarshalXDR() []byte {
func (o versionList) MarshalXDR() ([]byte, error) {
return o.AppendXDR(make([]byte, 0, 128))
}
func (o versionList) AppendXDR(bs []byte) []byte {
func (o versionList) MustMarshalXDR() []byte {
bs, err := o.MarshalXDR()
if err != nil {
panic(err)
}
return bs
}
func (o versionList) AppendXDR(bs []byte) ([]byte, error) {
var aw = xdr.AppendWriter(bs)
var xw = xdr.NewWriter(&aw)
o.encodeXDR(xw)
return []byte(aw)
_, err := o.encodeXDR(xw)
return []byte(aw), err
}
func (o versionList) encodeXDR(xw *xdr.Writer) (int, error) {