Encode writes the Index to the stream of the encoder.
(idx *Index)
| 35 | |
| 36 | // Encode writes the Index to the stream of the encoder. |
| 37 | func (e *Encoder) Encode(idx *Index) error { |
| 38 | // TODO: support v4 |
| 39 | // TODO: support extensions |
| 40 | if idx.Version > EncodeVersionSupported { |
| 41 | return ErrUnsupportedVersion |
| 42 | } |
| 43 | |
| 44 | if err := e.encodeHeader(idx); err != nil { |
| 45 | return err |
| 46 | } |
| 47 | |
| 48 | if err := e.encodeEntries(idx); err != nil { |
| 49 | return err |
| 50 | } |
| 51 | |
| 52 | return e.encodeFooter() |
| 53 | } |
| 54 | |
| 55 | func (e *Encoder) encodeHeader(idx *Index) error { |
| 56 | return binary.Write(e.w, |