writeString writes a string to buffer using xlang encoding Optimized to combine header and data writes with single grow() call
(buf *ByteBuffer, value string)
| 33 | // writeString writes a string to buffer using xlang encoding |
| 34 | // Optimized to combine header and data writes with single grow() call |
| 35 | func writeString(buf *ByteBuffer, value string) { |
| 36 | data := unsafeGetBytes(value) |
| 37 | dataLen := len(data) |
| 38 | header := (uint64(dataLen) << 2) | encodingUTF8 |
| 39 | |
| 40 | // Reserve space for header (max 5 bytes) + data in one call |
| 41 | buf.Reserve(5 + dataLen) |
| 42 | // Write header inline |
| 43 | buf.WriteVaruint36Small(header) |
| 44 | // Write data inline without grow check |
| 45 | if dataLen > 0 { |
| 46 | copy(buf.data[buf.writerIndex:], data) |
| 47 | buf.writerIndex += dataLen |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | // readString reads a string from buffer using xlang encoding |
| 52 | func readString(buf *ByteBuffer, err *Error) string { |
no test coverage detected