TryEncodeKV encode the KV data using the miner and encodeType specified by the data shard. Return false if the data is not managed by the ShardManager.
(kvIdx uint64, b []byte, hash common.Hash)
| 186 | // TryEncodeKV encode the KV data using the miner and encodeType specified by the data shard. |
| 187 | // Return false if the data is not managed by the ShardManager. |
| 188 | func (sm *ShardManager) TryEncodeKV(kvIdx uint64, b []byte, hash common.Hash) ([]byte, bool, error) { |
| 189 | shardIdx := kvIdx / sm.kvEntries |
| 190 | if ds, ok := sm.shardMap[shardIdx]; ok { |
| 191 | cb := make([]byte, ds.kvSize) |
| 192 | copy(cb, b) |
| 193 | return sm.EncodeKV(kvIdx, cb, hash, ds.Miner(), ds.EncodeType()) |
| 194 | } else { |
| 195 | return nil, false, nil |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | // TryReadWithMeta Read the encoded KV data and meta from storage file and decode it. |
| 200 | // Return error if the read IO fails. |
no test coverage detected