Code Room
Code reviewMediumcr-g589
Subject Tcp socket framingLevel Mid–Senior~20 minCommon in Networking & APIs interviewsIndustries Software development, Telecom

Question

Review this Go TCP client snippet. It reads a length-prefixed message from a server.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.

Talk through your review
Code to reviewgo
func readMessage(conn net.Conn) ([]byte, error) {	var header [4]byte	if _, err := conn.Read(header[:]); err != nil {		return nil, err	}	n := binary.BigEndian.Uint32(header[:])	buf := make([]byte, n)	if _, err := conn.Read(buf); err != nil {		return nil, err	}	return buf, nil}
Run or narrate your approach, then ask the coach.