Skip to content
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

Extract base64 encoding/decoding code into headers #6910

Closed
wants to merge 1 commit into from
Closed

Extract base64 encoding/decoding code into headers #6910

wants to merge 1 commit into from

Conversation

eugeneo
Copy link
Contributor

@eugeneo eugeneo commented May 21, 2016

This is related to PR #6792

For our protocol, we need Base64 encoder. It already exists in string_bytes.cc so I simply extracted it to the header. For symmetry, I also extracted decoder.

@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label May 21, 2016
@mscdex
Copy link
Contributor

mscdex commented May 21, 2016

/cc @nodejs/ctc Is this an API we want to support? I'm leaning towards -1 but more like -0.5 I guess....

EDIT: Thinking about this more I move my vote to -1 ;-)

@indutny
Copy link
Member

indutny commented May 21, 2016

-1 from me as well, this is an implementation detail, not an API.

@ofrobots
Copy link
Contributor

This looks like a refactoring of code so base64 could be used in other parts of Node core. This is not a new API. Did I miss something?

@ofrobots
Copy link
Contributor

@eugeneo The commit message should be formatted according to the commit guidelines: https://github.com/nodejs/node/blob/master/CONTRIBUTING.md

@mscdex
Copy link
Contributor

mscdex commented May 21, 2016

@ofrobots This PR moves the code from the existing string_bytes.cc to a new header file which is includable from outside of node, effectively making it a (newly) exposed API.

@ofrobots
Copy link
Contributor

But I could use the same 'API' by including string_bytes.cc from outside of node. It almost sounds like you are saying that if the refactored file was renamed to be base64.c it would be okay? How does one reuse C++ code in core without creating a header file?

@indutny
Copy link
Member

indutny commented May 21, 2016

@ofrobots this doesn't really feat into the concept of API, IMO. Node.js is about JS VM, OS bindings, and the rest. base64 is clearly not something that node offers by itself. While we carry it right now, it doesn't mean that we will do it this way forever, and I don't want to lock us in this kind of API.



// supports regular and URL-safe base64
static const int8_t unbase64_table[] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you leave the table itself in string_bytes.cc? Just drop the static keyword and declare it here. Maybe add [256] so there is no confusion about its size.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@bnoordhuis
Copy link
Member

LGTM with a comment and the same note about the commit log that @ofrobots mentioned.

All: this is moving internal code around for the benefit of #6792. If people are dumb enough to include it in their own code, they get what they deserve. tools/install.py won't install it, FWIW.

@mscdex
Copy link
Contributor

mscdex commented May 21, 2016

I somehow missed the PR link the first time. I rescind my -1 vote.

@eugeneo
Copy link
Contributor Author

eugeneo commented May 23, 2016

I updated the commit message & moved the array. Please take another look.

@bnoordhuis
Copy link
Member

@indutny
Copy link
Member

indutny commented May 23, 2016

If it is not public - should we add something like this to the header?

#ifdef NODE_WANT_INTERNALS
... all code goes here ...
#endif

Sorry, but not LGTM to me yet.

Node already has support for base64 encoding and decoding that is not
visible outside the string_bytes.cc file. Our work on providing a
support for the Chrome inspector protocol
(#6792) requires base64 encoding
support. Rather then introducing a second copy of the base64 encoder,
we suggest moving this code into a separate header.
@eugeneo
Copy link
Contributor Author

eugeneo commented May 23, 2016

@indutny I've added the condition to a header. Please note that it looks like there are no other headers with such directives - e.g. node-internal.h does not have the condition, it is node.h that conditionally includes node-internal.h.

@indutny
Copy link
Member

indutny commented May 23, 2016

@eugeneo thank you! I know that it is not present anywhere else, but if we don't want this header to be used in general user addons, we have to protect it somehow!

@indutny
Copy link
Member

indutny commented May 23, 2016

LGTM

@ofrobots
Copy link
Contributor

ofrobots pushed a commit that referenced this pull request May 23, 2016
Node already has support for base64 encoding and decoding that is not
visible outside the string_bytes.cc file. Our work on providing a
support for the Chrome inspector protocol
(#6792) requires base64 encoding
support. Rather then introducing a second copy of the base64 encoder,
we suggest moving this code into a separate header.

PR-URL: #6910
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: indutny - Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: ofrobots - Ali Ijaz Sheikh <ofrobots@google.com>
@ofrobots
Copy link
Contributor

Landed as 706e699.

@ofrobots ofrobots closed this May 23, 2016
@eugeneo eugeneo deleted the base64 branch May 23, 2016 23:34
@bnoordhuis
Copy link
Member

I'm with @eugeneo that adding the NODE_WANT_INTERNALS guard is incongruent when it's the only header doing that.

@indutny If you think it's a good idea (I don't disagree), then you should come up with a PR that applies it to all the header files we feel are for internal use only.

@bnoordhuis
Copy link
Member

#6948

bnoordhuis added a commit to bnoordhuis/io.js that referenced this pull request May 25, 2016
For consistency with the newly added src/base64.h header, check that
NODE_WANT_INTERNALS is defined and set in internal headers.

PR-URL: nodejs#6948
Refs: nodejs#6910
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Fishrock123 pushed a commit to Fishrock123/node that referenced this pull request May 30, 2016
Node already has support for base64 encoding and decoding that is not
visible outside the string_bytes.cc file. Our work on providing a
support for the Chrome inspector protocol
(nodejs#6792) requires base64 encoding
support. Rather then introducing a second copy of the base64 encoder,
we suggest moving this code into a separate header.

PR-URL: nodejs#6910
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: indutny - Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: ofrobots - Ali Ijaz Sheikh <ofrobots@google.com>
Fishrock123 pushed a commit to Fishrock123/node that referenced this pull request May 30, 2016
For consistency with the newly added src/base64.h header, check that
NODE_WANT_INTERNALS is defined and set in internal headers.

PR-URL: nodejs#6948
Refs: nodejs#6910
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
rvagg pushed a commit that referenced this pull request Jun 2, 2016
Node already has support for base64 encoding and decoding that is not
visible outside the string_bytes.cc file. Our work on providing a
support for the Chrome inspector protocol
(#6792) requires base64 encoding
support. Rather then introducing a second copy of the base64 encoder,
we suggest moving this code into a separate header.

PR-URL: #6910
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: indutny - Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: ofrobots - Ali Ijaz Sheikh <ofrobots@google.com>
rvagg pushed a commit that referenced this pull request Jun 2, 2016
For consistency with the newly added src/base64.h header, check that
NODE_WANT_INTERNALS is defined and set in internal headers.

PR-URL: #6948
Refs: #6910
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
@MylesBorins
Copy link
Contributor

@ofrobots @indutny @bnoordhuis @AndreasMadsen should this be included in #7048?

@bnoordhuis
Copy link
Member

@thealphanerd No, but it should be included if/when the V8 inspector changes are back-ported.

@MylesBorins MylesBorins added inspector Issues and PRs related to the V8 inspector protocol dont-land-on-v4.x and removed lts-watch-v4.x labels Jul 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. inspector Issues and PRs related to the V8 inspector protocol
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants