MCPcopy Create free account
hub / github.com/dan-v/lambda-nat-proxy / ReadControlMessage

Function ReadControlMessage

pkg/shared/control.go:49–68  ·  view source on GitHub ↗

ReadControlMessage reads a control message from the reader

(r io.Reader)

Source from the content-addressed store, hash-verified

47
48// ReadControlMessage reads a control message from the reader
49func ReadControlMessage(r io.Reader) (opcode byte, nonce uint64, err error) {
50 opcode, err = readByte(r)
51 if err != nil {
52 return 0, 0, fmt.Errorf("failed to read opcode: %w", err)
53 }
54
55 switch opcode {
56 case OpPing, OpPong:
57 nonce, err = readUint64(r)
58 if err != nil {
59 return opcode, 0, fmt.Errorf("failed to read nonce: %w", err)
60 }
61 case OpShutdown:
62 // No additional data for shutdown
63 default:
64 return opcode, 0, fmt.Errorf("unknown opcode: %02x", opcode)
65 }
66
67 return opcode, nonce, nil
68}
69
70// Helper functions for reading/writing
71func writeByte(w io.Writer, b byte) error {

Callers 6

handleControlStreamFunction · 0.92
startHealthCheckMethod · 0.92
TestPingPongRoundTripFunction · 0.85
TestPongMessageFunction · 0.85
TestShutdownMessageFunction · 0.85
TestUnknownOpcodeFunction · 0.85

Calls 2

readByteFunction · 0.85
readUint64Function · 0.85

Tested by 4

TestPingPongRoundTripFunction · 0.68
TestPongMessageFunction · 0.68
TestShutdownMessageFunction · 0.68
TestUnknownOpcodeFunction · 0.68