readString reads a string from buffer using xlang encoding
(buf *ByteBuffer, err *Error)
| 50 | |
| 51 | // readString reads a string from buffer using xlang encoding |
| 52 | func readString(buf *ByteBuffer, err *Error) string { |
| 53 | header := buf.ReadVaruint36Small(err) |
| 54 | size := header >> 2 // Extract byte count |
| 55 | encoding := header & 0b11 // Extract encoding type |
| 56 | if intSize == 32 && size > uint64(MaxInt) { |
| 57 | err.SetError(fmt.Errorf("string byte count %d exceeds supported int range", size)) |
| 58 | return "" |
| 59 | } |
| 60 | |
| 61 | switch encoding { |
| 62 | case encodingLatin1: |
| 63 | return readLatin1(buf, int(size), err) |
| 64 | case encodingUTF16LE: |
| 65 | // For UTF16LE, size is byte count, need to convert to char count |
| 66 | return readUTF16LE(buf, int(size), err) |
| 67 | case encodingUTF8: |
| 68 | return readUTF8(buf, int(size), err) |
| 69 | default: |
| 70 | err.SetError(fmt.Errorf("invalid string encoding: %d", encoding)) |
| 71 | return "" |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | // Specific encoding read methods |
| 76 | func readLatin1(buf *ByteBuffer, size int, err *Error) string { |
no test coverage detected