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 {
35  Decoder const decode;
36  Encoder const encode;
37  std::string_view const name;
38  static Codec const* Get(Code);
39 };
40 
41 std::string encode(Code, ByteView);
42 std::optional<std::vector<Byte>> decode(std::string_view mb_str);
43 } // namespace ipfs::mb
44 
45 #endif // IPFS_MB_PREFIXES_H_
Definition: multi_base.h:34