Page MenuHomePhabricator

[native][utils-module] Implement base64 encode
ClosedPublic

Authored by bartek on Apr 18 2023, 8:12 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 15, 5:39 PM
Unknown Object (File)
Fri, Nov 8, 3:38 AM
Unknown Object (File)
Tue, Nov 5, 4:32 AM
Unknown Object (File)
Tue, Nov 5, 4:32 AM
Unknown Object (File)
Tue, Nov 5, 4:32 AM
Unknown Object (File)
Tue, Nov 5, 4:32 AM
Unknown Object (File)
Oct 31 2024, 12:05 PM
Unknown Object (File)
Oct 6 2024, 3:45 PM
Subscribers

Details

Summary

Part of ENG-3408.This one implements base64 encode, which replaces the slow JS implementation.

This implementation is inspired by this article but it is somehow modified (original article impl requires C++20).

Depends on D7485

Test Plan

Called this from JS for various cases and compared it with online converter. Results are equal for each padding value (0, 1, 2).

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

bartek held this revision as a draft.
bartek published this revision for review.Apr 18 2023, 8:36 AM
kamil added inline comments.
native/cpp/CommonCpp/NativeModules/CommUtilsModule.cpp
102

just wondering, is there a reason for this to be synchronous instead of promise?

native/cpp/CommonCpp/Tools/Base64.cpp
6

I prefer the original name from article, I think alphabet is confusing as this name stands for standardized set of letter, not special characters like '+', '/'

15–18

can you make 63 a constant with some meaningful name to improve readability? SIX_BIT_MASK or something

native/cpp/CommonCpp/Tools/Base64.h
1

you should add #pragma once, docs

4

I think creating a class with a static method will be more readable and will match the pattern from the rest of the cpp codebase. Don't you think?

This revision is now accepted and ready to land.Apr 20 2023, 1:30 AM
native/cpp/CommonCpp/NativeModules/CommUtilsModule.cpp
102

Yes, this is to keep compatibility with our JS impl as well as other solutions like base64-js. I looked into many RN/JS base64 implementations and all of them are synchronous, the same way as JSON.stringify() is sync.

native/cpp/CommonCpp/Tools/Base64.cpp
6

As you wish

15–18

Sure

native/cpp/CommonCpp/Tools/Base64.h
4

I'd prefer not to introduce classes if unnecessary. But I'm not opposed to namespaces

native/cpp/CommonCpp/Tools/Base64.h
4

Never mind, I see this pattern is indeed everywhere else in our codebase. Not very happy about it but will follow it; I don't want to introduce inconsistencies

Apply review feedback. Rebase before landing

native/cpp/CommonCpp/NativeModules/CommUtilsModule.cpp
102

right, thanks for explanation!