MCPcopy Create free account
hub / github.com/dgrr/http2 / Read

Method Read

settings.go:166–206  ·  view source on GitHub ↗

Read reads from d and decodes the read values into st.

(d []byte)

Source from the content-addressed store, hash-verified

164
165// Read reads from d and decodes the read values into st.
166func (st *Settings) Read(d []byte) error {
167 var b []byte
168 var key uint16
169 var value uint32
170
171 last, i, n := 0, 6, len(d)
172
173 for i <= n {
174 b = d[last:i]
175 key = uint16(b[0])<<8 | uint16(b[1])
176 value = uint32(b[2])<<24 | uint32(b[3])<<16 | uint32(b[4])<<8 | uint32(b[5])
177
178 switch key {
179 case HeaderTableSize:
180 st.tableSize = value
181 case EnablePush:
182 if value != 0 && value != 1 {
183 return NewGoAwayError(ProtocolError, "wrong value for SETTINGS_ENABLE_PUSH")
184 }
185 st.enablePush = value != 0
186 case MaxConcurrentStreams:
187 st.maxStreams = value
188 case MaxWindowSize:
189 if value > 1<<31-1 {
190 return NewGoAwayError(FlowControlError, "SETTINGS_INITIAL_WINDOW_SIZE above maximum")
191 }
192 st.windowSize = value
193 case MaxFrameSize:
194 if value < 1<<14 || value > 1<<24-1 {
195 return NewGoAwayError(ProtocolError, "wrong value for SETTINGS_MAX_FRAME_SIZE")
196 }
197 st.frameSize = value
198 case MaxHeaderListSize:
199 st.headerSize = value
200 }
201
202 last = i
203 i += 6
204 }
205 return nil
206}
207
208// Encode encodes settings to be sent through the wire.
209func (st *Settings) Encode() {

Callers 4

DeserializeMethod · 0.95
ReadFromMethod · 0.80
ReadPrefaceFunction · 0.80
AddPaddingFunction · 0.80

Calls 1

NewGoAwayErrorFunction · 0.85

Tested by

no test coverage detected