MCPcopy Create free account
hub / github.com/pion/rtcp / wireSize

Function wireSize

packet_buffer.go:235–270  ·  view source on GitHub ↗

Returns the size that a structure will encode into. This fuction doesn't check that Write() will succeed, and may return unexpectedly large results for those structures that Write() will fail on.

(v any)

Source from the content-addressed store, hash-verified

233// and may return unexpectedly large results for those
234// structures that Write() will fail on.
235func wireSize(v any) int {
236 value := reflect.ValueOf(v)
237 // Indirect is safe to call on non-pointers, and
238 // will simply return the same value in such cases
239 value = reflect.Indirect(value)
240 size := int(0)
241
242 switch value.Kind() {
243 case reflect.Slice:
244 for i := 0; i < value.Len(); i++ {
245 if value.Index(i).CanInterface() {
246 size += wireSize(value.Index(i).Interface())
247 } else {
248 size += int(value.Index(i).Type().Size()) //nolint:gosec // RTCP element sizes are small and bounded
249 }
250 }
251
252 case reflect.Struct:
253 for i := 0; i < value.NumField(); i++ {
254 encoding := value.Type().Field(i).Tag.Get("encoding")
255 if encoding == omit {
256 continue
257 }
258 if value.Field(i).CanInterface() {
259 size += wireSize(value.Field(i).Interface())
260 } else {
261 size += int(value.Field(i).Type().Size()) // nolint:gosec // Size comes from type system and is bounded
262 }
263 }
264
265 default:
266 size = int(value.Type().Size()) // nolint:gosec // Size comes from type system and is bounde
267 }
268
269 return size
270}

Callers 11

setupBlockHeaderMethod · 0.85
setupBlockHeaderMethod · 0.85
setupBlockHeaderMethod · 0.85
setupBlockHeaderMethod · 0.85
setupBlockHeaderMethod · 0.85
setupBlockHeaderMethod · 0.85
setupBlockHeaderMethod · 0.85
setupBlockHeaderMethod · 0.85
MarshalSizeMethod · 0.85
MarshalMethod · 0.85
TestWriteFunction · 0.85

Calls 2

TypeMethod · 0.80
LenMethod · 0.45

Tested by 1

TestWriteFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…