MCPcopy Index your code
hub / github.com/syncthing/syncthing / readHeader

Method readHeader

lib/protocol/protocol.go:569–598  ·  view source on GitHub ↗
(fourByteBuf []byte)

Source from the content-addressed store, hash-verified

567}
568
569func (c *rawConnection) readHeader(fourByteBuf []byte) (*bep.Header, error) {
570 // First comes a 2 byte header length
571
572 if _, err := io.ReadFull(c.cr, fourByteBuf[:2]); err != nil {
573 return nil, fmt.Errorf("reading length: %w", err)
574 }
575 hdrLen := int16(binary.BigEndian.Uint16(fourByteBuf))
576 if hdrLen < 0 {
577 return nil, fmt.Errorf("negative header length %d", hdrLen)
578 }
579
580 // Then comes the header
581
582 buf := BufferPool.Get(int(hdrLen))
583 defer BufferPool.Put(buf)
584
585 if _, err := io.ReadFull(c.cr, buf); err != nil {
586 return nil, fmt.Errorf("reading header: %w", err)
587 }
588
589 var hdr bep.Header
590 err := proto.Unmarshal(buf, &hdr)
591 if err != nil {
592 return nil, fmt.Errorf("unmarshalling header: %w", err)
593 }
594
595 metricDeviceRecvDecompressedBytes.WithLabelValues(c.idString).Add(float64(2 + len(buf)))
596
597 return &hdr, nil
598}
599
600func (c *rawConnection) handleIndex(im *Index) error {
601 l.Debugf("Index(%v, %v, %d file)", c.deviceID, im.Folder, len(im.Files))

Callers 1

readMessageMethod · 0.95

Calls 4

GetMethod · 0.65
PutMethod · 0.65
UnmarshalMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected