Comments (7)
Sadly there isn't any built in function like
int base64_codec_supported(int flags);
but you can indirectly check for codec support by calling base64_decode
with the appropriate flags and build a little helper function on top of that as demonstrated in test/codec_supported.c
. The relevant snippet:
int base64ex_codec_supported(int flags)
{
// Check if given codec is supported by trying to decode a test string:
char a[] = "aGVsbG8=";
char b[10];
size_t outlen;
return (base64_decode(a, sizeof(a)-1, b, &outlen, flags) != -1);
}
use it like so:
if (base64ex_codec_supported(BASE64_FORCE_AVX2))
{
/*...*/
}
from base64.
It is a really good solution, thank you for help.
from base64.
You should probably not be using the FORCE
flags, they're mainly for testing purposes. On x86, the library should auto-detect at runtime the best compiled-in codec for the current platform. That code should do the right thing; if not, please file a bug!
This library is built for performance and portability. The idea is that this library could in principle be distributed in compiled binary form as a Debian package or so. This means that the capabilities of the target machine are unknown at compile time. To be portable but still get the best performance, this library does a number of runtime checks to determine the SIMD support level of the architecture it's running on, and chooses the best available codec, once, at runtime. The checking code (in codec_choose.c
) is built without architecture-specific compiler flags, so that it will run on any generic machine.
So the idea is that you should build with the maximum SIMD level your compiler will support, and rely on runtime feature detection to determine the actual codec that the machine will run. If you don't want to rely on our platform detection, you can bypass it with the FORCE
flags, but then it's on you to do proper fallback on older machines.
To get a list of built-in codecs, @BurningEnlightenment's solution is currently the correct one. You basically request some work from a codec and see if it returns an error. Maybe this should be a proper API call, since the test harness already has a use for this functionality...
from base64.
@aklomp The solution suggested by @BurningEnlightenment seems perfect, but in the end I won't use FORCE flags.
BTW I would suggest to get rid of FORCE flags at all. Instead an extra procedure base64_setup_coded could be available to change codec in runtime. Such procedure could be even enabled by some compile-time definition, as it's intended for tests as you said.
from base64.
So the idea is that you should build with the maximum SIMD level your compiler will support, and rely on runtime feature detection to determine the actual codec that the machine will run.
Is there actually an use case where you would want to exclude one of the codecs? If not I'm tempted to replace the user options in #7 with some detection logic...
from base64.
Well, the basic idea is that you compile for the best case, and fall back to what is available. Sorry if I didn't word this clearly in #7 or the README. (Pull requests welcome :)
You might want to exclude a codec if your compiler does not have proper support for it (e.g. GCC 4.6 miscompiled NEON64), but in that case you could just... not pass in the architecture flags. Also, this library does not do runtime detection on ARM (it's complicated), so on that platform, you do have to choose at compile time.
from base64.
@aklomp OK, thanks for the explanation. Please close the issue.
BTW, your library was included in a pretty big project, it replaced our in-house code.
from base64.
Related Issues (20)
- Decoding data containing <NUL> values HOT 6
- bin/base64: modernize the demo program
- Add a macro to calculate encoded size from raw size and vice versa
- Investigate `gf2p8affineqb` for the shuffle step
- enc: asm: add memory and flags as clobbers
- Integrate with google/oss-fuzz for continuous fuzz testing
- Create release 0.5.1
- Codec detection doesnโt work in test_base64 on musl libc HOT 2
- v0.5.1 breaks `base64 -d` on Alpine Linux (musl libc) HOT 15
- Build of 0.5.1 broken with MinGW HOT 15
- I made a online base64 decoder tool. We can use it HOT 1
- Simplify codepath selection HOT 4
- build failure using mingw32: `error: 'asm' operand has impossible constraints` HOT 4
- CMakeLists: update version to 0.5.2
- bin/base64: add command line options for decoding
- Add `BASE64_FORCE_INLINE` macro to always inline inner loop functions
- Decoding error on Windows (CRLF?) HOT 18
- Codepage error on Windows HOT 2
- Build fails on macOS: `make: objcopy: No such file or directory` HOT 2
- Add installation guide for lib HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from base64.