Skip to content

Commit eb4dc88

Browse files
committed
libutil: fluid: support FLUID_STRING_EMOJI
Problem: Encoding FLUIDs to a string of emoji is not supported. Use the libutil/basemoji implementation to add a FLUID_STRING_EMOJI string type to fluid_string_type_t. Make sure FLUID_STRING_EMOJI is supported with fluid_parse(3).
1 parent 805bc6d commit eb4dc88

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/common/libutil/fluid.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "ccan/str/str.h"
2828
#include "fluid.h"
2929
#include "mnemonic.h"
30+
#include "basemoji.h"
3031

3132
/* fluid: [ts:40 id:14 seq:10] */
3233
static const int bits_per_ts = 40;
@@ -334,6 +335,10 @@ int fluid_encode (char *buf, int bufsz, fluid_t fluid,
334335
if (fluid_f58_encode (buf, bufsz, fluid) < 0)
335336
return -1;
336337
break;
338+
case FLUID_STRING_EMOJI:
339+
if (uint64_basemoji_encode (fluid, buf, bufsz) < 0)
340+
return -1;
341+
break;
337342
}
338343
return 0;
339344
}
@@ -380,6 +385,10 @@ int fluid_decode (const char *s, fluid_t *fluidp, fluid_string_type_t type)
380385
if (fluid_f58_decode (&fluid, s) < 0)
381386
return -1;
382387
break;
388+
case FLUID_STRING_EMOJI:
389+
if (uint64_basemoji_decode (s, &fluid) < 0)
390+
return -1;
391+
break;
383392
default:
384393
errno = EINVAL;
385394
return -1;
@@ -413,6 +422,8 @@ fluid_string_type_t fluid_string_detect_type (const char *s)
413422
return FLUID_STRING_MNEMONIC;
414423
if (fluid_is_f58 (s) > 0)
415424
return FLUID_STRING_F58;
425+
if (is_basemoji_string (s))
426+
return FLUID_STRING_EMOJI;
416427
return 0;
417428
}
418429

src/common/libutil/fluid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ typedef enum {
2323
FLUID_STRING_DOTHEX = 1, // x.x.x.x
2424
FLUID_STRING_MNEMONIC = 2, // mnemonicode x-x-x--x-x-x
2525
FLUID_STRING_F58 = 3, // FLUID base58 enc: ƒXXXX or fXXXX
26+
FLUID_STRING_EMOJI = 4, // FLUID basemoji enc: 😪🏭🐭🍑👨
2627
} fluid_string_type_t;
2728

2829
struct fluid_generator {

0 commit comments

Comments
 (0)