Home / Function/ encodeV2() — netty Function Reference

encodeV2() — netty Function Reference

Architecture documentation for the encodeV2() function in HAProxyMessageEncoder.java from the netty codebase.

Function java Buffer Allocators calls 1 called by 1

Entity Profile

Dependency Diagram

graph TD
  deef989c_de3d_8f0c_8771_ef49cf56d11a["encodeV2()"]
  b42a18dd_ae6a_f2e4_51f0_5f6605567255["HAProxyMessageEncoder"]
  deef989c_de3d_8f0c_8771_ef49cf56d11a -->|defined in| b42a18dd_ae6a_f2e4_51f0_5f6605567255
  a87bc120_6d1a_d0f4_f2a7_ccb9bedf10e5["encode()"]
  a87bc120_6d1a_d0f4_f2a7_ccb9bedf10e5 -->|calls| deef989c_de3d_8f0c_8771_ef49cf56d11a
  c3cfdec7_54a2_8856_e2fc_229fff7a1dc8["encodeTlvs()"]
  deef989c_de3d_8f0c_8771_ef49cf56d11a -->|calls| c3cfdec7_54a2_8856_e2fc_229fff7a1dc8
  style deef989c_de3d_8f0c_8771_ef49cf56d11a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-haproxy/src/main/java/io/netty/handler/codec/haproxy/HAProxyMessageEncoder.java lines 79–111

    private static void encodeV2(HAProxyMessage msg, ByteBuf out) {
        out.writeBytes(BINARY_PREFIX);
        out.writeByte(V2_VERSION_BITMASK | msg.command().byteValue());
        out.writeByte(msg.proxiedProtocol().byteValue());

        switch (msg.proxiedProtocol().addressFamily()) {
            case AF_IPv4:
            case AF_IPv6:
                byte[] srcAddrBytes = NetUtil.createByteArrayFromIpAddressString(msg.sourceAddress());
                byte[] dstAddrBytes = NetUtil.createByteArrayFromIpAddressString(msg.destinationAddress());
                // srcAddrLen + dstAddrLen + 4 (srcPort + dstPort) + numTlvBytes
                out.writeShort(srcAddrBytes.length + dstAddrBytes.length + 4 + msg.tlvNumBytes());
                out.writeBytes(srcAddrBytes);
                out.writeBytes(dstAddrBytes);
                out.writeShort(msg.sourcePort());
                out.writeShort(msg.destinationPort());
                encodeTlvs(msg.tlvs(), out);
                break;
            case AF_UNIX:
                out.writeShort(TOTAL_UNIX_ADDRESS_BYTES_LENGTH + msg.tlvNumBytes());
                int srcAddrBytesWritten = out.writeCharSequence(msg.sourceAddress(), CharsetUtil.US_ASCII);
                out.writeZero(UNIX_ADDRESS_BYTES_LENGTH - srcAddrBytesWritten);
                int dstAddrBytesWritten = out.writeCharSequence(msg.destinationAddress(), CharsetUtil.US_ASCII);
                out.writeZero(UNIX_ADDRESS_BYTES_LENGTH - dstAddrBytesWritten);
                encodeTlvs(msg.tlvs(), out);
                break;
            case AF_UNSPEC:
                out.writeShort(0);
                break;
            default:
                throw new HAProxyProtocolException("unexpected addrFamily");
        }
    }

Domain

Subdomains

Calls

Called By

Frequently Asked Questions

What does encodeV2() do?
encodeV2() is a function in the netty codebase, defined in codec-haproxy/src/main/java/io/netty/handler/codec/haproxy/HAProxyMessageEncoder.java.
Where is encodeV2() defined?
encodeV2() is defined in codec-haproxy/src/main/java/io/netty/handler/codec/haproxy/HAProxyMessageEncoder.java at line 79.
What does encodeV2() call?
encodeV2() calls 1 function(s): encodeTlvs.
What calls encodeV2()?
encodeV2() is called by 1 function(s): encode.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free