pipe.go 716 B

12345678910111213141516171819202122232425262728293031
  1. package ndr
  2. import (
  3. "fmt"
  4. "reflect"
  5. )
  6. func (dec *Decoder) fillPipe(v reflect.Value, tag reflect.StructTag) error {
  7. s, err := dec.readUint32() // read element count of first chunk
  8. if err != nil {
  9. return err
  10. }
  11. a := reflect.MakeSlice(v.Type(), 0, 0)
  12. c := reflect.MakeSlice(v.Type(), int(s), int(s))
  13. for s != 0 {
  14. for i := 0; i < int(s); i++ {
  15. err := dec.fill(c.Index(i), tag, &[]deferedPtr{})
  16. if err != nil {
  17. return fmt.Errorf("could not fill element %d of pipe: %v", i, err)
  18. }
  19. }
  20. s, err = dec.readUint32() // read element count of first chunk
  21. if err != nil {
  22. return err
  23. }
  24. a = reflect.AppendSlice(a, c)
  25. c = reflect.MakeSlice(v.Type(), int(s), int(s))
  26. }
  27. v.Set(a)
  28. return nil
  29. }