Skip to content

Commit

Permalink
fix: 适配中文
Browse files Browse the repository at this point in the history
  • Loading branch information
styluo committed Oct 8, 2021
1 parent 7af7fa7 commit 31e41ff
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,14 @@ public void putString(ByteBuffer byteBuffer, @Nullable String value) throws Ille
if (value == null) {
value = "";
}
if (value.length() > (MAX_SIZE - (mValuePosition - mPosition))) {
byte[] valueBytes = value.getBytes();
short valueLength = valueBytes == null ? 0 : ((short) valueBytes.length);
if (valueLength > (MAX_SIZE - (mValuePosition - mPosition))) {
throw new IllegalArgumentException("value is too long, value.length() = " + value.length());
}
byteBuffer.putShort((short) value.length());
if (value.length() > 0) {
byteBuffer.put(value.getBytes());
byteBuffer.putShort(valueLength);
if (valueLength > 0) {
byteBuffer.put(valueBytes);
}
}

Expand Down

0 comments on commit 31e41ff

Please sign in to comment.