encodeExpire encodes the value format: [type][data]
(deadtime int64)
| 172 | // encodeExpire encodes the value |
| 173 | // format: [type][data] |
| 174 | func (ek *ExpireStructure) encodeExpire(deadtime int64) ([]byte, error) { |
| 175 | // Create a byte slice buf with a length of binary.MaxVarintLen64 |
| 176 | // to hold the encoded value and additional data. |
| 177 | buf := make([]byte, binary.MaxVarintLen64) |
| 178 | |
| 179 | // Set the first element of buf to represent the data structure type as String. |
| 180 | buf[0] = Expire |
| 181 | |
| 182 | // Use the variable bufIndex to keep track of the current index position in buf, |
| 183 | // starting from 1 to indicate the number of bytes written so far. |
| 184 | var bufIndex = 1 |
| 185 | |
| 186 | // Encode the expiration time expire as a variable-length integer |
| 187 | // and write it to the sub-slice of byte slice buf starting |
| 188 | // from the current index position bufIndex. |
| 189 | bufIndex += binary.PutVarint(buf[bufIndex:], deadtime) |
| 190 | |
| 191 | return buf[:bufIndex], nil |
| 192 | } |
| 193 | |
| 194 | // decodeList decodes the value |
| 195 | func (ek *ExpireStructure) decodeExpire(value []byte) (int64, error) { |