Home / Function/ unsafeWriteUtf8() — netty Function Reference

unsafeWriteUtf8() — netty Function Reference

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

Function java Buffer Search called by 1

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

buffer/src/main/java/io/netty/buffer/ByteBufUtil.java lines 1095–1139

    private static int unsafeWriteUtf8(byte[] buffer, long memoryOffset, int writerIndex,
                                       CharSequence seq, int start, int end) {
        assert !(seq instanceof AsciiString);
        long writerOffset = memoryOffset + writerIndex;
        final long oldWriterOffset = writerOffset;
        for (int i = start; i < end; i++) {
            char c = seq.charAt(i);
            if (c < 0x80) {
                PlatformDependent.putByte(buffer, writerOffset++, (byte) c);
            } else if (c < 0x800) {
                PlatformDependent.putByte(buffer, writerOffset++, (byte) (0xc0 | (c >> 6)));
                PlatformDependent.putByte(buffer, writerOffset++, (byte) (0x80 | (c & 0x3f)));
            } else if (isSurrogate(c)) {
                if (!Character.isHighSurrogate(c)) {
                    PlatformDependent.putByte(buffer, writerOffset++, WRITE_UTF_UNKNOWN);
                    continue;
                }
                // Surrogate Pair consumes 2 characters.
                if (++i == end) {
                    PlatformDependent.putByte(buffer, writerOffset++, WRITE_UTF_UNKNOWN);
                    break;
                }
                char c2 = seq.charAt(i);
                // Extra method is copied here to NOT allow inlining of writeUtf8
                // and increase the chance to inline CharSequence::charAt instead
                if (!Character.isLowSurrogate(c2)) {
                    PlatformDependent.putByte(buffer, writerOffset++, WRITE_UTF_UNKNOWN);
                    PlatformDependent.putByte(buffer, writerOffset++,
                                              (byte) (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.
                    PlatformDependent.putByte(buffer, writerOffset++, (byte) (0xf0 | (codePoint >> 18)));
                    PlatformDependent.putByte(buffer, writerOffset++, (byte) (0x80 | ((codePoint >> 12) & 0x3f)));
                    PlatformDependent.putByte(buffer, writerOffset++, (byte) (0x80 | ((codePoint >> 6) & 0x3f)));
                    PlatformDependent.putByte(buffer, writerOffset++, (byte) (0x80 | (codePoint & 0x3f)));
                }
            } else {
                PlatformDependent.putByte(buffer, writerOffset++, (byte) (0xe0 | (c >> 12)));
                PlatformDependent.putByte(buffer, writerOffset++, (byte) (0x80 | ((c >> 6) & 0x3f)));
                PlatformDependent.putByte(buffer, writerOffset++, (byte) (0x80 | (c & 0x3f)));
            }
        }
        return (int) (writerOffset - oldWriterOffset);
    }

Domain

Subdomains

Called By

Frequently Asked Questions

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