RLEncodebytes takes a byte slice and returns its run-length encoding as a byte slice
(data []byte)
| 48 | |
| 49 | // RLEncodebytes takes a byte slice and returns its run-length encoding as a byte slice |
| 50 | func RLEncodebytes(data []byte) []byte { |
| 51 | var result []byte |
| 52 | var count byte = 1 |
| 53 | |
| 54 | for i := 0; i < len(data); i++ { |
| 55 | if i+1 < len(data) && data[i] == data[i+1] { |
| 56 | count++ |
| 57 | continue |
| 58 | } |
| 59 | result = append(result, count, data[i]) |
| 60 | count = 1 |
| 61 | } |
| 62 | |
| 63 | return result |
| 64 | } |
| 65 | |
| 66 | // RLEdecodebytes takes a run-length encoded byte slice and returns the original byte slice |
| 67 | func RLEdecodebytes(data []byte) []byte { |
no outgoing calls