MCPcopy Create free account
hub / github.com/0xsequence/czip / WriteNWords

Method WriteNWords

compressor/encode.go:276–310  ·  view source on GitHub ↗

Encodes N words

(words []byte)

Source from the content-addressed store, hash-verified

274
275// Encodes N words
276func (buf *Buffer) WriteNWords(words []byte) (EncodeType, error) {
277 count := len(words) / 32
278 if len(words)%32 != 0 {
279 return Stateless, fmt.Errorf("words are not aligned to 32 bytes")
280 }
281
282 if count == 0 {
283 return Stateless, fmt.Errorf("words are empty")
284 }
285
286 if count <= 255 {
287 buf.commitUint(FLAG_NESTED_N_FLAGS_S)
288 buf.commitByte(byte(count))
289 } else if count <= 65535 {
290 buf.commitUint(FLAG_NESTED_N_FLAGS_L)
291 buf.commitByte(byte(count >> 8))
292 buf.commitByte(byte(count))
293 } else {
294 return Stateless, fmt.Errorf("too many words")
295 }
296
297 buf.end([]byte{}, Stateless)
298
299 encodeType := Stateless
300 for i := 0; i < count; i++ {
301 encoded, err := buf.WriteWord(words[i*32:i*32+32], buf.Refs.useContractStorage)
302 if err != nil {
303 return Stateless, err
304 }
305
306 encodeType = maxPriority(encodeType, encoded)
307 }
308
309 return encodeType, nil
310}
311
312// Encodes and writes a word to the buffer
313func (buf *Buffer) WriteWord(word []byte, useStorage bool) (EncodeType, error) {

Callers 1

extras.goFile · 0.80

Calls 5

commitUintMethod · 0.95
commitByteMethod · 0.95
endMethod · 0.95
WriteWordMethod · 0.95
maxPriorityFunction · 0.85

Tested by

no test coverage detected