Files
syncthing-arm/lib/db/truncated.go
T

55 lines
1.3 KiB
Go
Raw Normal View History

2015-01-09 08:19:32 +01:00
// Copyright (C) 2014 The Syncthing Authors.
//
2015-03-07 21:36:35 +01:00
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
2015-01-09 08:19:32 +01:00
package db
2015-01-09 08:19:32 +01:00
import (
"bytes"
"github.com/calmh/xdr"
"github.com/syncthing/syncthing/lib/protocol"
)
2015-01-09 08:19:32 +01:00
type FileInfoTruncated struct {
2015-02-13 13:46:49 +01:00
protocol.FileInfo
2015-01-09 08:19:32 +01:00
}
func (o *FileInfoTruncated) UnmarshalXDR(bs []byte) error {
var br = bytes.NewReader(bs)
var xr = xdr.NewReader(br)
return o.DecodeXDRFrom(xr)
2015-01-09 08:19:32 +01:00
}
func (o *FileInfoTruncated) DecodeXDRFrom(xr *xdr.Reader) error {
o.Name = xr.ReadStringMax(8192)
o.Flags = xr.ReadUint32()
o.Modified = int64(xr.ReadUint64())
(&o.Version).DecodeXDRFrom(xr)
o.LocalVersion = int64(xr.ReadUint64())
_BlocksSize := int(xr.ReadUint32())
if _BlocksSize < 0 {
return xdr.ElementSizeExceeded("Blocks", _BlocksSize, 1000000)
}
if _BlocksSize > 1000000 {
return xdr.ElementSizeExceeded("Blocks", _BlocksSize, 1000000)
}
buf := make([]byte, 64)
for i := 0; i < _BlocksSize; i++ {
size := xr.ReadUint32()
o.CachedSize += int64(size)
xr.ReadBytesMaxInto(64, buf)
}
return xr.Error()
2015-01-09 08:19:32 +01:00
}
2015-01-18 02:12:06 +01:00
func BlocksToSize(num int) int64 {
2015-01-09 08:19:32 +01:00
if num < 2 {
return protocol.BlockSize / 2
}
return int64(num-1)*protocol.BlockSize + protocol.BlockSize/2
}