本文整理汇总了Golang中github.com/timtadh/fs2/fmap.BlockFile.BlockSize方法的典型用法代码示例。如果您正苦于以下问题:Golang BlockFile.BlockSize方法的具体用法?Golang BlockFile.BlockSize怎么用?Golang BlockFile.BlockSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/timtadh/fs2/fmap.BlockFile
的用法示例。
在下文中一共展示了BlockFile.BlockSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: OpenVarchar
// Open a varchar structure in the given blockfile with the given offset
// as the control block. This function will confirm that the control
// block is indeed a properly formated control block.
func OpenVarchar(bf *fmap.BlockFile, a uint64) (v *Varchar, err error) {
v = &Varchar{bf: bf, a: a, blkSize: bf.BlockSize()}
var ptOff uint64
var szOff uint64
err = v.bf.Do(v.a, 1, func(bytes []byte) error {
ctrl := asCtrl(bytes)
if ctrl.flags&consts.VARCHAR_CTRL == 0 {
return errors.Errorf("Expected a Varchar control block")
}
ptOff = ctrl.posTree
szOff = ctrl.sizeTree
return nil
})
if err != nil {
return nil, err
}
v.posTree, err = OpenAt(bf, ptOff)
if err != nil {
return nil, err
}
v.sizeTree, err = OpenAt(bf, szOff)
if err != nil {
return nil, err
}
return v, nil
}
示例2: NewVarchar
// Create a new varchar structure. This takes a blockfile and an offset
// of an allocated block. The block becomes the control block for the
// varchar file (storing the free list for the allocator). It is
// important for the parent structure to track the location of this
// control block.
func NewVarchar(bf *fmap.BlockFile, a uint64) (v *Varchar, err error) {
ptOff, err := bf.Allocate()
if err != nil {
return nil, err
}
posTree, err := NewAt(bf, ptOff, 8, 0)
if err != nil {
return nil, err
}
szOff, err := bf.Allocate()
if err != nil {
return nil, err
}
sizeTree, err := NewAt(bf, szOff, 4, 8)
if err != nil {
return nil, err
}
v = &Varchar{
bf: bf,
posTree: posTree,
sizeTree: sizeTree,
a: a,
blkSize: bf.BlockSize(),
}
err = v.bf.Do(v.a, 1, func(bytes []byte) error {
ctrl := asCtrl(bytes)
ctrl.Init(ptOff, szOff)
return nil
})
if err != nil {
return nil, err
}
return v, nil
}