1- /* Decode-fn helpers (numerics, strings, identifiers, encodings, bitfields). */
1+ /* Decode-fn helpers (numerics, strings, identifiers, encodings, bitfields).
2+ *
3+ * Uniform signature: every helper accepts (value, args_json). Args-free
4+ * helpers ignore the second arg. Matches the Rust runtime's pattern.
5+ */
26
37#include "ads_helpers.h"
48#include <cjson/cJSON.h>
@@ -19,11 +23,7 @@ static char *substr_copy(const char *s, size_t start, size_t len) {
1923 return out ;
2024}
2125
22- ads_value_t * ads_decode_integer (const char * value ) {
23- return ads_value_from_int (value ? atoll (value ) : 0 );
24- }
25-
26- ads_value_t * ads_decode_integer_args (const char * value , const char * args_json ) {
26+ ads_value_t * ads_decode_integer (const char * value , const char * args_json ) {
2727 cJSON * args = args_json ? cJSON_Parse (args_json ) : NULL ;
2828 size_t start = 0 ;
2929 long len = -1 ;
@@ -37,17 +37,31 @@ ads_value_t *ads_decode_integer_args(const char *value, const char *args_json) {
3737 if (cJSON_IsNumber (m )) mult = m -> valuedouble ;
3838 }
3939 cJSON_Delete (args );
40+ if (!value ) return ads_value_from_double (0.0 );
4041 char * s = len >= 0 ? substr_copy (value , start , (size_t )len )
4142 : substr_copy (value , start , strlen (value ));
4243 double n = atof (s ) * mult ;
4344 free (s );
4445 return ads_value_from_double (n );
4546}
4647
47- ads_value_t * ads_decode_float (const char * value ) { return ads_value_from_double (value ? atof (value ) : 0.0 ); }
48- ads_value_t * ads_decode_string (const char * value ) { return ads_value_from_string (value ? value : "" ); }
49- ads_value_t * ads_decode_callsign (const char * value ) { return ads_decode_string (value ); }
50- ads_value_t * ads_decode_flight_number (const char * v ) { return ads_decode_string (v ); }
48+ ads_value_t * ads_decode_float (const char * value , const char * args_json ) {
49+ (void )args_json ;
50+ return ads_value_from_double (value ? atof (value ) : 0.0 );
51+ }
52+
53+ ads_value_t * ads_decode_string (const char * value , const char * args_json ) {
54+ (void )args_json ;
55+ return ads_value_from_string (value ? value : "" );
56+ }
57+
58+ ads_value_t * ads_decode_callsign (const char * value , const char * args_json ) {
59+ return ads_decode_string (value , args_json );
60+ }
61+
62+ ads_value_t * ads_decode_flight_number (const char * value , const char * args_json ) {
63+ return ads_decode_string (value , args_json );
64+ }
5165
5266static char * trim_inplace (char * s ) {
5367 char * start = s ;
@@ -58,31 +72,35 @@ static char *trim_inplace(char *s) {
5872 return s ;
5973}
6074
61- ads_value_t * ads_decode_trim (const char * value ) {
75+ ads_value_t * ads_decode_trim (const char * value , const char * args_json ) {
76+ (void )args_json ;
6277 char * copy = strdup (value ? value : "" );
6378 trim_inplace (copy );
6479 ads_value_t * v = ads_value_from_string (copy );
6580 free (copy );
6681 return v ;
6782}
6883
69- ads_value_t * ads_decode_uppercase (const char * value ) {
84+ ads_value_t * ads_decode_uppercase (const char * value , const char * args_json ) {
85+ (void )args_json ;
7086 char * copy = strdup (value ? value : "" );
7187 for (char * p = copy ; * p ; p ++ ) * p = (char )toupper ((unsigned char )* p );
7288 ads_value_t * v = ads_value_from_string (copy );
7389 free (copy );
7490 return v ;
7591}
7692
77- ads_value_t * ads_decode_lowercase (const char * value ) {
93+ ads_value_t * ads_decode_lowercase (const char * value , const char * args_json ) {
94+ (void )args_json ;
7895 char * copy = strdup (value ? value : "" );
7996 for (char * p = copy ; * p ; p ++ ) * p = (char )tolower ((unsigned char )* p );
8097 ads_value_t * v = ads_value_from_string (copy );
8198 free (copy );
8299 return v ;
83100}
84101
85- ads_value_t * ads_decode_airport (const char * value ) {
102+ ads_value_t * ads_decode_airport (const char * value , const char * args_json ) {
103+ (void )args_json ;
86104 char * copy = strdup (value ? value : "" );
87105 trim_inplace (copy );
88106 for (char * p = copy ; * p ; p ++ ) * p = (char )toupper ((unsigned char )* p );
@@ -121,20 +139,16 @@ static int64_t hhmmss_to_tod(const char *s) {
121139 return (int64_t )h * 3600 + (int64_t )m * 60 + sec ;
122140}
123141
124- ads_value_t * ads_decode_timestamp_hhmmss (const char * value ) {
125- return ads_value_from_int (hhmmss_to_tod (value ));
126- }
127-
128- ads_value_t * ads_decode_timestamp_hhmmss_args (const char * value , const char * args_json ) {
142+ ads_value_t * ads_decode_timestamp_hhmmss (const char * value , const char * args_json ) {
129143 cJSON * args = args_json ? cJSON_Parse (args_json ) : NULL ;
130144 const cJSON * app = args ? cJSON_GetObjectItemCaseSensitive (args , "append" ) : NULL ;
131145 char * combined ;
132146 if (app && cJSON_IsString (app )) {
133- size_t n = strlen (value ) + strlen (app -> valuestring ) + 1 ;
147+ size_t n = strlen (value ? value : "" ) + strlen (app -> valuestring ) + 1 ;
134148 combined = malloc (n );
135- snprintf (combined , n , "%s%s" , value , app -> valuestring );
149+ snprintf (combined , n , "%s%s" , value ? value : "" , app -> valuestring );
136150 } else {
137- combined = strdup (value );
151+ combined = strdup (value ? value : "" );
138152 }
139153 cJSON_Delete (args );
140154 int64_t tod = hhmmss_to_tod (combined );
0 commit comments