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

Function encodeChunk

ethstorage/data_shard.go:252–283  ·  view source on GitHub ↗
(chunkSize uint64, bs []byte, encodeType uint64, encodeKey common.Hash)

Source from the content-addressed store, hash-verified

250}
251
252func encodeChunk(chunkSize uint64, bs []byte, encodeType uint64, encodeKey common.Hash) []byte {
253 if len(bs) > int(chunkSize) {
254 panic("cannot encode chunk with size > CHUNK_SIZE")
255 }
256 if encodeType == ENCODE_KECCAK_256 {
257 output := make([]byte, chunkSize)
258 j := 0
259 for i := 0; i < int(chunkSize); i++ {
260 b := byte(0)
261 if i < len(bs) {
262 b = bs[i]
263 }
264 output[i] = b ^ encodeKey[j]
265 j = j + 1
266 if j >= len(encodeKey) {
267 j = 0
268 }
269 }
270 return output
271 } else if encodeType == NO_ENCODE {
272 output := make([]byte, chunkSize)
273 copy(output, bs)
274 return output
275 } else if encodeType == ENCODE_BLOB_POSEIDON {
276 mask, _ := encoder.Encode(encodeKey, int(chunkSize))
277 return MaskDataInPlace(mask, bs)
278 } else if encodeType == ENCODE_ETHASH {
279 return MaskDataInPlace(pora.GetMaskData(0, encodeKey, int(chunkSize), nil), bs)
280 } else {
281 panic("unsupported encode type")
282 }
283}
284
285func IsValidEncodeType(encodeType uint64) bool {
286 switch encodeType {

Callers 3

EncodeChunkFunction · 0.85
WriteMethod · 0.85
DecodeOrEncodeKVMethod · 0.85

Calls 3

EncodeFunction · 0.92
GetMaskDataFunction · 0.92
MaskDataInPlaceFunction · 0.85

Tested by

no test coverage detected