(prefix string, withPerfix bool)
| 175 | } |
| 176 | |
| 177 | func (r *Reader) ReadBytesWithLength(prefix string, withPerfix bool) []byte { |
| 178 | var length int |
| 179 | switch prefix { |
| 180 | case "u8": |
| 181 | length = int(r.ReadU8()) |
| 182 | case "u16": |
| 183 | length = int(r.ReadU16()) |
| 184 | case "u32": |
| 185 | length = int(r.ReadU32()) |
| 186 | case "u64": |
| 187 | length = int(r.ReadU64()) |
| 188 | default: |
| 189 | panic("invaild prefix") |
| 190 | } |
| 191 | if withPerfix { |
| 192 | plus, err := strconv.Atoi(prefix[1:]) |
| 193 | if err != nil { |
| 194 | panic(err) |
| 195 | } |
| 196 | length -= plus / 8 |
| 197 | } |
| 198 | return r.ReadBytes(length) |
| 199 | } |
| 200 | |
| 201 | func (r *Reader) ReadStringWithLength(prefix string, withPerfix bool) string { |
| 202 | return utils.B2S(r.ReadBytesWithLength(prefix, withPerfix)) |
no test coverage detected