text: #ifndef STEALIFY_ENCODE_H
  #define STEALIFY_ENCODE_H
  
  #include <stealify.h>
  
  namespace stealify {
  
  namespace encode {
  
  const int8_t unbase64_table[256] =
    { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, -2, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63,
      52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
      -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
      15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63,
      -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
      41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
    };
  
  
  const int8_t unhex_table[256] =
    { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
       0,  1,  2,  3,  4,  5,  6,  7,  8,  9, -1, -1, -1, -1, -1, -1,
      -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
    };
  
  inline unsigned unhex(uint8_t x) {
    return unhex_table[x];
  }
  
  size_t hex_decode(char* buf,
                           size_t len,
                           const char* src,
                           const size_t srcLen);
  
  inline size_t hex_encode(const char* src, size_t slen, char* dst, size_t dlen) {
    // We know how much we'll write, stealify make sure that there's space.
    dlen = slen * 2;
    for (uint32_t i = 0, k = 0; k < dlen; i += 1, k += 2) {
      static const char hex[] = "0123456789abcdef";
      uint8_t val = static_cast<uint8_t>(src[i]);
      dst[k + 0] = hex[val >> 4];
      dst[k + 1] = hex[val & 15];
    }
  
    return dlen;
  }
  
  inline int8_t unbase64(uint8_t x) {
    return unbase64_table[x];
  }
  
  inline constexpr size_t base64_encoded_size(size_t size) {
    return ((size + 2 - ((size + 2) % 3)) / 3 * 4);
  }
  
  // Doesn't check for padding at the end.  Can be 1-2 bytes over.
  inline size_t base64_decoded_size_fast(size_t size) {
    size_t remainder = size % 4;
  
    size = (size / 4) * 3;
    if (remainder) {
      if (size == 0 && remainder == 1) {
        // special case: 1-byte input cannot be decoded
        size = 0;
      } else {
        // non-padded input, add 1 or 2 extra bytes
        size += 1 + (remainder == 3);
      }
    }
  
    return size;
  }
  
  size_t base64_decoded_size(const char* src, size_t size);
  bool base64_decode_group_slow(char* dst, const size_t dstlen,
                                const char* src, const size_t srclen,
                                size_t* const i, size_t* const k);
  size_t base64_decode_fast(char* dst, const size_t dstlen,
                            const char* src, const size_t srclen,
                            const size_t decoded_size);
  size_t base64_decode(char* dst, const size_t dstlen,
                       const char* src, const size_t srclen);
  size_t base64_encode(const char* src,
                              size_t slen,
                              char* dst,
                              size_t dlen);
  void HexEncode(const FunctionCallbackInfo<Value> &args);
  void Base64Encode(const FunctionCallbackInfo<Value> &args);
  void Init(Isolate* isolate, Local<ObjectTemplate> target);
  
  }
  
  }
  
  extern "C" {
  	void* _register_encode() {
  		return (void*)stealify::encode::Init;
  	}
  }
  
  #endif
  