(data *[]byte, expanded bool)
| 454 | } |
| 455 | |
| 456 | func decodeFlowSample(data *[]byte, expanded bool) (SFlowFlowSample, error) { |
| 457 | s := SFlowFlowSample{} |
| 458 | var sdf SFlowDataFormat |
| 459 | *data, sdf = (*data)[4:], SFlowDataFormat(binary.BigEndian.Uint32((*data)[:4])) |
| 460 | var sdc SFlowDataSource |
| 461 | |
| 462 | s.EnterpriseID, s.Format = sdf.decode() |
| 463 | if len(*data) < 4 { |
| 464 | return SFlowFlowSample{}, errors.New("ethernet counters too small") |
| 465 | } |
| 466 | *data, s.SampleLength = (*data)[4:], binary.BigEndian.Uint32((*data)[:4]) |
| 467 | if len(*data) < 4 { |
| 468 | return SFlowFlowSample{}, errors.New("ethernet counters too small") |
| 469 | } |
| 470 | *data, s.SequenceNumber = (*data)[4:], binary.BigEndian.Uint32((*data)[:4]) |
| 471 | if expanded { |
| 472 | if len(*data) < 4 { |
| 473 | return SFlowFlowSample{}, errors.New("ethernet counters too small") |
| 474 | } |
| 475 | *data, s.SourceIDClass = (*data)[4:], SFlowSourceFormat(binary.BigEndian.Uint32((*data)[:4])) |
| 476 | if len(*data) < 4 { |
| 477 | return SFlowFlowSample{}, errors.New("ethernet counters too small") |
| 478 | } |
| 479 | *data, s.SourceIDIndex = (*data)[4:], SFlowSourceValue(binary.BigEndian.Uint32((*data)[:4])) |
| 480 | } else { |
| 481 | if len(*data) < 4 { |
| 482 | return SFlowFlowSample{}, errors.New("ethernet counters too small") |
| 483 | } |
| 484 | *data, sdc = (*data)[4:], SFlowDataSource(binary.BigEndian.Uint32((*data)[:4])) |
| 485 | s.SourceIDClass, s.SourceIDIndex = sdc.decode() |
| 486 | } |
| 487 | if len(*data) < 4 { |
| 488 | return SFlowFlowSample{}, errors.New("ethernet counters too small") |
| 489 | } |
| 490 | *data, s.SamplingRate = (*data)[4:], binary.BigEndian.Uint32((*data)[:4]) |
| 491 | if len(*data) < 4 { |
| 492 | return SFlowFlowSample{}, errors.New("ethernet counters too small") |
| 493 | } |
| 494 | *data, s.SamplePool = (*data)[4:], binary.BigEndian.Uint32((*data)[:4]) |
| 495 | if len(*data) < 4 { |
| 496 | return SFlowFlowSample{}, errors.New("ethernet counters too small") |
| 497 | } |
| 498 | *data, s.Dropped = (*data)[4:], binary.BigEndian.Uint32((*data)[:4]) |
| 499 | |
| 500 | if expanded { |
| 501 | if len(*data) < 4 { |
| 502 | return SFlowFlowSample{}, errors.New("ethernet counters too small") |
| 503 | } |
| 504 | *data, s.InputInterfaceFormat = (*data)[4:], binary.BigEndian.Uint32((*data)[:4]) |
| 505 | if len(*data) < 4 { |
| 506 | return SFlowFlowSample{}, errors.New("ethernet counters too small") |
| 507 | } |
| 508 | *data, s.InputInterface = (*data)[4:], binary.BigEndian.Uint32((*data)[:4]) |
| 509 | if len(*data) < 4 { |
| 510 | return SFlowFlowSample{}, errors.New("ethernet counters too small") |
| 511 | } |
| 512 | *data, s.OutputInterfaceFormat = (*data)[4:], binary.BigEndian.Uint32((*data)[:4]) |
| 513 | if len(*data) < 4 { |
no test coverage detected
searching dependent graphs…