in library/src/main/java/com/whatsapp/stringpacks/MMappedStringPack.java [27:76]
public MMappedStringPack(
@NonNull List<String> parentLocales, @NonNull MappedByteBuffer mappedPackFile) {
mappedByteBuffer = mappedPackFile;
final int numLocales = read16BitsFrom(0);
final int startOfLocaleData = read32BitsFrom(2);
final byte encodingId = mappedByteBuffer.get(6);
if (encodingId >= StringPackData.ENCODINGS.length) {
SpLog.e("MMappedStringPack: unrecognized encoding");
}
encoding = StringPackData.ENCODINGS[encodingId];
startOfStringData = read32BitsFrom(7);
if (parentLocales.isEmpty()) {
SpLog.e("MMappedStringPack: parentLocales is empty");
return;
}
int caret = StringPackData.HEADER_SIZE;
int numMatches = 0;
final int[] translationLocations = new int[parentLocales.size()];
for (int i = 0; i < numLocales; i++) {
final String resourceLocale = readLocaleFrom(caret);
final int listIndex = parentLocales.indexOf(resourceLocale);
if (listIndex != -1) { // Matching locale found
numMatches++;
translationLocations[listIndex] = caret; // Save the caret position for the match
if (numMatches >= parentLocales.size()) {
// No need to continue. We've already seen the maximum number of matches.
break;
}
}
caret += StringPackData.LOCALE_CODE_SIZE + 4;
}
for (int translationLocation : translationLocations) {
if (translationLocation == 0) {
continue;
}
final int headerStart;
mappedByteBuffer.position(translationLocation + StringPackData.LOCALE_CODE_SIZE);
headerStart = read32BitsFrom(mappedByteBuffer.position());
// We will map the translation location here from less specific to more specific
mapTranslations(startOfLocaleData, headerStart);
}
}