ReadFile reads a file into 'dst' using a read-only memory mapping. Consequently, the file must be mmap-able, and the Unmarshaler should never write to the source memory. (Methods generated by the msgp tool obey that constraint, but user-defined implementations may not.) Reading and writing through
(dst Unmarshaler, file *os.File)
| 20 | // files are best read and written using |
| 21 | // the ordinary streaming interfaces. |
| 22 | func ReadFile(dst Unmarshaler, file *os.File) error { |
| 23 | stat, err := file.Stat() |
| 24 | if err != nil { |
| 25 | return err |
| 26 | } |
| 27 | data, err := syscall.Mmap(int(file.Fd()), 0, int(stat.Size()), syscall.PROT_READ, syscall.MAP_SHARED) |
| 28 | if err != nil { |
| 29 | return err |
| 30 | } |
| 31 | adviseRead(data) |
| 32 | _, err = dst.UnmarshalMsg(data) |
| 33 | uerr := syscall.Munmap(data) |
| 34 | if err == nil { |
| 35 | err = uerr |
| 36 | } |
| 37 | return err |
| 38 | } |
| 39 | |
| 40 | // MarshalSizer is the combination |
| 41 | // of the Marshaler and Sizer |
nothing calls this directly
no test coverage detected
searching dependent graphs…