readWith read the encoded data from storage with a decoder.
(kvIdx uint64, readLen int, decoder func([]byte, uint64) []byte)
| 188 | |
| 189 | // readWith read the encoded data from storage with a decoder. |
| 190 | func (ds *DataShard) readWith(kvIdx uint64, readLen int, decoder func([]byte, uint64) []byte) ([]byte, error) { |
| 191 | if !ds.Contains(kvIdx) { |
| 192 | return nil, fmt.Errorf("kv not found") |
| 193 | } |
| 194 | if readLen > int(ds.kvSize) { |
| 195 | return nil, fmt.Errorf("read len too large") |
| 196 | } |
| 197 | var data []byte |
| 198 | for i := uint64(0); i < ds.chunksPerKv; i++ { |
| 199 | if readLen == 0 { |
| 200 | break |
| 201 | } |
| 202 | |
| 203 | chunkReadLen := min(readLen, int(ds.chunkSize)) |
| 204 | readLen = readLen - chunkReadLen |
| 205 | |
| 206 | chunkIdx := kvIdx*ds.chunksPerKv + i |
| 207 | cdata, err := ds.readChunk(chunkIdx, chunkReadLen) |
| 208 | if err != nil { |
| 209 | return nil, err |
| 210 | } |
| 211 | |
| 212 | cdata = decoder(cdata, chunkIdx) |
| 213 | data = append(data, cdata...) |
| 214 | } |
| 215 | return data, nil |
| 216 | } |
| 217 | |
| 218 | func (ds *DataShard) ReadSample(sampleIdx uint64) (common.Hash, error) { |
| 219 |
no test coverage detected