processPrelude is the function that reads the 12 bytes of the prelude and ensures the CRC is correct while also extracting relevant information into the struct,
(prelude io.Reader, crc hash.Hash32)
| 622 | // ensures the CRC is correct while also extracting relevant information into |
| 623 | // the struct, |
| 624 | func processPrelude(prelude io.Reader, crc hash.Hash32) (preludeInfo, error) { |
| 625 | var err error |
| 626 | pInfo := preludeInfo{} |
| 627 | |
| 628 | // reads total length of the message (first 4 bytes) |
| 629 | pInfo.totalLen, err = extractUint32(prelude) |
| 630 | if err != nil { |
| 631 | return pInfo, err |
| 632 | } |
| 633 | |
| 634 | // reads total header length of the message (2nd 4 bytes) |
| 635 | pInfo.headerLen, err = extractUint32(prelude) |
| 636 | if err != nil { |
| 637 | return pInfo, err |
| 638 | } |
| 639 | |
| 640 | // checks that the CRC is correct (3rd 4 bytes) |
| 641 | preCRC := crc.Sum32() |
| 642 | if err := checkCRC(prelude, preCRC); err != nil { |
| 643 | return pInfo, err |
| 644 | } |
| 645 | |
| 646 | return pInfo, nil |
| 647 | } |
| 648 | |
| 649 | // extracts the relevant information from the Headers. |
| 650 | func extractHeader(body io.Reader, myHeaders http.Header) error { |
no test coverage detected