Home / Function/ safeDirectWriteUtf8() — netty Function Reference

safeDirectWriteUtf8() — netty Function Reference

Architecture documentation for the safeDirectWriteUtf8() function in ByteBufUtil.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  21c07711_ebaa_7ef8_dfc5_a30f45f8be31["safeDirectWriteUtf8()"]
  920454f6_25f6_4a9b_3d32_9684c3e11f6c["ByteBufUtil"]
  21c07711_ebaa_7ef8_dfc5_a30f45f8be31 -->|defined in| 920454f6_25f6_4a9b_3d32_9684c3e11f6c
  1179b53a_e196_1505_4b75_0d4181586259["writeUtf8()"]
  1179b53a_e196_1505_4b75_0d4181586259 -->|calls| 21c07711_ebaa_7ef8_dfc5_a30f45f8be31
  style 21c07711_ebaa_7ef8_dfc5_a30f45f8be31 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

buffer/src/main/java/io/netty/buffer/ByteBufUtil.java lines 958–1002

    private static int safeDirectWriteUtf8(ByteBuffer 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.put(writerIndex++, (byte) c);
            } else if (c < 0x800) {
                buffer.put(writerIndex++, (byte) (0xc0 | (c >> 6)));
                buffer.put(writerIndex++, (byte) (0x80 | (c & 0x3f)));
            } else if (isSurrogate(c)) {
                if (!Character.isHighSurrogate(c)) {
                    buffer.put(writerIndex++, WRITE_UTF_UNKNOWN);
                    continue;
                }
                // Surrogate Pair consumes 2 characters.
                if (++i == end) {
                    buffer.put(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.put(writerIndex++, WRITE_UTF_UNKNOWN);
                    buffer.put(writerIndex++, Character.isHighSurrogate(c2)? WRITE_UTF_UNKNOWN : (byte) c2);
                } else {
                    int codePoint = Character.toCodePoint(c, c2);
                    // See https://www.unicode.org/versions/Unicode7.0.0/ch03.pdf#G2630.
                    buffer.put(writerIndex++, (byte) (0xf0 | (codePoint >> 18)));
                    buffer.put(writerIndex++, (byte) (0x80 | ((codePoint >> 12) & 0x3f)));
                    buffer.put(writerIndex++, (byte) (0x80 | ((codePoint >> 6) & 0x3f)));
                    buffer.put(writerIndex++, (byte) (0x80 | (codePoint & 0x3f)));
                }
            } else {
                buffer.put(writerIndex++, (byte) (0xe0 | (c >> 12)));
                buffer.put(writerIndex++, (byte) (0x80 | ((c >> 6) & 0x3f)));
                buffer.put(writerIndex++, (byte) (0x80 | (c & 0x3f)));
            }
        }
        return writerIndex - oldWriterIndex;
    }

Domain

Subdomains

Called By

Frequently Asked Questions

What does safeDirectWriteUtf8() do?
safeDirectWriteUtf8() is a function in the netty codebase, defined in buffer/src/main/java/io/netty/buffer/ByteBufUtil.java.
Where is safeDirectWriteUtf8() defined?
safeDirectWriteUtf8() is defined in buffer/src/main/java/io/netty/buffer/ByteBufUtil.java at line 958.
What calls safeDirectWriteUtf8()?
safeDirectWriteUtf8() 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