decode4to3() — netty Function Reference
Architecture documentation for the decode4to3() function in Base64.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD ecb75b44_a34c_e912_2204_cd8b6698abcb["decode4to3()"] 28e851bb_9265_53b6_adb0_c9cb3a05d218["Decoder"] ecb75b44_a34c_e912_2204_cd8b6698abcb -->|defined in| 28e851bb_9265_53b6_adb0_c9cb3a05d218 74bdbf8f_873e_a2b1_95c7_3ecf25a01412["ByteBuf()"] 74bdbf8f_873e_a2b1_95c7_3ecf25a01412 -->|calls| ecb75b44_a34c_e912_2204_cd8b6698abcb 4d39ba07_cab0_b244_3cdb_710ee60e1b2d["process()"] 4d39ba07_cab0_b244_3cdb_710ee60e1b2d -->|calls| ecb75b44_a34c_e912_2204_cd8b6698abcb style ecb75b44_a34c_e912_2204_cd8b6698abcb fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-base/src/main/java/io/netty/handler/codec/base64/Base64.java lines 430–500
private static int decode4to3(byte[] src, ByteBuf dest, int destOffset, byte[] decodabet) {
final byte src0 = src[0];
final byte src1 = src[1];
final byte src2 = src[2];
final int decodedValue;
if (src2 == EQUALS_SIGN) {
// Example: Dk==
try {
decodedValue = (decodabet[src0] & 0xff) << 2 | (decodabet[src1] & 0xff) >>> 4;
} catch (IndexOutOfBoundsException ignored) {
throw new IllegalArgumentException("not encoded in Base64");
}
dest.setByte(destOffset, decodedValue);
return 1;
}
final byte src3 = src[3];
if (src3 == EQUALS_SIGN) {
// Example: DkL=
final byte b1 = decodabet[src1];
// Packing bytes into a short to reduce bound and reference count checking.
try {
if (dest.order() == ByteOrder.BIG_ENDIAN) {
// The decodabet bytes are meant to straddle byte boundaries and so we must carefully mask out
// the bits we care about.
decodedValue = ((decodabet[src0] & 0x3f) << 2 | (b1 & 0xf0) >> 4) << 8 |
(b1 & 0xf) << 4 | (decodabet[src2] & 0xfc) >>> 2;
} else {
// This is just a simple byte swap of the operation above.
decodedValue = (decodabet[src0] & 0x3f) << 2 | (b1 & 0xf0) >> 4 |
((b1 & 0xf) << 4 | (decodabet[src2] & 0xfc) >>> 2) << 8;
}
} catch (IndexOutOfBoundsException ignored) {
throw new IllegalArgumentException("not encoded in Base64");
}
dest.setShort(destOffset, decodedValue);
return 2;
}
// Example: DkLE
try {
if (dest.order() == ByteOrder.BIG_ENDIAN) {
decodedValue = (decodabet[src0] & 0x3f) << 18 |
(decodabet[src1] & 0xff) << 12 |
(decodabet[src2] & 0xff) << 6 |
decodabet[src3] & 0xff;
} else {
final byte b1 = decodabet[src1];
final byte b2 = decodabet[src2];
// The goal is to byte swap the BIG_ENDIAN case above. There are 2 interesting things to consider:
// 1. We are byte swapping a 3 byte data type. The left and the right byte switch, but the middle
// remains the same.
// 2. The contents straddles byte boundaries. This means bytes will be pulled apart during the byte
// swapping process.
decodedValue = (decodabet[src0] & 0x3f) << 2 |
// The bottom half of b1 remains in the middle.
(b1 & 0xf) << 12 |
// The top half of b1 are the least significant bits after the swap.
(b1 & 0xf0) >>> 4 |
// The bottom 2 bits of b2 will be the most significant bits after the swap.
(b2 & 0x3) << 22 |
// The remaining 6 bits of b2 remain in the middle.
(b2 & 0xfc) << 6 |
(decodabet[src3] & 0xff) << 16;
}
} catch (IndexOutOfBoundsException ignored) {
throw new IllegalArgumentException("not encoded in Base64");
}
dest.setMedium(destOffset, decodedValue);
return 3;
}
Domain
Subdomains
Source
Frequently Asked Questions
What does decode4to3() do?
decode4to3() is a function in the netty codebase, defined in codec-base/src/main/java/io/netty/handler/codec/base64/Base64.java.
Where is decode4to3() defined?
decode4to3() is defined in codec-base/src/main/java/io/netty/handler/codec/base64/Base64.java at line 430.
What calls decode4to3()?
decode4to3() is called by 2 function(s): ByteBuf, process.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free