(entry *Entry)
| 158 | } |
| 159 | |
| 160 | func (e *Encoder) encodeEntryNameV4(entry *Entry) error { |
| 161 | // V4 prefix compression: find the longest common prefix between the |
| 162 | // previous entry's name and the current one. The strip length tells |
| 163 | // the decoder how many bytes to remove from the end of the previous |
| 164 | // name, and the suffix is the remainder of the current name. |
| 165 | prefix := 0 |
| 166 | if e.lastEntry != nil { |
| 167 | prefix = commonPrefixLen(e.lastEntry.Name, entry.Name) |
| 168 | } |
| 169 | stripLen := 0 |
| 170 | if e.lastEntry != nil { |
| 171 | stripLen = len(e.lastEntry.Name) - prefix |
| 172 | } |
| 173 | |
| 174 | e.lastEntry = entry |
| 175 | |
| 176 | if err := binary.WriteVariableWidthInt(e.w, int64(stripLen)); err != nil { |
| 177 | return err |
| 178 | } |
| 179 | |
| 180 | suffix := entry.Name[prefix:] |
| 181 | return binary.Write(e.w, append([]byte(suffix), '\x00')) |
| 182 | } |
| 183 | |
| 184 | // commonPrefixLen returns the length of the longest common byte prefix |
| 185 | // between a and b. |
no test coverage detected