MCPcopy Index your code
hub / github.com/coder/coder / WriteFrame

Function WriteFrame

agent/boundarylogproxy/codec/codec.go:62–85  ·  view source on GitHub ↗

WriteFrame writes a framed message with the given tag and data. The data must not exceed 2^DataLength in length.

(w io.Writer, tag Tag, data []byte)

Source from the content-addressed store, hash-verified

60// WriteFrame writes a framed message with the given tag and data. The data
61// must not exceed 2^DataLength in length.
62func WriteFrame(w io.Writer, tag Tag, data []byte) error {
63 maxSize, err := maxSizeForTag(tag)
64 if err != nil {
65 return err
66 }
67
68 if len(data) > int(maxSize) {
69 return xerrors.Errorf("%w for tag %d: %d > %d", ErrMessageTooLarge, tag, len(data), maxSize)
70 }
71
72 var header uint32
73 //nolint:gosec // The length check above ensures there's no overflow.
74 header |= uint32(len(data))
75 header |= uint32(tag) << DataLength
76
77 if err := binary.Write(w, binary.BigEndian, header); err != nil {
78 return xerrors.Errorf("write header error: %w", err)
79 }
80 if _, err := w.Write(data); err != nil {
81 return xerrors.Errorf("write data error: %w", err)
82 }
83
84 return nil
85}
86
87// ReadFrame reads a framed message, returning the decoded tag and data. If the
88// message size exceeds MaxMessageSizeV1, ErrMessageTooLarge is returned. The

Callers 6

sendBoundaryLogsRequestFunction · 0.92
TestRoundTripFunction · 0.92
TestWriteFrameDataSizeFunction · 0.92
TestWriteFrameInvalidTagFunction · 0.92
WriteMessageFunction · 0.85

Calls 3

maxSizeForTagFunction · 0.85
WriteMethod · 0.65
ErrorfMethod · 0.45

Tested by 5

sendBoundaryLogsRequestFunction · 0.74
TestRoundTripFunction · 0.74
TestWriteFrameDataSizeFunction · 0.74
TestWriteFrameInvalidTagFunction · 0.74