Encodes N words
(words []byte)
| 274 | |
| 275 | // Encodes N words |
| 276 | func (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 |
| 313 | func (buf *Buffer) WriteWord(word []byte, useStorage bool) (EncodeType, error) { |
no test coverage detected