本文整理匯總了Golang中github.com/FactomProject/factomd/common/interfaces.DatabaseBatchable.MarshalBinary方法的典型用法代碼示例。如果您正苦於以下問題:Golang DatabaseBatchable.MarshalBinary方法的具體用法?Golang DatabaseBatchable.MarshalBinary怎麽用?Golang DatabaseBatchable.MarshalBinary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/FactomProject/factomd/common/interfaces.DatabaseBatchable
的用法示例。
在下文中一共展示了DatabaseBatchable.MarshalBinary方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SaveEntryBinary
func SaveEntryBinary(entry interfaces.DatabaseBatchable, blockHeight uint32) error {
data, err := entry.MarshalBinary()
if err != nil {
return err
}
strChainID := fmt.Sprintf("%x", entry.GetChainID())
dir := DataStorePath + strChainID + "/entries"
if FileNotExists(dir) {
err := os.MkdirAll(dir, 0777)
if err == nil {
fmt.Println("Created directory " + dir)
} else {
return err
}
}
err = ioutil.WriteFile(fmt.Sprintf(dir+"/store.%09d.%v.entry", blockHeight, entry.DatabasePrimaryIndex().String()), data, 0777)
if err != nil {
return err
}
return nil
}
示例2: SaveBinary
func SaveBinary(block interfaces.DatabaseBatchable) error {
data, err := block.MarshalBinary()
if err != nil {
return err
}
strChainID := fmt.Sprintf("%x", block.GetChainID())
dir := DataStorePath + strChainID
if FileNotExists(dir) {
err := os.MkdirAll(dir, 0777)
if err == nil {
fmt.Println("Created directory " + dir)
} else {
return err
}
}
err = ioutil.WriteFile(fmt.Sprintf(dir+"/store.%09d.block", block.GetDatabaseHeight()), data, 0777)
if err != nil {
return err
}
return nil
}