WritePacketBytes prefix must not be empty
(v []byte, prefix string, withPrefix bool)
| 79 | |
| 80 | // WritePacketBytes prefix must not be empty |
| 81 | func (b *Builder) WritePacketBytes(v []byte, prefix string, withPrefix bool) *Builder { |
| 82 | n := len(v) |
| 83 | if withPrefix { |
| 84 | plus, err := strconv.Atoi(prefix[1:]) |
| 85 | if err != nil { |
| 86 | panic(err) |
| 87 | } |
| 88 | n += plus / 8 |
| 89 | } |
| 90 | switch prefix { |
| 91 | case "u8": |
| 92 | b.WriteU8(uint8(n)) |
| 93 | case "u16": |
| 94 | b.WriteU16(uint16(n)) |
| 95 | case "u32": |
| 96 | b.WriteU32(uint32(n)) |
| 97 | case "u64": |
| 98 | b.WriteU64(uint64(n)) |
| 99 | default: |
| 100 | panic("invaild prefix") |
| 101 | } |
| 102 | b.WriteBytes(v) |
| 103 | return b |
| 104 | } |
| 105 | |
| 106 | func (b *Builder) WritePacketString(s, prefix string, withPrefix bool) *Builder { |
| 107 | return b.WritePacketBytes(utils.S2B(s), prefix, withPrefix) |
no test coverage detected