-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix:go emoji to java emoji(a character takes up 3-4 bytes of special symbols) #129
Comments
@pantianying pls provide a unit test so that we can follow up |
|
ps:
|
@pantianying I find that java uses two 16-bit characters to represent emoji "🤣", while golang uses one rune to represent it. So the length of the emoji in java is 2, while 1 in golang. The hessian protocol says that:
So, it's a bug of golang hessian2, I will try to fix it. |
New knowledge:
/**
* Prints a string to the stream, encoded as UTF-8
*
* @param v the string to print.
*/
public void printString(char []v, int strOffset, int length)
throws IOException
{
int offset = _offset;
byte []buffer = _buffer;
for (int i = 0; i < length; i++) {
if (SIZE <= offset + 16) {
_offset = offset;
flushBuffer();
offset = _offset;
}
char ch = v[i + strOffset];
if (ch < 0x80)
buffer[offset++] = (byte) (ch);
else if (ch < 0x800) {
buffer[offset++] = (byte) (0xc0 + ((ch >> 6) & 0x1f));
buffer[offset++] = (byte) (0x80 + (ch & 0x3f));
}
else {
buffer[offset++] = (byte) (0xe0 + ((ch >> 12) & 0xf));
buffer[offset++] = (byte) (0x80 + ((ch >> 6) & 0x3f));
buffer[offset++] = (byte) (0x80 + (ch & 0x3f));
}
}
_offset = offset;
}
private int parseUTF8Char()
throws IOException
{
int ch = _offset < _length ? (_buffer[_offset++] & 0xff) : read();
if (ch < 0x80)
return ch;
else if ((ch & 0xe0) == 0xc0) {
int ch1 = read();
int v = ((ch & 0x1f) << 6) + (ch1 & 0x3f);
return v;
}
else if ((ch & 0xf0) == 0xe0) {
int ch1 = read();
int ch2 = read();
int v = ((ch & 0x0f) << 12) + ((ch1 & 0x3f) << 6) + (ch2 & 0x3f);
return v;
}
else
throw error("bad utf-8 encoding at " + codeName(ch));
} |
java only support ucs-2, while golang support ucs-4. |
i'm working on it, and it may be resolved as early as tomorrow. |
What would you like to be added:
Why is this needed:
The text was updated successfully, but these errors were encountered: