-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Update Base64 as non-throwing API #11149
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for meta-velox canceled.
|
f3e0450
to
4b0ca32
Compare
@majetideepak Can you please review the changes? |
Thanks @Joe-Abraham , based on brief glance, it seems its mostly renaming variables etc for readability and consistency (which is welcome change); Want to make sure I am not missing any material change. |
@kgpai I have also made the APIs used in BinaryFunctions.h as non-throwing. |
@Joe-Abraham this should be its own PR since its a functional change. We can leave the remaining code improvements this PR. |
c421830
to
62510fb
Compare
velox/common/encode/Base64.h
Outdated
@@ -139,7 +143,8 @@ class Base64 { | |||
// character. | |||
static uint8_t base64ReverseLookup( | |||
char encodedChar, | |||
const ReverseIndex& reverseIndex); | |||
const ReverseIndex& reverseIndex, | |||
Status& status); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Status should always be the return type. The return value is not valid if Status is not OK. You can combine Status with a return value using folly::Expected.
See #7589
Here I think you can return uint8_t
as a return argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the code in a similar way.
velox/common/encode/Base64.cpp
Outdated
if (reverseLookupValue >= 0x40) { | ||
VELOX_USER_FAIL("decode() - invalid input string: invalid characters"); | ||
status = Status::UserError( | ||
"decode() - invalid input string: invalid characters"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably print the invalid character here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the code and added the testcases as well.
velox/common/encode/Base64.cpp
Outdated
outputBuffer[0] = (decodedBlock >> 16) & 0xff; | ||
outputBuffer[1] = (decodedBlock >> 8) & 0xff; | ||
outputBuffer[2] = decodedBlock & 0xff; | ||
(base64ReverseLookup(input[0], reverseIndex, lookupStatus) << 18) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can may-be directly pass outputBuffer[i]
to store the return value for each call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the code.
velox/common/encode/Base64.cpp
Outdated
@@ -163,10 +161,10 @@ std::string Base64::encodeImpl( | |||
const T& input, | |||
const Charset& charset, | |||
bool includePadding) { | |||
size_t encodedSize = calculateEncodedSize(input.size(), includePadding); | |||
const size_t encodedSize{calculateEncodedSize(input.size(), includePadding)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const is not meaningful for scalar values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated the code
velox/common/encode/Base64.cpp
Outdated
} | ||
|
||
// static | ||
template <class T> | ||
void Base64::encodeImpl( | ||
Status Base64::encodeImpl( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does encodeImpl throw? If not why use Status?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
base64ReverseLookup
call is being made from encodeImpl
, Can you have a look into the updated code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't base64ReverseLookup
being called from decodeImpl
?
I don't see any function call being made inside encodeImpl
.
80aefc1
to
c940434
Compare
439959f
to
47d0c0d
Compare
@@ -163,10 +161,10 @@ std::string Base64::encodeImpl( | |||
const T& input, | |||
const Charset& charset, | |||
bool includePadding) { | |||
size_t encodedSize = calculateEncodedSize(input.size(), includePadding); | |||
size_t encodedSize{calculateEncodedSize(input.size(), includePadding)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change?
velox/common/encode/Base64.cpp
Outdated
} | ||
|
||
// static | ||
template <class T> | ||
void Base64::encodeImpl( | ||
Status Base64::encodeImpl( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't base64ReverseLookup
being called from decodeImpl
?
I don't see any function call being made inside encodeImpl
.
velox/common/encode/Base64.cpp
Outdated
@@ -320,29 +322,36 @@ void Base64::decode( | |||
const std::pair<const char*, int32_t>& payload, | |||
std::string& decodedOutput) { | |||
size_t inputSize = payload.second; | |||
decodedOutput.resize(calculateDecodedSize(payload.first, inputSize)); | |||
decode(payload.first, inputSize, decodedOutput.data(), decodedOutput.size()); | |||
size_t decodedSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initialize the variable to 0.
decodedOutput.resize(calculateDecodedSize(payload.first, inputSize)); | ||
decode(payload.first, inputSize, decodedOutput.data(), decodedOutput.size()); | ||
size_t decodedSize; | ||
(void)calculateDecodedSize(payload.first, inputSize, decodedSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the return Status from calculateDecodedSize ignored here?
Follow-up PR: #10371
The following changes are done in this PR.
Changing the
char
tostd::string_view
andstd::string
will be done in subsequent PR.