MCPcopy Create free account
hub / github.com/ethstorage/es-node / DecodeOrEncodeKV

Method DecodeOrEncodeKV

ethstorage/shard_manager.go:236–262  ·  view source on GitHub ↗
(kvIdx uint64, b []byte, hash common.Hash, providerAddr common.Address, encode bool, encodeType uint64)

Source from the content-addressed store, hash-verified

234}
235
236func (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.

Callers 2

DecodeKVMethod · 0.95
EncodeKVMethod · 0.95

Calls 3

calcEncodeKeyFunction · 0.85
encodeChunkFunction · 0.85
decodeChunkFunction · 0.85

Tested by

no test coverage detected