decFloat32Sequence receives a byte slice with float numbers separated by spaces and a preallocated destination slice. It reads numbers from the source byte slice, converts them to float32 and stores in the destination array.
(cdata []byte, dest []float32)
| 350 | // It reads numbers from the source byte slice, converts them to float32 and |
| 351 | // stores in the destination array. |
| 352 | func decFloat32Sequence(cdata []byte, dest []float32) error { |
| 353 | |
| 354 | var br bytesReader |
| 355 | br.Init(cdata) |
| 356 | idx := 0 |
| 357 | for { |
| 358 | tok := br.TokenNext() |
| 359 | if tok == nil { |
| 360 | break |
| 361 | } |
| 362 | if idx >= len(dest) { |
| 363 | return fmt.Errorf("To much float array data") |
| 364 | } |
| 365 | v, err := strconv.ParseFloat(string(tok), 32) |
| 366 | if err != nil { |
| 367 | return err |
| 368 | } |
| 369 | dest[idx] = float32(v) |
| 370 | idx++ |
| 371 | } |
| 372 | if idx < len(dest)-1 { |
| 373 | return fmt.Errorf("Expected %d floats, got %d", len(dest), idx) |
| 374 | } |
| 375 | return nil |
| 376 | } |
| 377 | |
| 378 | // decStringSequence receives a byte slice with strings separated |
| 379 | // by spaces and a preallocated destination slice. |
no test coverage detected