JSON_Base64.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #ifndef LIBJSON_GUARD_BASE64_H
  2. #define LIBJSON_GUARD_BASE64_H
  3. #include "JSONDebug.h"
  4. #if defined(JSON_BINARY) || defined(JSON_EXPOSE_BASE64) //if this is not needed, don't waste space compiling it
  5. #include "../Dependencies/libbase64++/libbase64++.h"
  6. class JSONBase64 {
  7. public:
  8. inline static json_string json_encode64(const unsigned char * binary, size_t bytes) json_nothrow json_cold;
  9. inline static std::string json_decode64(const json_string & encoded) json_nothrow json_cold;
  10. private:
  11. JSONBase64(void);
  12. };
  13. json_string JSONBase64::json_encode64(const unsigned char * binary, size_t bytes) json_nothrow {
  14. #if defined JSON_DEBUG || defined JSON_SAFE
  15. return libbase64::encode<json_string, json_char, json_uchar, true>(binary, bytes);
  16. #else
  17. return libbase64::encode<json_string, json_char, json_uchar, false>(binary, bytes);
  18. #endif
  19. }
  20. std::string JSONBase64::json_decode64(const json_string & encoded) json_nothrow {
  21. #if defined JSON_DEBUG || defined JSON_SAFE
  22. return libbase64::decode<json_string, json_char, json_uchar, true>(encoded);
  23. #else
  24. return libbase64::decode<json_string, json_char, json_uchar, false>(encoded);
  25. #endif
  26. }
  27. #endif
  28. #endif