ipfs-chromium
multi_base.h
1 #ifndef IPFS_MB_PREFIXES_H_
2 #define IPFS_MB_PREFIXES_H_
3 
4 #include <vocab/byte_view.h>
5 
6 #include <optional>
7 #include <string>
8 #include <string_view>
9 #include <vector>
10 
11 namespace ipfs::mb {
12 
13 // https://github.com/multiformats/multibase/blob/master/multibase.csv
14 enum class Code : char {
15  IDENTITY = '\0',
16  UNSUPPORTED = '1',
17  BASE16_LOWER = 'f',
18  BASE16_UPPER = 'F',
19  BASE32_LOWER = 'b',
20  BASE32_UPPER = 'B',
21  BASE36_LOWER = 'k',
22  BASE36_UPPER = 'K',
23  BASE58_BTC = 'z',
24  BASE64 = 'm'
25 };
26 Code CodeFromPrefix(char c);
27 std::string_view GetName(Code);
28 
29 using Decoder = std::vector<Byte> (*)(std::string_view);
30 using Encoder = std::string (*)(ByteView);
34 struct Codec {
37  Decoder const decode;
40  Encoder const encode;
44  std::string_view const name;
48  static Codec const* Get(Code code);
49 };
50 
51 std::string encode(Code, ByteView);
52 std::optional<std::vector<Byte>> decode(std::string_view mb_str);
53 } // namespace ipfs::mb
54 
55 #endif // IPFS_MB_PREFIXES_H_
Definition: multi_base.h:34
Encoder const encode
Definition: multi_base.h:40
static Codec const * Get(Code code)
Definition: multi_base.cc:63
std::string_view const name
Definition: multi_base.h:44
Decoder const decode
Definition: multi_base.h:37