(kvIdx uint64, b []byte, hash common.Hash, providerAddr common.Address, encode bool, encodeType uint64)
| 234 | } |
| 235 | |
| 236 | func (sm *ShardManager) DecodeOrEncodeKV(kvIdx uint64, b []byte, hash common.Hash, providerAddr common.Address, encode bool, encodeType uint64) ([]byte, bool, error) { |
| 237 | shardIdx := kvIdx / sm.kvEntries |
| 238 | var data []byte |
| 239 | if ds, ok := sm.shardMap[shardIdx]; ok { |
| 240 | datalen := len(b) |
| 241 | for i := uint64(0); i < ds.chunksPerKv; i++ { |
| 242 | if datalen == 0 { |
| 243 | break |
| 244 | } |
| 245 | |
| 246 | chunkReadLen := min(datalen, int(sm.chunkSize)) |
| 247 | datalen = datalen - chunkReadLen |
| 248 | |
| 249 | chunkIdx := kvIdx*ds.chunksPerKv + i |
| 250 | encodeKey := calcEncodeKey(hash, chunkIdx, providerAddr) |
| 251 | var cdata []byte |
| 252 | if encode { |
| 253 | cdata = encodeChunk(sm.chunkSize, b[i*sm.chunkSize:i*sm.chunkSize+uint64(chunkReadLen)], encodeType, encodeKey) |
| 254 | } else { |
| 255 | cdata = decodeChunk(sm.chunkSize, b[i*sm.chunkSize:i*sm.chunkSize+uint64(chunkReadLen)], encodeType, encodeKey) |
| 256 | } |
| 257 | data = append(data, cdata...) |
| 258 | } |
| 259 | return data, true, nil |
| 260 | } |
| 261 | return nil, false, nil |
| 262 | } |
| 263 | |
| 264 | // TryReadEncoded Read the encoded KV data from storage file and return it. |
| 265 | // Return error if the read IO fails. |
no test coverage detected