diff --git a/src/flamenco/fd_flamenco_base.h b/src/flamenco/fd_flamenco_base.h index 7ac25e499f..ed15cdc65e 100644 --- a/src/flamenco/fd_flamenco_base.h +++ b/src/flamenco/fd_flamenco_base.h @@ -47,6 +47,30 @@ fd_acct_addr_cstr( char cstr[ static FD_BASE58_ENCODED_32_SZ ], return fd_base58_encode_32( addr, NULL, cstr ); } +/* fd_pod utils */ + +FD_FN_UNUSED static fd_pubkey_t * +fd_pod_query_pubkey( uchar const * pod, + char const * path, + fd_pubkey_t * val ) { + + ulong bufsz = 0UL; + void const * buf = fd_pod_query_buf( pod, path, &bufsz ); + + if( FD_UNLIKELY( (!buf) | (bufsz!=sizeof(fd_pubkey_t)) ) ) + return NULL; + + memcpy( val->uc, buf, sizeof(fd_pubkey_t) ); + return val; +} + +static inline ulong +fd_pod_insert_pubkey( uchar * pod, + char const * path, + fd_pubkey_t const * val ) { + return fd_pod_insert_buf( pod, path, val->uc, sizeof(fd_pubkey_t) ); +} + FD_PROTOTYPES_END #endif /* HEADER_fd_src_flamenco_fd_flamenco_base_h */ diff --git a/src/flamenco/types/fd_bincode.h b/src/flamenco/types/fd_bincode.h index 6d58b5c5c6..defb3c0cd7 100644 --- a/src/flamenco/types/fd_bincode.h +++ b/src/flamenco/types/fd_bincode.h @@ -1,7 +1,7 @@ #ifndef HEADER_fd_src_util_encoders_fd_bincode_h #define HEADER_fd_src_util_encoders_fd_bincode_h -#include "../../util/fd_util.h" +#include "../../util/valloc/fd_valloc.h" typedef void (* fd_types_walk_fn_t)( void * self, @@ -20,6 +20,21 @@ struct fd_bincode_encode_ctx { }; typedef struct fd_bincode_encode_ctx fd_bincode_encode_ctx_t; +FD_PROTOTYPES_BEGIN + +static inline fd_bincode_encode_ctx_t +fd_bincode_encode_ctx( void * buf, + ulong sz ) { + return (fd_bincode_encode_ctx_t){ buf, (uchar *)buf + sz }; +} + +FD_FN_PURE static inline ulong +fd_bincode_encode_sz( fd_bincode_encode_ctx_t const * ctx ) { + return (ulong)( (uchar *)ctx->data - (uchar *)ctx->dataend ); +} + +FD_PROTOTYPES_END + /* Context argument used for decoding */ struct fd_bincode_decode_ctx { /* Current position in data buffer */ @@ -76,7 +91,7 @@ typedef struct fd_bincode_destroy_ctx fd_bincode_destroy_ctx_t; uchar * ptr = (uchar *)ctx->data; \ if ( FD_UNLIKELY((void *)(ptr + sizeof(type)) > ctx->dataend ) ) \ return FD_BINCODE_ERR_OVERFLOW; \ - FD_STORE( type, ptr, self ); /* unaligned */ \ + memcpy( ptr, &self, sizeof(type) ); /* unaligned */ \ ctx->data = ptr + sizeof(type); \ return FD_BINCODE_SUCCESS; \ } diff --git a/src/flamenco/types/test_types_meta.c b/src/flamenco/types/test_types_meta.c index afee72d528..3fb6c616e3 100644 --- a/src/flamenco/types/test_types_meta.c +++ b/src/flamenco/types/test_types_meta.c @@ -1,4 +1,5 @@ #include "fd_types_meta.h" +#include "../../util/fd_util.h" int main( int argc, diff --git a/src/util/pod/fd_pod.h b/src/util/pod/fd_pod.h index 37493b4490..dff0aea9f8 100644 --- a/src/util/pod/fd_pod.h +++ b/src/util/pod/fd_pod.h @@ -467,7 +467,7 @@ fd_pod_resize( uchar * pod, is done such that the pod_max is reduced to be equal to pod_used and the pod header is accordingly compacted (otherwise, the pod_max will be unchanged on return). - + Regardless of full, all subpods will be recursively fully compacted and all cstrs in the pod will have had their padding removed (they will be still be '\0' terminated if originally correctly '\0' @@ -508,7 +508,7 @@ fd_pod_val_type_to_cstr( int val_type, bytes), 0 on failure. Failure reasons include NULL pod, NULL path, one of the path prefixes resolved to a non-subpod, path is already in the pod, invalid val_type or no room in pod for val_sz. - + If subpods along the path do not exist, they will be created in the process. @@ -655,7 +655,7 @@ fd_pod_insert_subpod( uchar * FD_RESTRICT pod, static inline ulong fd_pod_insert_buf( uchar * FD_RESTRICT pod, char const * FD_RESTRICT path, - void * FD_RESTRICT val, + void const * FD_RESTRICT val, ulong val_sz ) { return fd_pod_insert( pod, path, FD_POD_VAL_TYPE_BUF, val_sz, val ); }