| 88 | } |
| 89 | |
| 90 | func readUTF16LE(buf *ByteBuffer, byteCount int, err *Error) string { |
| 91 | if byteCount&1 != 0 { |
| 92 | err.SetError(InvalidUTF16StringError(byteCount)) |
| 93 | return "" |
| 94 | } |
| 95 | |
| 96 | data := buf.ReadBinary(byteCount, err) |
| 97 | if err.HasError() { |
| 98 | return "" |
| 99 | } |
| 100 | |
| 101 | // Reconstruct UTF-16 code units |
| 102 | charCount := byteCount / 2 |
| 103 | u16s := make([]uint16, charCount) |
| 104 | for i := 0; i < byteCount; i += 2 { |
| 105 | u16s[i/2] = uint16(data[i]) | uint16(data[i+1])<<8 |
| 106 | } |
| 107 | |
| 108 | return string(utf16.Decode(u16s)) |
| 109 | } |
| 110 | |
| 111 | func readUTF8(buf *ByteBuffer, size int, err *Error) string { |
| 112 | data := buf.ReadBinary(size, err) |