safeWriteUtf8() — netty Function Reference
Architecture documentation for the safeWriteUtf8() function in ByteBufUtil.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 06b00c3b_df76_8539_d152_b6b1616c5bb8["safeWriteUtf8()"] 920454f6_25f6_4a9b_3d32_9684c3e11f6c["ByteBufUtil"] 06b00c3b_df76_8539_d152_b6b1616c5bb8 -->|defined in| 920454f6_25f6_4a9b_3d32_9684c3e11f6c 1179b53a_e196_1505_4b75_0d4181586259["writeUtf8()"] 1179b53a_e196_1505_4b75_0d4181586259 -->|calls| 06b00c3b_df76_8539_d152_b6b1616c5bb8 style 06b00c3b_df76_8539_d152_b6b1616c5bb8 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
buffer/src/main/java/io/netty/buffer/ByteBufUtil.java lines 1005–1049
private static int safeWriteUtf8(AbstractByteBuf buffer, int writerIndex, CharSequence seq, int start, int end) {
assert !(seq instanceof AsciiString);
int oldWriterIndex = writerIndex;
// We can use the _set methods as these not need to do any index checks and reference checks.
// This is possible as we called ensureWritable(...) before.
for (int i = start; i < end; i++) {
char c = seq.charAt(i);
if (c < 0x80) {
buffer._setByte(writerIndex++, (byte) c);
} else if (c < 0x800) {
buffer._setByte(writerIndex++, (byte) (0xc0 | (c >> 6)));
buffer._setByte(writerIndex++, (byte) (0x80 | (c & 0x3f)));
} else if (isSurrogate(c)) {
if (!Character.isHighSurrogate(c)) {
buffer._setByte(writerIndex++, WRITE_UTF_UNKNOWN);
continue;
}
// Surrogate Pair consumes 2 characters.
if (++i == end) {
buffer._setByte(writerIndex++, WRITE_UTF_UNKNOWN);
break;
}
// Extra method is copied here to NOT allow inlining of writeUtf8
// and increase the chance to inline CharSequence::charAt instead
char c2 = seq.charAt(i);
if (!Character.isLowSurrogate(c2)) {
buffer._setByte(writerIndex++, WRITE_UTF_UNKNOWN);
buffer._setByte(writerIndex++, Character.isHighSurrogate(c2)? WRITE_UTF_UNKNOWN : c2);
} else {
int codePoint = Character.toCodePoint(c, c2);
// See https://www.unicode.org/versions/Unicode7.0.0/ch03.pdf#G2630.
buffer._setByte(writerIndex++, (byte) (0xf0 | (codePoint >> 18)));
buffer._setByte(writerIndex++, (byte) (0x80 | ((codePoint >> 12) & 0x3f)));
buffer._setByte(writerIndex++, (byte) (0x80 | ((codePoint >> 6) & 0x3f)));
buffer._setByte(writerIndex++, (byte) (0x80 | (codePoint & 0x3f)));
}
} else {
buffer._setByte(writerIndex++, (byte) (0xe0 | (c >> 12)));
buffer._setByte(writerIndex++, (byte) (0x80 | ((c >> 6) & 0x3f)));
buffer._setByte(writerIndex++, (byte) (0x80 | (c & 0x3f)));
}
}
return writerIndex - oldWriterIndex;
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does safeWriteUtf8() do?
safeWriteUtf8() is a function in the netty codebase, defined in buffer/src/main/java/io/netty/buffer/ByteBufUtil.java.
Where is safeWriteUtf8() defined?
safeWriteUtf8() is defined in buffer/src/main/java/io/netty/buffer/ByteBufUtil.java at line 1005.
What calls safeWriteUtf8()?
safeWriteUtf8() is called by 1 function(s): writeUtf8.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free