Nyx Node
Loading...
Searching...
No Matches
nyx_node.h
1/* NyxNode
2 * Author: Jérôme ODIER <jerome.odier@lpsc.in2p3.fr>
3 * SPDX-License-Identifier: GPL-2.0-only (Mongoose backend) or GPL-3.0+
4 */
5
6/*--------------------------------------------------------------------------------------------------------------------*/
7
8#ifndef NYX_NODE_H
9#define NYX_NODE_H
10
11/*--------------------------------------------------------------------------------------------------------------------*/
12
13#include <stddef.h>
14#include <stdint.h>
15#include <stdbool.h>
16
17/*--------------------------------------------------------------------------------------------------------------------*/
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23/*--------------------------------------------------------------------------------------------------------------------*/
24
25#if defined(__clang__) && !defined(ARDUINO)
26# pragma clang diagnostic push
27# pragma ide diagnostic ignored "OCUnusedMacroInspection"
28# pragma ide diagnostic ignored "UnreachableCallsOfFunction"
29#endif
30
31/*--------------------------------------------------------------------------------------------------------------------*/
32
33double nan(const char *tag);
34
35/*--------------------------------------------------------------------------------------------------------------------*/
36
37#if !defined(__GNUC__) && !defined(__clang__) && !defined(__attribute__)
38# define __attribute__(x)
39#endif
40
41/*--------------------------------------------------------------------------------------------------------------------*/
42
43#define __NYX_NOTNULL__ \
44 /* do nothing */
45
46#define __NYX_NULLABLE__ \
47 /* do nothing */
48
49#define __NYX_ZEROABLE__ \
50 /* do nothing */
51
52#define __NYX_UNUSED__ \
53 __attribute__ ((unused))
54
55#define __NYX_INLINE__ \
56 __attribute__ ((always_inline)) static inline
57
58/*--------------------------------------------------------------------------------------------------------------------*/
59/* MEMORY */
60/*--------------------------------------------------------------------------------------------------------------------*/
61/** @defgroup MEMORY Memory
62 * Memory primitives with leak detection.
63 * @{
64 */
65/*--------------------------------------------------------------------------------------------------------------------*/
66
67#define buff_t /*-*/ void * //!< Alias for `void *`.
68#define BUFF_t const void * //!< Alias for `const void *`.
69
70#define str_t /*-*/ char * //!< Alias for `char *`.
71#define STR_t const char * //!< Alias for `const char *`.
72
73/*--------------------------------------------------------------------------------------------------------------------*/
74
75#define buffof(p) \
76 ((buff_t *) (p))
77
78/*--------------------------------------------------------------------------------------------------------------------*/
79
80/**
81 * @brief Initializes the memory subsystem.
82 */
83
84void nyx_memory_initialize(void);
85
86/*--------------------------------------------------------------------------------------------------------------------*/
87
88/**
89 * @brief Finalizes the memory subsystem.
90 * @return `true` if there is no memory leak, `false` otherwise.
91 */
92
93bool nyx_memory_finalize(void);
94
95/*--------------------------------------------------------------------------------------------------------------------*/
96
97/**
98 * @brief Similar to libc free except that it returns the amount of memory freed.
99 */
100
101__NYX_ZEROABLE__ size_t nyx_memory_free(
102 __NYX_NULLABLE__ buff_t buff
103);
104
105/*--------------------------------------------------------------------------------------------------------------------*/
106
107/**
108 * @brief Similar to libc malloc except that a memory overflow causes the node to stop.
109 */
110
111__NYX_NULLABLE__ buff_t nyx_memory_alloc(
112 __NYX_ZEROABLE__ size_t size
113);
114
115/*--------------------------------------------------------------------------------------------------------------------*/
116
117/**
118 * @brief Similar to libc realloc except that a memory overflow causes the node to stop.
119 */
120
121__NYX_NULLABLE__ buff_t nyx_memory_realloc(
122 __NYX_NULLABLE__ buff_t buff,
123 __NYX_ZEROABLE__ size_t size
124);
125
126/*--------------------------------------------------------------------------------------------------------------------*/
127
128/**
129 * @brief Similar to libc strdup.
130 */
131
132__NYX_NULLABLE__ str_t nyx_string_dup(
133 __NYX_NULLABLE__ STR_t s
134);
135
136/*--------------------------------------------------------------------------------------------------------------------*/
137
138/**
139 * @brief Similar to libc strndup.
140 */
141
142__NYX_NULLABLE__ str_t nyx_string_ndup(
143 __NYX_NULLABLE__ STR_t s,
144 __NYX_ZEROABLE__ size_t n
145);
146
147/*--------------------------------------------------------------------------------------------------------------------*/
148/* LOGGER */
149/*--------------------------------------------------------------------------------------------------------------------*/
150/** @}
151 * @defgroup LOGGER Logger
152 * Logger.
153 * @{
154 */
155/*--------------------------------------------------------------------------------------------------------------------*/
156
157/**
158 * @brief Nyx log levels.
159 */
160
161typedef enum nyx_log_level_e
162{
163 NYX_LOG_LEVEL_NONE = 100, //!< Logging disabled.
164 NYX_LOG_LEVEL_FATAL = 101, //!< Fatal level.
165 NYX_LOG_LEVEL_ERROR = 102, //!< Error level.
166 NYX_LOG_LEVEL_WARN = 103, //!< Warning level.
167 NYX_LOG_LEVEL_INFO = 104, //!< Log level.
168 NYX_LOG_LEVEL_DEBUG = 105, //!< Debug level.
169 NYX_LOG_LEVEL_TRACE = 106, //!< Trace level.
170
172
173/*--------------------------------------------------------------------------------------------------------------------*/
174
175/**
176 * @brief Sets the log level threshold.
177 * @param level Log level threshold.
178 */
179
181 nyx_log_level_t level
182);
183
184/*--------------------------------------------------------------------------------------------------------------------*/
185
186/**
187 * @private
188 */
189
190void __attribute__((format(printf, 5, 6))) nyx_log(
191 nyx_log_level_t level,
192 STR_t file,
193 STR_t func,
194 int line,
195 STR_t fmt,
196 ...
197);
198
199/*--------------------------------------------------------------------------------------------------------------------*/
200
201/**
202 * @brief Logs a fatal message.
203 * @param fmt Printf-style formatting string.
204 * @param ... Format arguments.
205 * @warning This macro never returns and stops the node.
206 */
207
208#define NYX_LOG_FATAL(fmt, ...) \
209 do { nyx_log(NYX_LOG_LEVEL_FATAL, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); } while(1)
210
211/*--------------------------------------------------------------------------------------------------------------------*/
212
213/**
214 * @brief Logs an error message.
215 * @param fmt Printf-style formatting string.
216 * @param ... Format arguments.
217*/
218
219#define NYX_LOG_ERROR(fmt, ...) \
220 do { nyx_log(NYX_LOG_LEVEL_ERROR, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); } while(0)
221
222/*--------------------------------------------------------------------------------------------------------------------*/
223
224/**
225 * @brief Logs a warning message.
226 * @param fmt Printf-style formatting string.
227 * @param ... Format arguments.
228*/
229
230#define NYX_LOG_WARN(fmt, ...) \
231 do { nyx_log(NYX_LOG_LEVEL_WARN, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); } while(0)
232
233/*--------------------------------------------------------------------------------------------------------------------*/
234
235/**
236 * @brief Logs an info message.
237 * @param fmt Printf-style formatting string.
238 * @param ... Format arguments.
239 */
240
241#define NYX_LOG_INFO(fmt, ...) \
242 do { nyx_log(NYX_LOG_LEVEL_INFO, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); } while(0)
243
244/*--------------------------------------------------------------------------------------------------------------------*/
245
246/**
247 * @brief Logs a debug message.
248 * @param fmt Printf-style formatting string.
249 * @param ... Format arguments.
250 */
251
252#define NYX_LOG_DEBUG(fmt, ...) \
253 do { nyx_log(NYX_LOG_LEVEL_DEBUG, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); } while(0)
254
255/*--------------------------------------------------------------------------------------------------------------------*/
256
257/**
258 * @brief Logs a trace message.
259 * @param fmt Printf-style formatting string.
260 * @param ... Format arguments.
261 */
262
263#define NYX_LOG_TRACE(fmt, ...) \
264 do { nyx_log(NYX_LOG_LEVEL_TRACE, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); } while(0)
265
266/*--------------------------------------------------------------------------------------------------------------------*/
267/* UTILITIES */
268/*--------------------------------------------------------------------------------------------------------------------*/
269/** @}
270 * @defgroup UTILITIES Utilities
271 * Utilities.
272 * @{
273 */
274/*--------------------------------------------------------------------------------------------------------------------*/
275
276/**
277 * @brief Hashes a buffer using the MurmurHash2 algorithm.
278 * \param size Size of the buffer to hash.
279 * \param buff Pointer to the buffer to hash.
280 * \param seed Initial seed value.
281 * \return The computed 32-bit hash.
282 */
283
284uint32_t nyx_hash(
285 __NYX_ZEROABLE__ size_t size,
286 __NYX_NULLABLE__ BUFF_t buff,
287 uint32_t seed
288);
289
290/*--------------------------------------------------------------------------------------------------------------------*/
291
292/**
293 * @brief Generates a MAC address based on a node identifier.
294 * @param result_mac Output array to store the generated MAC address.
295 * @param mac0 First fixed byte of the MAC address.
296 * @param mac1 Second fixed byte of the MAC address.
297 * @param node_id Unique node identifier used to hash the remaining bytes.
298 */
299
301 uint8_t result_mac[6],
302 uint8_t mac0,
303 uint8_t mac1,
304 STR_t node_id
305);
306
307/*--------------------------------------------------------------------------------------------------------------------*/
308
309/**
310 * @brief Encodes a buffer using the Base64 algorithm.
311 * \param result_len Optional pointer to store the length of the encoded string.
312 * \param size Size of the buffer to encode.
313 * \param buff Pointer to the buffer to encode.
314 * \return The encoded string.
315 */
316
317__NYX_NULLABLE__ str_t nyx_base64_encode(
318 __NYX_NULLABLE__ size_t *result_len,
319 __NYX_ZEROABLE__ size_t size,
320 __NYX_NULLABLE__ BUFF_t buff
321);
322
323/*--------------------------------------------------------------------------------------------------------------------*/
324
325/**
326 * @brief Decodes a string using the Base64 algorithm.
327 * \param result_size Optional pointer to store the size of the decoded buffer.
328 * \param len Length of the string to decode.
329 * \param str Pointer to the string to decode.
330 * \return The decoded buffer.
331 */
332
333__NYX_NULLABLE__ buff_t nyx_base64_decode(
334 __NYX_NULLABLE__ size_t *result_size,
335 __NYX_ZEROABLE__ size_t len,
336 __NYX_NULLABLE__ STR_t str
337);
338
339/*--------------------------------------------------------------------------------------------------------------------*/
340
341/**
342 * @brief Compresses a buffer using the ZLib algorithm.
343 * \param result_size Optional pointer to store the size of the compressed buffer.
344 * \param size Size of the buffer to compress.
345 * \param buff Pointer to the buffer to compress.
346 * \return The compressed buffer.
347 */
348
349__NYX_NULLABLE__ buff_t nyx_zlib_deflate(
350 __NYX_NULLABLE__ size_t *result_size,
351 __NYX_ZEROABLE__ size_t size,
352 __NYX_NULLABLE__ BUFF_t buff
353);
354
355/*--------------------------------------------------------------------------------------------------------------------*/
356
357/**
358 * @brief Decompresses a buffer using the ZLib algorithm.
359 * \param result_size Mandatory pointer to provide and store the size of the decompressed buffer.
360 * \param size Size of the buffer to decompress.
361 * \param buff Pointer to the buffer to decompress.
362 * \return The decompressed buffer.
363 */
364
365__NYX_NULLABLE__ buff_t nyx_zlib_inflate(
366 __NYX_NOTNULL__ size_t *result_size,
367 __NYX_ZEROABLE__ size_t size,
368 __NYX_NULLABLE__ BUFF_t buff
369);
370
371/*--------------------------------------------------------------------------------------------------------------------*/
372
373/**
374 * @brief Compresses a buffer using the ZLib+Base64 algorithm.
375 * \param result_len Optional pointer to store the length of the compressed string.
376 * \param size Size of the buffer to compress.
377 * \param buff Pointer to the buffer to compress.
378 * \return The compressed string.
379 */
380
382 __NYX_NULLABLE__ size_t *result_len,
383 __NYX_ZEROABLE__ size_t size,
384 __NYX_NULLABLE__ BUFF_t buff
385);
386
387/*--------------------------------------------------------------------------------------------------------------------*/
388
389/**
390 * @brief Decompresses a string using the ZLib+Base64 algorithm.
391 * \param result_size Mandatory pointer to provide and store the size of the decompressed buffer.
392 * \param len Length of the string to decompress.
393 * \param str Pointer to the string to decompress.
394 * \return The decompressed buffer.
395 */
396
398 __NYX_NOTNULL__ size_t *result_size,
399 __NYX_ZEROABLE__ size_t len,
400 __NYX_NULLABLE__ STR_t str
401);
402
403/*--------------------------------------------------------------------------------------------------------------------*/
404/* OBJECT */
405/*--------------------------------------------------------------------------------------------------------------------*/
406/** @}
407 * @defgroup OBJECT JSON serialization / deserialization
408 * JSON serialization / deserialization.
409 * @{
410 */
411/*--------------------------------------------------------------------------------------------------------------------*/
412
413#define NYX_OBJECT_MAGIC UINT32_C(0x65656500) //!< Magic number for identifying JSON objects.
414
415/*--------------------------------------------------------------------------------------------------------------------*/
416
417#define NYX_FLAGS_DISABLED UINT64_C(0x0000000000000001) // Flag indicating that the object is disabled.
418 /* 0b0000000000000000000000000000000_0000000000000000000000000000000_01 */
419
420#define NYX_FLAGS_BLOB_MASK UINT64_C(0x00000001FFFFFFFC) // Mask indicating the Nyx blob emission per client.
421 /* 0b0000000000000000000000000000000_1111111111111111111111111111111_00 */
422
423#define NYX_FLAGS_STREAM_MASK UINT64_C(0xFFFFFFFE00000000) // Mask indicating the Nyx stream emission per client.
424 /* 0b1111111111111111111111111111111_0000000000000000000000000000000_00 */
425
426/*--------------------------------------------------------------------------------------------------------------------*/
427
428/**
429 * @brief JSON object types.
430 */
431
432typedef enum
433{
434 NYX_TYPE_NULL = NYX_OBJECT_MAGIC | 0, //!< Null object.
435 NYX_TYPE_BOOLEAN = NYX_OBJECT_MAGIC | 1, //!< Boolean object.
436 NYX_TYPE_NUMBER = NYX_OBJECT_MAGIC | 2, //!< Number object.
437 NYX_TYPE_STRING = NYX_OBJECT_MAGIC | 3, //!< String object.
438 NYX_TYPE_DICT = NYX_OBJECT_MAGIC | 4, //!< Dict object.
439 NYX_TYPE_LIST = NYX_OBJECT_MAGIC | 5, //!< List object.
440
441} nyx_type_t;
442
443/*--------------------------------------------------------------------------------------------------------------------*/
444
445/**
446 * @private
447 */
448
449struct nyx_dict_s;
450
451/*--------------------------------------------------------------------------------------------------------------------*/
452
453/**
454 * @struct nyx_object_t
455 * @brief Struct describing a JSON object.
456 */
457
458typedef struct nyx_object_s
459{
460 /*----------------------------------------------------------------------------------------------------------------*/
461
462 nyx_type_t type; //!< Type of object, see @ref nyx_type_t.
463 uint64_t flags; //!< Mask of flags, see NYX_FLAGS_XXX definitions.
464 int32_t ref; //!< Reference counter for memory allocation.
465
466 /*----------------------------------------------------------------------------------------------------------------*/
467
468 __NYX_NULLABLE__ struct nyx_node_s *node; //!< Pointer to the associated Nyx node.
469
470 __NYX_NULLABLE__ struct nyx_object_s *parent; //!< Pointer to the parent object.
471
472 /*----------------------------------------------------------------------------------------------------------------*/
473
474 union {
475
476 __NYX_NULLABLE__ void *_ptr; //!< Untyped pointer.
477
478 __NYX_NULLABLE__ bool (* _int)(
479 struct nyx_dict_s *vector, //!< Parent vector object.
480 struct nyx_dict_s *prop, //!< Property object.
481 int new_value, //!< New value.
482 int old_value //!< Old value.
483 );
484
485 __NYX_NULLABLE__ bool (* _uint)(
486 struct nyx_dict_s *vector, //!< Parent vector object.
487 struct nyx_dict_s *prop, //!< Property object.
488 unsigned int new_value, //!< New value.
489 unsigned int old_value //!< Old value.
490 );
491
492 __NYX_NULLABLE__ bool (* _long)(
493 struct nyx_dict_s *vector, //!< Parent vector object.
494 struct nyx_dict_s *prop, //!< Property object.
495 long new_value, //!< New value.
496 long old_value //!< Old value.
497 );
498
499 __NYX_NULLABLE__ bool (* _ulong)(
500 struct nyx_dict_s *vector, //!< Parent vector object.
501 struct nyx_dict_s *prop, //!< Property object.
502 unsigned long new_value, //!< New value.
503 unsigned long old_value //!< Old value.
504 );
505
506 __NYX_NULLABLE__ bool (* _double)(
507 struct nyx_dict_s *vector, //!< Parent vector object.
508 struct nyx_dict_s *prop, //!< Property object.
509 double new_value, //!< New value.
510 double old_value //!< Old value.
511 );
512
513 __NYX_NULLABLE__ bool (* _str)(
514 struct nyx_dict_s *vector, //!< Parent vector object.
515 struct nyx_dict_s *prop, //!< Property object.
516 STR_t new_value, //!< New value.
517 STR_t old_value //!< Old value.
518 );
519
520 __NYX_NULLABLE__ bool (* _buffer)(
521 struct nyx_dict_s *vector, //!< Parent vector object.
522 struct nyx_dict_s *prop, //!< Property object.
523 size_t size, //!< Size of the new buffer.
524 BUFF_t buff //!< Pointer to the new buffer.
525 );
526
527 __NYX_NULLABLE__ void (* _vector)(
528 struct nyx_dict_s *vector, //!< Vector object.
529 bool modified //!< Indicates whether the vector has been modified.
530 );
531
532 } callback; //!< Callback triggered when the client modifies this object.
533
534 /*----------------------------------------------------------------------------------------------------------------*/
535
536 __NYX_NULLABLE__ void *ctx; //!< User context pointer.
537
538 /*----------------------------------------------------------------------------------------------------------------*/
539
541
542/*--------------------------------------------------------------------------------------------------------------------*/
543
544/**
545 * @memberof nyx_object_t
546 * @brief Parses a JSON object from a string buffer.
547 * \param size String size.
548 * \param buff String pointer.
549 * \return The new JSON object.
550 */
551
553 __NYX_ZEROABLE__ size_t size,
554 __NYX_NULLABLE__ BUFF_t buff
555);
556
557/*--------------------------------------------------------------------------------------------------------------------*/
558
559/**
560 * @memberof nyx_object_t
561 * @brief Parses a JSON object from a C string.
562 * \param string C string.
563 * \return The new JSON object.
564 */
565
567 __NYX_NULLABLE__ STR_t string
568);
569
570/*--------------------------------------------------------------------------------------------------------------------*/
571
572/**
573 * @memberof nyx_object_t
574 * @brief Increments the reference counter of the provided JSON object.
575 * @param object JSON object.
576 * @return The input JSON object of NULL.
577 */
578
579__NYX_NULLABLE__ nyx_object_t *nyx_object_ref(
580 __NYX_NULLABLE__ void *object
581);
582
583/*--------------------------------------------------------------------------------------------------------------------*/
584
585/**
586 * @memberof nyx_object_t
587 * @brief Decrements the reference counter of the provided JSON object and frees it when it reaches zero.
588 * @param object JSON object.
589 * @return The input JSON object of NULL.
590 */
591
593 __NYX_NULLABLE__ void *object
594);
595
596/*--------------------------------------------------------------------------------------------------------------------*/
597
598/**
599 * @memberof nyx_object_t
600 * @brief Gets the type of the provided JSON object.
601 * @param object JSON object.
602 * @return The type.
603 */
604
606 __NYX_NULLABLE__ const nyx_object_t *object
607);
608
609/*--------------------------------------------------------------------------------------------------------------------*/
610
611/**
612 * @memberof nyx_object_t
613 * @brief Notifies the provided Nyx / INDI object to the clients.
614 * @param object The provided Nyx / INDI object.
615 */
616
618 __NYX_NULLABLE__ const nyx_object_t *object
619);
620
621/*--------------------------------------------------------------------------------------------------------------------*/
622
623/**
624 * @memberof nyx_object_t
625 * @brief Compares two JSON objects.
626 * @param object1 First JSON object.
627 * @param object2 Second JSON object.
628 * @return `true` if the objects are equal, `false` otherwise.
629 */
630
632 __NYX_NULLABLE__ const nyx_object_t *object1,
633 __NYX_NULLABLE__ const nyx_object_t *object2
634);
635
636/*--------------------------------------------------------------------------------------------------------------------*/
637
638/**
639 * @memberof nyx_object_t
640 * @brief Returns a string, with the special character escaping, representing the provided JSON object.
641 * @param object JSON object.
642 * @return A newly allocated string that represents the provided JSON object.
643 * @note Must be freed with @ref nyx_memory_free.
644 */
645
647 __NYX_NULLABLE__ const nyx_object_t *object
648);
649
650/*--------------------------------------------------------------------------------------------------------------------*/
651
652/**
653 * @memberof nyx_object_t
654 * @brief Returns a C string, without special character escaping, representing the provided JSON object.
655 * @param object JSON object.
656 * @return A newly allocated string that represents the provided JSON object.
657 * @note Must be freed with @ref nyx_memory_free.
658 */
659
661 __NYX_NULLABLE__ const nyx_object_t *object
662);
663
664/*--------------------------------------------------------------------------------------------------------------------*/
665/* NULL */
666/*--------------------------------------------------------------------------------------------------------------------*/
667/** @}
668 * @defgroup NULL_OBJECT JSON Null Object
669 * @ingroup OBJECT
670 * JSON Null Object.
671 * @{
672 */
673/*--------------------------------------------------------------------------------------------------------------------*/
674
675/**
676 * @brief Struct describing a JSON null object.
677 */
678
679typedef struct
680{
681 nyx_object_t base; //!< Common object header for JSON objects.
682
683} nyx_null_t;
684
685/*--------------------------------------------------------------------------------------------------------------------*/
686
687/**
688 * @memberof nyx_null_t
689 * @brief Allocates a new JSON null object.
690 *
691 * @return The new JSON null object.
692 */
693
694nyx_null_t *nyx_null_new(void);
695
696/*--------------------------------------------------------------------------------------------------------------------*/
697
698/**
699 * @memberof nyx_null_t
700 * @brief Returns a string representing the provided JSON null object.
701 * @param object JSON null object.
702 * @return A newly allocated string that represents the provided JSON null object.
703 * @note Must be freed with @ref nyx_memory_free.
704 */
705
707 const nyx_null_t *object
708);
709
710/*--------------------------------------------------------------------------------------------------------------------*/
711/* NUMBER */
712/*--------------------------------------------------------------------------------------------------------------------*/
713/** @}
714 * @defgroup NUMBER_OBJECT JSON Number Object
715 * @ingroup OBJECT
716 * JSON Number Object.
717 * @{
718 */
719/*--------------------------------------------------------------------------------------------------------------------*/
720
721/**
722 * @brief Struct describing a JSON number object.
723 */
724
725typedef struct
726{
727 nyx_object_t base; //!< Common object header for JSON objects.
728
729 double value; //!< Number payload.
730
732
733/*--------------------------------------------------------------------------------------------------------------------*/
734
735/**
736 * @memberof nyx_number_t
737 * @brief Allocates a new JSON number object.
738 *
739 * @return The new JSON number object.
740 */
741
742nyx_number_t *nyx_number_new(void);
743
744/*--------------------------------------------------------------------------------------------------------------------*/
745
746/**
747 * @memberof nyx_number_t
748 * @brief Gets the value of the provided JSON number object.
749 * @param object JSON number object.
750 * @return The value.
751 */
752
753double nyx_number_get(
754 const nyx_number_t *object
755);
756
757/*--------------------------------------------------------------------------------------------------------------------*/
758
759/**
760 * @memberof nyx_number_t
761 * @brief Sets the value of the provided JSON number object.
762 * @param object JSON number object.
763 * @param value Value for the provided JSON number object.
764 * @return `true` if the value was modified, `false` otherwise.
765 */
766
767bool nyx_number_set(
768 /*-*/ nyx_number_t *object,
769 double value
770);
771
772
773/*--------------------------------------------------------------------------------------------------------------------*/
774
775/**
776 * @memberof nyx_number_t
777 * @brief Returns a string representing the provided JSON number object.
778 * @param object JSON number object.
779 * @return A newly allocated string that represents the provided JSON number object.
780 * @note Must be freed with @ref nyx_memory_free.
781 */
782
783str_t nyx_number_to_string(
784 const nyx_number_t *object
785);
786
787/*--------------------------------------------------------------------------------------------------------------------*/
788
789/**
790 * @memberof nyx_number_t
791 * @brief Returns a JSON number object holding the value of the provided argument.
792 * @param value Value for the new JSON number object.
793 * @return The new JSON number object.
794 */
795
796__NYX_INLINE__ nyx_number_t *nyx_number_from(double value)
797{
798 nyx_number_t *result = nyx_number_new();
799
800 nyx_number_set(result, value);
801
802 return result;
803}
804
805/*--------------------------------------------------------------------------------------------------------------------*/
806/* BOOLEAN */
807/*--------------------------------------------------------------------------------------------------------------------*/
808/** @}
809 * @defgroup BOOLEAN_OBJECT JSON Boolean Object
810 * @ingroup OBJECT
811 * JSON Boolean Object.
812 * @{
813 */
814/*--------------------------------------------------------------------------------------------------------------------*/
815
816/**
817 * @brief Struct describing a JSON boolean object.
818 */
819
820typedef struct
821{
822 nyx_object_t base; //!< Common object header for JSON objects.
823
824 bool value; //!< Boolean payload.
825
827
828/*--------------------------------------------------------------------------------------------------------------------*/
829
830/**
831 * @memberof nyx_boolean_t
832 * @brief Allocates a new JSON boolean object.
833 * @return The new JSON boolean object.
834 */
835
836nyx_boolean_t *nyx_boolean_new(void);
837
838/*--------------------------------------------------------------------------------------------------------------------*/
839
840/**
841 * @memberof nyx_boolean_t
842 * @brief Gets the value of the provided JSON boolean object.
843 * @param object JSON boolean object.
844 * @return The value.
845 */
846
847bool nyx_boolean_get(
848 const nyx_boolean_t *object
849);
850
851/*--------------------------------------------------------------------------------------------------------------------*/
852
853/**
854 * @memberof nyx_boolean_t
855 * @brief Sets the value of the provided JSON boolean object.
856 * @param object JSON boolean object.
857 * @param value Value for the provided JSON boolean object.
858 * @return `true` if the value was modified, `false` otherwise.
859 */
860
861bool nyx_boolean_set(
862 /*-*/ nyx_boolean_t *object,
863 bool value
864);
865
866/*--------------------------------------------------------------------------------------------------------------------*/
867
868/**
869 * @memberof nyx_boolean_t
870 * @brief Returns a string representing the provided JSON boolean object.
871 * @param object JSON boolean object.
872 * @return A newly allocated string that represents the provided JSON boolean object.
873 * @note Must be freed with @ref nyx_memory_free.
874 */
875
876str_t nyx_boolean_to_string(
877 const nyx_boolean_t *object
878);
879
880/*--------------------------------------------------------------------------------------------------------------------*/
881
882/**
883 * @memberof nyx_boolean_t
884 * @brief Returns a JSON boolean object holding the value of the provided argument.
885 * @param value Value for the new JSON boolean object.
886 * @return The new JSON boolean object.
887 */
888
890{
891 nyx_boolean_t *result = nyx_boolean_new();
892
893 nyx_boolean_set(result, value);
894
895 return result;
896}
897
898/*--------------------------------------------------------------------------------------------------------------------*/
899/* STRING */
900/*--------------------------------------------------------------------------------------------------------------------*/
901/** @}
902 * @defgroup STRING_OBJECT JSON String Object
903 * @ingroup OBJECT
904 * JSON String Object.
905 * @{
906 */
907/*--------------------------------------------------------------------------------------------------------------------*/
908
909/**
910 * @brief Struct describing a JSON string object.
911 */
912
913typedef struct
914{
915 nyx_object_t base; //!< Common object header for JSON objects.
916
917 bool managed; //!< `true` if the value is freed with this object.
918 size_t length; //!< C string length excluding `NULL`.
919 str_t value; //!< C string payload.
920
922
923/*--------------------------------------------------------------------------------------------------------------------*/
924
925/**
926 * @memberof nyx_string_t
927 * @brief Allocates a new JSON string object.
928 * @return The new JSON string object.
929 */
930
931nyx_string_t *nyx_string_new(void);
932
933/*--------------------------------------------------------------------------------------------------------------------*/
934
935/**
936 * @memberof nyx_string_t
937 * @brief Gets the text value of the provided JSON string object.
938 * @param object JSON string object.
939 * @return The text value of the provided JSON string object.
940 * @note The returned text value remains valid until the object is modified or released.
941 */
942
943STR_t nyx_string_get(
944 const nyx_string_t *object
945);
946
947/*--------------------------------------------------------------------------------------------------------------------*/
948
949/**
950 * @memberof nyx_string_t
951 * @brief Gets the content of the provided JSON string object as a byte buffer.
952 * @param object JSON string object.
953 * @param result_size Optional pointer receiving the number of content bytes.
954 * @param result_buff Optional pointer receiving the content buffer.
955 * @note The returned buffer remains valid until the object is modified or released.
956 */
957
959 const nyx_string_t *object,
960 __NYX_NULLABLE__ size_t *result_size,
961 __NYX_NULLABLE__ buff_t *result_buff
962);
963
964/*--------------------------------------------------------------------------------------------------------------------*/
965
966/**
967 * @memberof nyx_string_t
968 * @brief Sets the text value of the provided JSON string object.
969 * @param object JSON string object.
970 * @param value Text value.
971 * @param managed If `true`, ownership of the provided value is transferred to the object.
972 * @return `true` if the value was modified, `false` otherwise.
973 */
974
975bool nyx_string_set(
976 /*-*/ nyx_string_t *object,
977 STR_t value,
978 bool managed
979);
980
981/*--------------------------------------------------------------------------------------------------------------------*/
982
983/**
984 * @memberof nyx_string_t
985 * @brief Sets the content of the provided JSON string object from a byte buffer.
986 * @param object JSON string object.
987 * @param size Number of content bytes.
988 * @param buff Content buffer.
989 * @param managed If `true`, ownership of the provided buffer is transferred to the object.
990 * @return `true` if the value was modified, `false` otherwise.
991 */
992
994 /*-*/ nyx_string_t *object,
995 size_t size,
996 BUFF_t buff,
997 bool managed
998);
999
1000/*--------------------------------------------------------------------------------------------------------------------*/
1001
1002/**
1003 * @memberof nyx_string_t
1004 * @brief Returns the number of content bytes of the provided JSON string object.
1005 * @param object JSON string object.
1006 * @return The number of content bytes.
1007 */
1008
1009size_t nyx_string_length(
1010 const nyx_string_t *object
1011);
1012
1013/*--------------------------------------------------------------------------------------------------------------------*/
1014
1015/**
1016 * @memberof nyx_string_t
1017 * @brief Returns a C string, with the special character escaping, representing the provided JSON string object.
1018 * @param object JSON string object.
1019 * @return A newly allocated string that represents the provided JSON string object.
1020 * @note Must be freed with @ref nyx_memory_free.
1021 */
1022
1024 const nyx_string_t *object
1025);
1026
1027/*--------------------------------------------------------------------------------------------------------------------*/
1028
1029/**
1030 * @memberof nyx_string_t
1031 * @brief Returns a C string, without special character escaping, representing the provided JSON string object.
1032 * @param object JSON string object.
1033 * @return A newly allocated string that represents the provided JSON string object.
1034 * @note Must be freed with @ref nyx_memory_free.
1035 */
1036
1038 const nyx_string_t *object
1039);
1040
1041/*--------------------------------------------------------------------------------------------------------------------*/
1042
1043/**
1044 * @memberof nyx_string_t
1045 * @brief Returns a JSON string object holding the provided text value.
1046 * @param value Text value.
1047 * @param managed If `true`, ownership of the provided value is transferred to the object.
1048 * @return The new JSON string object.
1049 */
1050
1052{
1053 nyx_string_t *result = nyx_string_new();
1054
1055 nyx_string_set(result, value, managed);
1056
1057 return result;
1058}
1059
1060/*--------------------------------------------------------------------------------------------------------------------*/
1061
1062/**
1063 * @memberof nyx_string_t
1064 * @brief Returns a JSON string object holding the provided content bytes.
1065 * @param size Number of content bytes.
1066 * @param buff Content buffer.
1067 * @param managed If `true`, ownership of the provided buffer is transferred to the object.
1068 * @return The new JSON string object.
1069 */
1070
1071__NYX_INLINE__ nyx_string_t *nyx_string_from_buff(size_t size, BUFF_t buff, bool managed)
1072{
1073 nyx_string_t *result = nyx_string_new();
1074
1075 nyx_string_set_buff(result, size, buff, managed);
1076
1077 return result;
1078}
1079
1080/*--------------------------------------------------------------------------------------------------------------------*/
1081/* DICT */
1082/*--------------------------------------------------------------------------------------------------------------------*/
1083/** @}
1084 * @defgroup DICT_OBJECT JSON Dict Object
1085 * @ingroup OBJECT
1086 * JSON Dict Object.
1087 * @{
1088 */
1089/*--------------------------------------------------------------------------------------------------------------------*/
1090
1091/**
1092 * @struct nyx_dict_t
1093 * @brief Struct describing a JSON dict object.
1094 */
1095
1096typedef struct nyx_dict_s
1097{
1098 nyx_object_t base; //!< Common object header for JSON objects.
1099
1100 struct nyx_dict_node_s *head; //!< Linked list of key/value entries.
1101 struct nyx_dict_node_s *tail; //!< Linked list of key/value entries.
1102
1103} nyx_dict_t;
1104
1105/*--------------------------------------------------------------------------------------------------------------------*/
1106
1107/**
1108 * @brief Struct describing a JSON dict iterator.
1109 */
1110
1111typedef struct
1112{
1113 size_t idx; //!< Current zero-based iteration index.
1114
1115 struct nyx_dict_node_s *head; //!< Next JSON object to visit.
1116
1118
1119/*--------------------------------------------------------------------------------------------------------------------*/
1120
1121/**
1122 * @brief Initializes a JSON dict iterator.
1123 * @param dict JSON dict.
1124 */
1125
1126#define NYX_DICT_ITER(dict) \
1127 ((nyx_dict_iter_t) {0, ((nyx_dict_t *) (dict))->head})
1128
1129/*--------------------------------------------------------------------------------------------------------------------*/
1130
1131/**
1132 * @memberof nyx_dict_t
1133 * @brief Allocates a new JSON dict object.
1134 * @return The new JSON dict object.
1135 */
1136
1137nyx_dict_t *nyx_dict_new(void);
1138
1139/*--------------------------------------------------------------------------------------------------------------------*/
1140
1141/**
1142 * @memberof nyx_dict_t
1143 * @brief Clears the content of the provided JSON dict object.
1144 * @param object JSON dict object.
1145 */
1146
1147void nyx_dict_clear(
1148 /*-*/ nyx_dict_t *object
1149);
1150
1151/*--------------------------------------------------------------------------------------------------------------------*/
1152
1153/**
1154 * @memberof nyx_dict_t
1155 * @brief Deletes the entry of the provided key.
1156 * @param object JSON dict object.
1157 * @param key Key.
1158 */
1159
1160void nyx_dict_del(
1161 /*-*/ nyx_dict_t *object,
1162 STR_t key
1163);
1164
1165/*--------------------------------------------------------------------------------------------------------------------*/
1166
1167/**
1168 * @memberof nyx_dict_t
1169 * @brief Iterates over a JSON dict object.
1170 * @param iter Dict iterator.
1171 * @param key Pointer to the current element key.
1172 * @param object Pointer to the current JSON object.
1173 * @return `true` while elements remain, `false` otherwise.
1174 * @code
1175 * STR_t key;
1176 *
1177 * nyx_object_t *object;
1178 *
1179 * for(nyx_dict_iter_t iter = NYX_DICT_ITER(dict); nyx_dict_iterate(&iter, &key, &object);)
1180 * {
1181 * ...
1182 * }
1183 * @endcode
1184 */
1185
1186bool nyx_dict_iterate(
1187 nyx_dict_iter_t *iter,
1188 STR_t *key,
1189 nyx_object_t **object
1190);
1191
1192/*--------------------------------------------------------------------------------------------------------------------*/
1193
1194/**
1195 * @memberof nyx_dict_t
1196 * @brief Gets the JSON object of the provided key.
1197 * @param object JSON dict object.
1198 * @param key Key.
1199 * @return The JSON object or `NULL`.
1200 */
1201
1202nyx_object_t *nyx_dict_get(
1203 const nyx_dict_t *object,
1204 STR_t key
1205);
1206
1207/*--------------------------------------------------------------------------------------------------------------------*/
1208
1209/**
1210 * @memberof nyx_dict_t
1211 * @brief Sets a JSON object in the provided JSON dict object.
1212 * @param object JSON dict object.
1213 * @param key Key.
1214 * @param value JSON object to be added.
1215 * @return `true` if the value was modified, `false` otherwise.
1216 */
1217
1218bool nyx_dict_set(
1219 /*-*/ nyx_dict_t *object,
1220 STR_t key,
1221 void *value
1222);
1223
1224/*--------------------------------------------------------------------------------------------------------------------*/
1225
1226/**
1227 * @memberof nyx_dict_t
1228 * @brief Gets the number of items in the provided JSON dict object.
1229 * @param object JSON dict object.
1230 * @return The number of items in the provided JSON dict object.
1231 */
1232
1233size_t nyx_dict_size(
1234 const nyx_dict_t *object
1235);
1236
1237/*--------------------------------------------------------------------------------------------------------------------*/
1238
1239/**
1240 * @memberof nyx_dict_t
1241 * @brief Returns a string representing the provided JSON dict object.
1242 * @param object JSON dict object.
1243 * @return A newly allocated string that represents the provided JSON dict object.
1244 * @note Must be freed with @ref nyx_memory_free.
1245 */
1246
1247str_t nyx_dict_to_string(
1248 const nyx_dict_t *object
1249);
1250
1251/*--------------------------------------------------------------------------------------------------------------------*/
1252
1253/**
1254 * @memberof nyx_dict_t
1255 * @brief Gets a boolean value of the provided key.
1256 * @param object JSON dict object.
1257 * @param key Key.
1258 * @return The related boolean value or `false` if absent or wrong type.
1259 */
1260
1261__NYX_INLINE__ bool nyx_dict_get_boolean(const nyx_dict_t *object, STR_t key)
1262{
1263 nyx_object_t *value = nyx_dict_get(object, key);
1264
1265 return value != NULL && value->type == NYX_TYPE_BOOLEAN ? nyx_boolean_get((nyx_boolean_t *) value)
1266 : false
1267 ;
1268}
1269
1270/*--------------------------------------------------------------------------------------------------------------------*/
1271
1272/**
1273 * @memberof nyx_dict_t
1274 * @brief Gets a number value of the provided key.
1275 * @param dict JSON dict object.
1276 * @param key Key.
1277 * @return The related number value or `NaN` if absent or wrong type.
1278 */
1279
1280__NYX_INLINE__ double nyx_dict_get_number(const nyx_dict_t *dict, STR_t key)
1281{
1282 nyx_object_t *object = nyx_dict_get(dict, key);
1283
1284 return object != NULL && object->type == NYX_TYPE_NUMBER ? nyx_number_get((nyx_number_t *) object)
1285 : nan("1")
1286 ;
1287}
1288
1289/*--------------------------------------------------------------------------------------------------------------------*/
1290
1291/**
1292 * @memberof nyx_dict_t
1293 * @brief Gets a text value of the provided key.
1294 * @param dict JSON dict object.
1295 * @param key Key.
1296 * @return The related text value or `NULL` if absent or wrong type.
1297 * @note The returned text value remains valid until the related string object is modified or released.
1298 */
1299
1300__NYX_INLINE__ STR_t nyx_dict_get_string(const nyx_dict_t *dict, STR_t key)
1301{
1302 nyx_object_t *object = nyx_dict_get(dict, key);
1303
1304 return object != NULL && object->type == NYX_TYPE_STRING ? nyx_string_get((nyx_string_t *) object)
1305 : NULL
1306 ;
1307}
1308
1309/*--------------------------------------------------------------------------------------------------------------------*/
1310
1311/**
1312 * @memberof nyx_dict_t
1313 * @brief Gets the content of the provided key as a byte buffer.
1314 * @param dict JSON dict object.
1315 * @param key Key.
1316 * @param result_size Pointer receiving the number of content bytes.
1317 * @param result_buff Pointer receiving the content buffer.
1318 * @note The returned buffer remains valid until the related string object is modified or released.
1319*/
1320
1321__NYX_INLINE__ void nyx_dict_get_buff(const nyx_dict_t *dict, STR_t key, __NYX_NULLABLE__ size_t *result_size, __NYX_NULLABLE__ buff_t *result_buff)
1322{
1323 nyx_object_t *object = nyx_dict_get(dict, key);
1324
1325 if(object != NULL && object->type == NYX_TYPE_STRING) nyx_string_get_buff((nyx_string_t *) object, result_size, result_buff);
1326}
1327
1328/*--------------------------------------------------------------------------------------------------------------------*/
1329
1330/**
1331 * @memberof nyx_dict_t
1332 * @brief Sets a boolean value of an existing key holding a boolean.
1333 * @param dict JSON dict object.
1334 * @param key Key.
1335 * @param value Boolean value to set.
1336 * @return `true` if the value was modified, `false` otherwise.
1337 */
1338
1339__NYX_INLINE__ bool nyx_dict_set_boolean(const nyx_dict_t *dict, STR_t key, bool value)
1340{
1341 nyx_object_t *object = nyx_dict_get(dict, key);
1342
1343 return object != NULL && object->type == NYX_TYPE_BOOLEAN ? nyx_boolean_set((nyx_boolean_t *) object, value)
1344 : false
1345 ;
1346}
1347
1348/*--------------------------------------------------------------------------------------------------------------------*/
1349
1350/**
1351 * @memberof nyx_dict_t
1352 * @brief Sets a number value of an existing key holding a number.
1353 * @param dict JSON dict object.
1354 * @param key Key.
1355 * @param value Number value to set.
1356 * @return `true` if the value was modified, `false` otherwise.
1357 */
1358
1359__NYX_INLINE__ bool nyx_dict_set_number(const nyx_dict_t *dict, STR_t key, double value)
1360{
1361 nyx_object_t *object = nyx_dict_get(dict, key);
1362
1363 return object != NULL && object->type == NYX_TYPE_NUMBER ? nyx_number_set((nyx_number_t *) object, value)
1364 : false
1365 ;
1366}
1367
1368/*--------------------------------------------------------------------------------------------------------------------*/
1369
1370/**
1371 * @memberof nyx_dict_t
1372 * @brief Sets a text value of an existing key holding a string.
1373 * @param dict JSON dict object.
1374 * @param key Key.
1375 * @param value Text value to set.
1376 * @param managed If `true`, ownership of the provided value is transferred to the object.
1377 * @return `true` if the value was modified, `false` otherwise.
1378 */
1379
1380__NYX_INLINE__ bool nyx_dict_set_string(const nyx_dict_t *dict, STR_t key, STR_t value, bool managed)
1381{
1382 nyx_object_t *object = nyx_dict_get(dict, key);
1383
1384 return object != NULL && object->type == NYX_TYPE_STRING ? nyx_string_set((nyx_string_t *) object, value, managed)
1385 : false
1386 ;
1387}
1388
1389/*--------------------------------------------------------------------------------------------------------------------*/
1390
1391/**
1392 * @memberof nyx_dict_t
1393 * @brief Sets the content of an existing key holding a string from a byte buffer.
1394 * @param dict JSON dict object.
1395 * @param key Key.
1396 * @param size Number of content bytes.
1397 * @param buff Content buffer.
1398 * @param managed If `true`, ownership of the provided buffer is transferred to the object.
1399 * @return `true` if the value was modified, `false` otherwise.
1400 */
1401
1402__NYX_INLINE__ bool nyx_dict_set_buff(const nyx_dict_t *dict, STR_t key, size_t size, BUFF_t buff, bool managed)
1403{
1404 nyx_object_t *object = nyx_dict_get(dict, key);
1405
1406 return object != NULL && object->type == NYX_TYPE_STRING ? nyx_string_set_buff((nyx_string_t *) object, size, buff, managed)
1407 : false
1408 ;
1409}
1410
1411/*--------------------------------------------------------------------------------------------------------------------*/
1412/* LIST */
1413/*--------------------------------------------------------------------------------------------------------------------*/
1414/** @}
1415 * @defgroup LIST_OBJECT JSON List Object
1416 * @ingroup OBJECT
1417 * JSON List Object.
1418 * @{
1419 */
1420/*--------------------------------------------------------------------------------------------------------------------*/
1421
1422/**
1423 * @struct nyx_list_t
1424 * @brief Struct describing a JSON list object.
1425 */
1426
1427typedef struct nyx_list_s
1428{
1429 nyx_object_t base; //!< Common object header for JSON objects.
1430
1431 struct nyx_list_node_s *head; //!< Linked list of key/value entries.
1432 struct nyx_list_node_s *tail; //!< Linked list of key/value entries.
1433
1434} nyx_list_t;
1435
1436/*--------------------------------------------------------------------------------------------------------------------*/
1437
1438/**
1439 * @brief Struct describing a JSON list iterator.
1440 */
1441
1442typedef struct
1443{
1444 size_t idx; //!< Current zero-based iteration index.
1445
1446 struct nyx_list_node_s *head; //!< Next JSON object to visit.
1447
1449
1450/*--------------------------------------------------------------------------------------------------------------------*/
1451
1452/**
1453 * @brief Initializes a JSON list iterator.
1454 * @param list JSON list object.
1455 */
1456
1457#define NYX_LIST_ITER(list) \
1458 ((nyx_list_iter_t) {0, ((nyx_list_t *) (list))->head})
1459
1460/*--------------------------------------------------------------------------------------------------------------------*/
1461
1462/**
1463 * @memberof nyx_list_t
1464 * @brief Allocates a new JSON list.
1465 * @return The new JSON list.
1466 */
1467
1468nyx_list_t *nyx_list_new(void);
1469
1470/*--------------------------------------------------------------------------------------------------------------------*/
1471
1472/**
1473 * @memberof nyx_list_t
1474 * @brief Clears the content of the provided JSON list object.
1475 * @param object JSON list object.
1476 */
1477
1478void nyx_list_clear(
1479 /*-*/ nyx_list_t *object
1480);
1481
1482/*--------------------------------------------------------------------------------------------------------------------*/
1483
1484/**
1485 * @memberof nyx_list_t
1486 * @brief Deletes the entry at the provided index.
1487 * @param object JSON list object.
1488 * @param idx Index.
1489 */
1490
1491void nyx_list_del(
1492 /*-*/ nyx_list_t *object,
1493 size_t idx
1494);
1495
1496/*--------------------------------------------------------------------------------------------------------------------*/
1497
1498/**
1499 * @memberof nyx_list_t
1500 * @brief Iterates over a JSON list object.
1501 * @param iter List iterator.
1502 * @param idx Pointer to the current element index.
1503 * @param object Pointer to the current JSON object.
1504 * @return `true` while elements remain, `false` otherwise.
1505 * @code
1506 * size_t idx;
1507 *
1508 * nyx_object_t *object;
1509 *
1510 * for(nyx_list_iter_t iter = NYX_LIST_ITER(list); nyx_list_iterate(&iter, &idx, &object);)
1511 * {
1512 * ...
1513 * }
1514 * @endcode
1515 */
1516
1517bool nyx_list_iterate(
1518 nyx_list_iter_t *iter,
1519 size_t *idx,
1520 nyx_object_t **object
1521);
1522
1523/*--------------------------------------------------------------------------------------------------------------------*/
1524
1525/**
1526 * @memberof nyx_list_t
1527 * @brief Gets the JSON object at the provided index.
1528 * @param object JSON list object.
1529 * @param idx Index.
1530 * @return The JSON object at the provided index or `NULL`.
1531 */
1532
1533nyx_object_t *nyx_list_get(
1534 const nyx_list_t *object,
1535 size_t idx
1536);
1537
1538/*--------------------------------------------------------------------------------------------------------------------*/
1539
1540/**
1541 * @private
1542 */
1543
1544bool nyx_list_set(
1545 /*-*/ nyx_list_t *object,
1546 size_t idx,
1547 void *value
1548);
1549
1550/*--------------------------------------------------------------------------------------------------------------------*/
1551
1552/**
1553 * @memberof nyx_list_t
1554 * @brief Pushes a JSON object in the provided JSON list object.
1555 * @param object JSON list object.
1556 * @param value JSON object to be added.
1557 * @return `true` if the value was modified, `false` otherwise.
1558 */
1559
1560__NYX_INLINE__ bool nyx_list_push(nyx_list_t *object, void *value)
1561{
1562 return nyx_list_set(object, (size_t) -1, value);
1563}
1564
1565/*--------------------------------------------------------------------------------------------------------------------*/
1566
1567/**
1568 * @memberof nyx_list_t
1569 * @brief Gets the number of items in the provided JSON list object.
1570 * @param object JSON list object.
1571 * @return The number of items in the provided JSON list object.
1572 */
1573
1574size_t nyx_list_size(
1575 const nyx_list_t *object
1576);
1577
1578/*--------------------------------------------------------------------------------------------------------------------*/
1579
1580/**
1581 * @memberof nyx_list_t
1582 * @brief Returns a string representing the provided JSON list object.
1583 * @param object JSON list object.
1584 * @return A newly allocated string that represents the provided JSON list object.
1585 * @note Must be freed with @ref nyx_memory_free.
1586 */
1587
1588str_t nyx_list_to_string(
1589 const nyx_list_t *object
1590);
1591
1592/*--------------------------------------------------------------------------------------------------------------------*/
1593
1594/**
1595 * @memberof nyx_list_t
1596 * @brief Gets a boolean value at the provided index.
1597 * @param object JSON list object.
1598 * @param idx Index.
1599 * @return The related boolean value or `false` if absent or wrong type.
1600 */
1601
1602__NYX_INLINE__ bool nyx_list_get_boolean(const nyx_list_t *object, size_t idx)
1603{
1604 nyx_object_t *value = nyx_list_get(object, idx);
1605
1606 return value != NULL && value->type == NYX_TYPE_BOOLEAN ? nyx_boolean_get((nyx_boolean_t *) value)
1607 : false
1608 ;
1609}
1610
1611/*--------------------------------------------------------------------------------------------------------------------*/
1612
1613/**
1614 * @memberof nyx_list_t
1615 * @brief Gets a number value at the provided index.
1616 * @param list JSON list object.
1617 * @param idx Index.
1618 * @return The related number value or `NaN` if absent or wrong type.
1619 */
1620
1621__NYX_INLINE__ double nyx_list_get_number(const nyx_list_t *list, size_t idx)
1622{
1623 nyx_object_t *object = nyx_list_get(list, idx);
1624
1625 return object != NULL && object->type == NYX_TYPE_NUMBER ? nyx_number_get((nyx_number_t *) object)
1626 : nan("1")
1627 ;
1628}
1629
1630/*--------------------------------------------------------------------------------------------------------------------*/
1631
1632/**
1633 * @memberof nyx_list_t
1634 * @brief Gets a text value at the provided index.
1635 * @param list JSON list object.
1636 * @param idx Index.
1637 * @return The related text value or `NULL` if absent or wrong type.
1638 * @note The returned text value remains valid until the related string object is modified or released.
1639 */
1640
1641__NYX_INLINE__ STR_t nyx_list_get_string(const nyx_list_t *list, size_t idx)
1642{
1643 nyx_object_t *object = nyx_list_get(list, idx);
1644
1645 return object != NULL && object->type == NYX_TYPE_STRING ? nyx_string_get((nyx_string_t *) object)
1646 : NULL
1647 ;
1648}
1649
1650/*--------------------------------------------------------------------------------------------------------------------*/
1651
1652/**
1653 * @memberof nyx_list_t
1654 * @brief Gets the content of the provided index as a byte buffer.
1655 * @param list JSON list object.
1656 * @param idx Index.
1657 * @param result_size Pointer receiving the number of content bytes.
1658 * @param result_buff Pointer receiving the content buffer.
1659 * @note The returned buffer remains valid until the related string object is modified or released.
1660 */
1661
1662__NYX_INLINE__ void nyx_list_get_buff(const nyx_list_t *list, size_t idx, __NYX_NULLABLE__ size_t *result_size, __NYX_NULLABLE__ buff_t *result_buff)
1663{
1664 nyx_object_t *object = nyx_list_get(list, idx);
1665
1666 if(object != NULL && object->type == NYX_TYPE_STRING) nyx_string_get_buff((nyx_string_t *) object, result_size, result_buff);
1667}
1668
1669/*--------------------------------------------------------------------------------------------------------------------*/
1670
1671/**
1672 * @memberof nyx_list_t
1673 * @brief Sets a boolean value of an existing index holding a boolean.
1674 * @param list JSON list object.
1675 * @param idx Index.
1676 * @param value Boolean value to set.
1677 * @return `true` if the value was modified, `false` otherwise.
1678 */
1679
1680__NYX_INLINE__ bool nyx_list_set_boolean(const nyx_list_t *list, size_t idx, bool value)
1681{
1682 nyx_object_t *object = nyx_list_get(list, idx);
1683
1684 return object != NULL && object->type == NYX_TYPE_BOOLEAN ? nyx_boolean_set((nyx_boolean_t *) object, value)
1685 : false
1686 ;
1687}
1688
1689/*--------------------------------------------------------------------------------------------------------------------*/
1690
1691/**
1692 * @memberof nyx_list_t
1693 * @brief Sets a number value of an existing index holding a number.
1694 * @param list JSON list object.
1695 * @param idx Index.
1696 * @param value Number value to set.
1697 * @return `true` if the value was modified, `false` otherwise.
1698 */
1699
1700__NYX_INLINE__ bool nyx_list_set_number(const nyx_list_t *list, size_t idx, double value)
1701{
1702 nyx_object_t *object = nyx_list_get(list, idx);
1703
1704 return object != NULL && object->type == NYX_TYPE_NUMBER ? nyx_number_set((nyx_number_t *) object, value)
1705 : false
1706 ;
1707}
1708
1709/*--------------------------------------------------------------------------------------------------------------------*/
1710
1711/**
1712 * @memberof nyx_list_t
1713 * @brief Sets a text value of an existing index holding a string.
1714 * @param list JSON list object.
1715 * @param idx Index.
1716 * @param value Text value to set.
1717 * @param managed If `true`, ownership of the provided value is transferred to the object.
1718 * @return `true` if the value was modified, `false` otherwise.
1719 */
1720
1721__NYX_INLINE__ bool nyx_list_set_string(const nyx_list_t *list, size_t idx, STR_t value, bool managed)
1722{
1723 nyx_object_t *object = nyx_list_get(list, idx);
1724
1725 return object != NULL && object->type == NYX_TYPE_STRING ? nyx_string_set((nyx_string_t *) object, value, managed)
1726 : false
1727 ;
1728}
1729
1730/*--------------------------------------------------------------------------------------------------------------------*/
1731
1732/**
1733 * @memberof nyx_list_t
1734 * @brief Sets the content of an existing index holding a string from a byte buffer.
1735 * @param list JSON list object.
1736 * @param idx Index.
1737 * @param size Number of content bytes.
1738 * @param buff Content buffer.
1739 * @param managed If `true`, ownership of the provided buffer is transferred to the object.
1740 * @return `true` if the value was modified, `false` otherwise.
1741 */
1742
1743__NYX_INLINE__ bool nyx_list_set_buff(const nyx_list_t *list, size_t idx, size_t size, BUFF_t buff, bool managed)
1744{
1745 nyx_object_t *object = nyx_list_get(list, idx);
1746
1747 return object != NULL && object->type == NYX_TYPE_STRING ? nyx_string_set_buff((nyx_string_t *) object, size, buff, managed)
1748 : false
1749 ;
1750}
1751
1752/*--------------------------------------------------------------------------------------------------------------------*/
1753/* XMLDOC */
1754/*--------------------------------------------------------------------------------------------------------------------*/
1755#if !defined(ARDUINO)
1756/*--------------------------------------------------------------------------------------------------------------------*/
1757/** @}
1758 * @defgroup XMLDOC XML serialization / deserialization
1759 * XML serialization / deserialization (not available on ARDUINO).
1760 * @{
1761 */
1762/*--------------------------------------------------------------------------------------------------------------------*/
1763
1764/**
1765 * @memberof nyx_xmldoc_t
1766 * @brief XML node types.
1767 */
1768
1769typedef enum
1770{
1771 NYX_XML_ELEM = 300, //!< Element node.
1772 NYX_XML_ATTR = 301, //!< Attribute node.
1773 NYX_XML_COMMENT = 302, //!< Comment node.
1774 NYX_XML_CDATA = 303, //!< CDATA content.
1775 NYX_XML_TEXT = 304, //!< Text content.
1776
1777} nyx_xml_type_t;
1778
1779/*--------------------------------------------------------------------------------------------------------------------*/
1780
1781/**
1782 * @struct nyx_xmldoc_t
1783 * @brief Struct describing an XML document.
1784 */
1785
1786typedef struct nyx_xmldoc_s
1787{
1788 str_t name;
1789 nyx_xml_type_t type;
1790 str_t data;
1791
1792 struct nyx_xmldoc_s *next;
1793 struct nyx_xmldoc_s *parent;
1794
1795 struct nyx_xmldoc_s *children;
1796 struct nyx_xmldoc_s *attributes;
1797
1798 bool self_closing;
1799
1800} nyx_xmldoc_t;
1801
1802/*--------------------------------------------------------------------------------------------------------------------*/
1803
1804/**
1805 * @memberof nyx_xmldoc_t
1806 * @brief Parses an XML document from a string buffer.
1807 * \param size String size.
1808 * \param buff String pointer.
1809 * \return The new XML document.
1810 */
1811
1813 __NYX_ZEROABLE__ size_t size,
1814 __NYX_NULLABLE__ BUFF_t buff
1815);
1816
1817/*--------------------------------------------------------------------------------------------------------------------*/
1818
1819/**
1820 * @memberof nyx_xmldoc_t
1821 * @brief Parses an XML document from a C string.
1822 * \param string C string.
1823 * \return The new XML document.
1824 */
1825
1827 __NYX_NULLABLE__ STR_t string
1828);
1829
1830/*--------------------------------------------------------------------------------------------------------------------*/
1831
1832/**
1833 * @memberof nyx_xmldoc_t
1834 * @brief Frees memory of the provided XML document.
1835 * @param xmldoc The provided XML document.
1836 */
1837
1839 __NYX_NULLABLE__ nyx_xmldoc_t *xmldoc
1840);
1841
1842/*--------------------------------------------------------------------------------------------------------------------*/
1843
1844/**
1845 * @memberof nyx_xmldoc_t
1846 * @brief Returns a string representing the provided XML document.
1847 * @param xmldoc XML document.
1848 * @return A newly allocated string that represents the provided XML document.
1849 * @note Must be freed with @ref nyx_memory_free.
1850 */
1851
1853 const nyx_xmldoc_t *xmldoc
1854);
1855
1856/*--------------------------------------------------------------------------------------------------------------------*/
1857#endif
1858/*--------------------------------------------------------------------------------------------------------------------*/
1859/* TRANSFORM */
1860/*--------------------------------------------------------------------------------------------------------------------*/
1861#if !defined(ARDUINO)
1862/*--------------------------------------------------------------------------------------------------------------------*/
1863/** @}
1864 * @defgroup TRANSFORM JSON ↔ XML
1865 * JSON ↔ XML Nyx / INDI commands (not available on ARDUINO).
1866 * @{
1867 */
1868/*--------------------------------------------------------------------------------------------------------------------*/
1869
1870/**
1871 * @brief Converts an XML Nyx / INDI command to the JSON one.
1872 * @param xmldoc XML Nyx / INDI command.
1873 * @return The corresponding JSON Nyx / INDI command.
1874 */
1875
1877 __NYX_NULLABLE__ const nyx_xmldoc_t *xmldoc
1878);
1879
1880/*--------------------------------------------------------------------------------------------------------------------*/
1881
1882/**
1883 * @brief Converts a JSON Nyx / INDI command to the XML one.
1884 * @param object JSON Nyx / INDI command.
1885 * @return The corresponding XML Nyx / INDI command.
1886 */
1887
1889 __NYX_NULLABLE__ const nyx_object_t *object
1890);
1891
1892/*--------------------------------------------------------------------------------------------------------------------*/
1893#endif
1894/*--------------------------------------------------------------------------------------------------------------------*/
1895/* NYX */
1896/*--------------------------------------------------------------------------------------------------------------------*/
1897/** @}
1898 * @defgroup NYX Nyx protocol
1899 * Nyx protocol.
1900 * @{
1901 */
1902/*--------------------------------------------------------------------------------------------------------------------*/
1903
1904#define NYX_INDI_VERSION "1.7" //!< INDI backward compatibility version.
1905
1906/*--------------------------------------------------------------------------------------------------------------------*/
1907
1908/**
1909 * @brief Vector state hint.
1910 */
1911
1912typedef enum
1913{
1914 NYX_STATE_IDLE = 400, //!< State is idle.
1915 NYX_STATE_OK = 401, //!< State is ok.
1916 NYX_STATE_BUSY = 402, //!< State is busy.
1917 NYX_STATE_ALERT = 403, //!< State is alert.
1918
1919} nyx_state_t;
1920
1921/*--------------------------------------------------------------------------------------------------------------------*/
1922
1923/**
1924 * @private
1925 */
1926
1927STR_t nyx_state_to_str(
1928 nyx_state_t state
1929);
1930
1931/*--------------------------------------------------------------------------------------------------------------------*/
1932
1933/**
1934 * @private
1935 */
1936
1937nyx_state_t nyx_str_to_state(
1938 STR_t state
1939);
1940
1941/*--------------------------------------------------------------------------------------------------------------------*/
1942
1943/**
1944 * @brief Vector permission hint.
1945 */
1946
1947typedef enum
1948{
1949 NYX_PERM_RO = 500, //!< Read only.
1950 NYX_PERM_WO = 501, //!< Write only.
1951 NYX_PERM_RW = 502, //!< Read & write.
1952
1953} nyx_perm_t;
1954
1955/*--------------------------------------------------------------------------------------------------------------------*/
1956
1957/**
1958 * @private
1959 */
1960
1961STR_t nyx_perm_to_str(
1962 nyx_perm_t perm
1963);
1964
1965/*--------------------------------------------------------------------------------------------------------------------*/
1966
1967/**
1968 * @private
1969 */
1970
1971nyx_perm_t nyx_str_to_perm(
1972 STR_t perm
1973);
1974
1975/*--------------------------------------------------------------------------------------------------------------------*/
1976
1977/**
1978 * @brief Switch vector rule hint.
1979 */
1980
1981typedef enum
1982{
1983 NYX_RULE_ONE_OF_MANY = 600, //!< Only one switch of many can be ON (e.g., radio buttons).
1984 NYX_RULE_AT_MOST_ONE = 601, //!< At most one switch can be ON, but all switches can be OFF.
1985 NYX_RULE_ANY_OF_MANY = 602, //!< Any number of switches can be ON (e.g., check boxes).
1986
1987} nyx_rule_t;
1988
1989/*--------------------------------------------------------------------------------------------------------------------*/
1990
1991/**
1992 * @private
1993 */
1994
1995STR_t nyx_rule_to_str(
1996 nyx_rule_t rule
1997);
1998
1999/*--------------------------------------------------------------------------------------------------------------------*/
2000
2001/**
2002 * @private
2003 */
2004
2005nyx_rule_t nyx_str_to_rule(
2006 STR_t rule
2007);
2008
2009/*--------------------------------------------------------------------------------------------------------------------*/
2010
2011/**
2012 * @brief Switch state.
2013 */
2014
2015typedef enum
2016{
2017 NYX_ONOFF_ON = 700, //!< Switch is ON.
2018 NYX_ONOFF_OFF = 701, //!< Switch is OFF.
2019
2020} nyx_onoff_t;
2021
2022/*--------------------------------------------------------------------------------------------------------------------*/
2023
2024/**
2025 * @private
2026 */
2027
2028STR_t nyx_onoff_to_str(
2029 nyx_onoff_t onoff
2030);
2031
2032/*--------------------------------------------------------------------------------------------------------------------*/
2033
2034/**
2035 * @private
2036 */
2037
2038nyx_onoff_t nyx_str_to_onoff(
2039 STR_t onoff
2040);
2041
2042/*--------------------------------------------------------------------------------------------------------------------*/
2043
2044/**
2045 * @brief Struct describing the options for INDI / Nyx vectors.
2046 */
2047
2048typedef struct
2049{
2050 __NYX_NULLABLE__ STR_t group; //!< GUI group membership, if `NULL`, replaced by "Main".
2051 __NYX_NULLABLE__ STR_t label; //!< GUI label, if `NULL`, replaced by the device name.
2052 __NYX_NULLABLE__ STR_t hints; //!< GUI Markdown description.
2053 __NYX_NULLABLE__ STR_t message; //!< Free comment.
2054 __NYX_ZEROABLE__ double timeout; //!< Worst-case time [sec] to apply, 0 by default, N/A for RO.
2055
2056} nyx_opts_t;
2057
2058/*--------------------------------------------------------------------------------------------------------------------*/
2059/** @}
2060 * @defgroup NYX_NUMBER Nyx Number Message
2061 * @ingroup NYX
2062 * Nyx Number Message
2063 * @{
2064 */
2065
2066/*--------------------------------------------------------------------------------------------------------------------*/
2067
2068/**
2069 * @brief Allocates a new INDI / Nyx `int32_t` number property.
2070 * @param name Property name.
2071 * @param label Property label.
2072 * @param format Printf-style formatting string (%[flags][width]d).
2073 * @param min Range min, ignored if min == max.
2074 * @param max Range max, ignored if min == max.
2075 * @param step Step size, ignored if step == 0.
2076 * @param value Initial `int32_t` value.
2077 * @return The new property object.
2078 */
2079
2081 STR_t name,
2082 __NYX_NULLABLE__ STR_t label,
2083 STR_t format,
2084 int32_t min,
2085 int32_t max,
2086 int32_t step,
2087 int32_t value
2088);
2089
2090/*--------------------------------------------------------------------------------------------------------------------*/
2091
2092/**
2093 * @brief Allocates a new INDI / Nyx `uint32_t` number property.
2094 * @param name Property name.
2095 * @param label Property label.
2096 * @param format Printf-style formatting string (%[flags][width]{uoxX}).
2097 * @param min Range min, ignored if min == max.
2098 * @param max Range max, ignored if min == max.
2099 * @param step Step size, ignored if step == 0.
2100 * @param value Initial `uint32_t` value.
2101 * @return The new property object.
2102 */
2103
2105 STR_t name,
2106 __NYX_NULLABLE__ STR_t label,
2107 STR_t format,
2108 uint32_t min,
2109 uint32_t max,
2110 uint32_t step,
2111 uint32_t value
2112);
2113
2114/*--------------------------------------------------------------------------------------------------------------------*/
2115
2116/**
2117 * @brief Allocates a new INDI / Nyx `int64_t` number property.
2118 * @param name Property name.
2119 * @param label Property label.
2120 * @param format Printf-style formatting string (%[flags][width]ld).
2121 * @param min Range min, ignored if min == max.
2122 * @param max Range max, ignored if min == max.
2123 * @param step Step size, ignored if step == 0.
2124 * @param value Initial `int64_t` value.
2125 * @return The new property object.
2126 */
2127
2129 STR_t name,
2130 __NYX_NULLABLE__ STR_t label,
2131 STR_t format,
2132 int64_t min,
2133 int64_t max,
2134 int64_t step,
2135 int64_t value
2136);
2137
2138/*--------------------------------------------------------------------------------------------------------------------*/
2139
2140/**
2141 * @brief Allocates a new INDI / Nyx `uint64_t` number property.
2142 * @param name Property name.
2143 * @param label Property label.
2144 * @param format Printf-style formatting string (%[flags][width]l{uoxX}).
2145 * @param min Range min, ignored if min == max.
2146 * @param max Range max, ignored if min == max.
2147 * @param step Step size, ignored if step == 0.
2148 * @param value Initial `uint64_t` value.
2149 * @return The new property object.
2150 */
2151
2153 STR_t name,
2154 __NYX_NULLABLE__ STR_t label,
2155 STR_t format,
2156 uint64_t min,
2157 uint64_t max,
2158 uint64_t step,
2159 uint64_t value
2160);
2161
2162/*--------------------------------------------------------------------------------------------------------------------*/
2163
2164/**
2165 * @brief Allocates a new INDI / Nyx `double` number property.
2166 * @param name Property name.
2167 * @param label Property label.
2168 * @param format Printf-style formatting string (%[flags][width]l?{fFeEgGaAm}).
2169 * @param min Range min, ignored if min == max.
2170 * @param max Range max, ignored if min == max.
2171 * @param step Step size, ignored if step == 0.
2172 * @param value Initial `double` value.
2173 * @return The new property object.
2174 */
2175
2177 STR_t name,
2178 __NYX_NULLABLE__ STR_t label,
2179 STR_t format,
2180 double min,
2181 double max,
2182 double step,
2183 double value
2184);
2185
2186/*--------------------------------------------------------------------------------------------------------------------*/
2187
2188/**
2189 * @brief Sets the new value of the provided property object.
2190 * @param prop Property object.
2191 * @param value New value.
2192 * @return `true` if the value was modified, `false` otherwise.
2193 */
2194
2196 nyx_dict_t *prop,
2197 int32_t value
2198);
2199
2200/*--------------------------------------------------------------------------------------------------------------------*/
2201
2202/**
2203 * @brief Gets the value of the provided property object.
2204 * @param prop Property object.
2205 * @return The value.
2206 */
2207
2209 const nyx_dict_t *prop
2210);
2211
2212/*--------------------------------------------------------------------------------------------------------------------*/
2213
2214/**
2215 * @brief Sets the new value of the provided property object.
2216 * @param prop Property object.
2217 * @param value New value.
2218 * @return `true` if the value was modified, `false` otherwise.
2219 */
2220
2222 nyx_dict_t *prop,
2223 uint32_t value
2224);
2225
2226/*--------------------------------------------------------------------------------------------------------------------*/
2227
2228/**
2229 * @brief Gets the value of the provided property object.
2230 * @param prop Property object.
2231 * @return The value.
2232 */
2233
2235 const nyx_dict_t *prop
2236);
2237
2238/*--------------------------------------------------------------------------------------------------------------------*/
2239
2240/**
2241 * @brief Sets the new value of the provided property object.
2242 * @param prop Property object.
2243 * @param value New value.
2244 * @return `true` if the value was modified, `false` otherwise.
2245 */
2246
2248 nyx_dict_t *prop,
2249 int64_t value
2250);
2251
2252/*--------------------------------------------------------------------------------------------------------------------*/
2253
2254/**
2255 * @brief Gets the value of the provided property object.
2256 * @param prop Property object.
2257 * @return The value.
2258 */
2259
2261 const nyx_dict_t *prop
2262);
2263
2264/*--------------------------------------------------------------------------------------------------------------------*/
2265
2266/**
2267 * @brief Sets the new value of the provided property object.
2268 * @param prop Property object.
2269 * @param value New value.
2270 * @return `true` if the value was modified, `false` otherwise.
2271 */
2272
2274 nyx_dict_t *prop,
2275 uint64_t value
2276);
2277
2278/*--------------------------------------------------------------------------------------------------------------------*/
2279
2280/**
2281 * @brief Gets the value of the provided property object.
2282 * @param prop Property object.
2283 * @return The value.
2284 */
2285
2287 const nyx_dict_t *prop
2288);
2289
2290/*--------------------------------------------------------------------------------------------------------------------*/
2291
2292/**
2293 * @brief Sets the new value of the provided property object.
2294 * @param prop Property object.
2295 * @param value New value.
2296 * @return `true` if the value was modified, `false` otherwise.
2297 */
2298
2300 nyx_dict_t *prop,
2301 double value
2302);
2303
2304/*--------------------------------------------------------------------------------------------------------------------*/
2305
2306/**
2307 * @brief Gets the value of the provided property object.
2308 * @param prop Property object.
2309 * @return The value.
2310 */
2311
2313 const nyx_dict_t *prop
2314);
2315
2316/*--------------------------------------------------------------------------------------------------------------------*/
2317
2318/**
2319 * @brief Allocates a new INDI / Nyx number vector.
2320 * @param device Device name.
2321 * @param name Vector name.
2322 * @param state Vector state.
2323 * @param perm Vector permissions.
2324 * @param props Array of properties with `NULL` sentinel.
2325 * @param opts Options (group, label, hints, timeout, message).
2326 * @return The new vector object.
2327 */
2328
2330 STR_t device,
2331 STR_t name,
2332 nyx_state_t state,
2333 nyx_perm_t perm,
2334 nyx_dict_t *props[],
2335 __NYX_NULLABLE__ const nyx_opts_t *opts
2336);
2337
2338/*--------------------------------------------------------------------------------------------------------------------*/
2339
2340/**
2341 * @private
2342 */
2343
2344nyx_dict_t *nyx_number_set_vector_new(
2345 const nyx_dict_t *vector
2346);
2347
2348/*--------------------------------------------------------------------------------------------------------------------*/
2349/** @}
2350 * @defgroup NYX_TEXT Nyx Text Message
2351 * @ingroup NYX
2352 * Nyx Text Message
2353 * @{
2354 */
2355/*--------------------------------------------------------------------------------------------------------------------*/
2356
2357/**
2358 * @brief Allocates a new INDI / Nyx text property.
2359 * @param name Property name.
2360 * @param label Property label.
2361 * @param value Initial text value.
2362 * @param managed If `true`, ownership of the provided value is transferred to the property object.
2363 * @return The new property object.
2364 */
2365
2367 STR_t name,
2368 __NYX_NULLABLE__ STR_t label,
2369 __NYX_NULLABLE__ STR_t value,
2370 bool managed
2371);
2372
2373/*--------------------------------------------------------------------------------------------------------------------*/
2374
2375/**
2376 * @brief Sets the text value of the provided property object.
2377 * @param prop Property object.
2378 * @param value Text value.
2379 * @param managed If `true`, ownership of the provided value is transferred to the property object.
2380 * @return `true` if the value was modified, `false` otherwise.
2381 */
2382
2384 const nyx_dict_t *prop,
2385 __NYX_NULLABLE__ STR_t value,
2386 bool managed
2387);
2388
2389/*--------------------------------------------------------------------------------------------------------------------*/
2390
2391/**
2392 * @brief Gets the text value of the provided property object.
2393 * @param prop Property object.
2394 * @return The text value.
2395 * @note The returned text value remains valid until the property object is modified or released.
2396 */
2397
2399 const nyx_dict_t *prop
2400);
2401
2402/*--------------------------------------------------------------------------------------------------------------------*/
2403
2404/**
2405 * @brief Allocates a new INDI / Nyx text vector.
2406 * @param device Device name.
2407 * @param name Vector name.
2408 * @param state Vector state.
2409 * @param perm Vector permissions.
2410 * @param props Array of properties with `NULL` sentinel.
2411 * @param opts Options (group, label, hints, timeout, message).
2412 * @return The new vector object.
2413 */
2414
2416 STR_t device,
2417 STR_t name,
2418 nyx_state_t state,
2419 nyx_perm_t perm,
2420 nyx_dict_t *props[],
2421 __NYX_NULLABLE__ const nyx_opts_t *opts
2422);
2423
2424/*--------------------------------------------------------------------------------------------------------------------*/
2425
2426/**
2427 * @private
2428 */
2429
2430nyx_dict_t *nyx_text_set_vector_new(
2431 const nyx_dict_t *vector
2432);
2433
2434/*--------------------------------------------------------------------------------------------------------------------*/
2435/** @}
2436 * @defgroup NYX_LIGHT Nyx Light Message
2437 * @ingroup NYX
2438 * Nyx Light Message
2439 * @{
2440 */
2441/*--------------------------------------------------------------------------------------------------------------------*/
2442
2443/**
2444 * @brief Allocates a new INDI / Nyx light property.
2445 * @param name Property name.
2446 * @param label Property label.
2447 * @param value Initial value.
2448 * @return The new property object.
2449 */
2450
2452 STR_t name,
2453 __NYX_NULLABLE__ STR_t label,
2454 nyx_state_t value
2455);
2456
2457/*--------------------------------------------------------------------------------------------------------------------*/
2458
2459/**
2460 * @brief Sets the new value of the provided property object.
2461 * @param prop Property object.
2462 * @param value New value.
2463 * @return `true` if the value was modified, `false` otherwise.
2464 */
2465
2467 const nyx_dict_t *prop,
2468 nyx_state_t value
2469);
2470
2471/*--------------------------------------------------------------------------------------------------------------------*/
2472
2473/**
2474 * @brief Gets the value of the provided property object.
2475 * @param prop Property object.
2476 * @return The value.
2477 */
2478
2480 const nyx_dict_t *prop
2481);
2482
2483/*--------------------------------------------------------------------------------------------------------------------*/
2484
2485/**
2486 * @brief Allocates a new INDI / Nyx light vector.
2487 * @param device Device name.
2488 * @param name Vector name.
2489 * @param state Vector state.
2490 * @param props Array of properties with `NULL` sentinel.
2491 * @param opts Options (group, label, hints, timeout, message).
2492 * @return The new vector object.
2493 */
2494
2496 STR_t device,
2497 STR_t name,
2498 nyx_state_t state,
2499 nyx_dict_t *props[],
2500 __NYX_NULLABLE__ const nyx_opts_t *opts
2501);
2502
2503/*--------------------------------------------------------------------------------------------------------------------*/
2504
2505/**
2506 * @private
2507 */
2508
2509nyx_dict_t *nyx_light_set_vector_new(
2510 const nyx_dict_t *vector
2511);
2512
2513/*--------------------------------------------------------------------------------------------------------------------*/
2514/** @}
2515 * @defgroup NYX_SWITCH Nyx Switch Message
2516 * @ingroup NYX
2517 * Nyx Switch Message
2518 * @{
2519 */
2520/*--------------------------------------------------------------------------------------------------------------------*/
2521
2522/**
2523 * @brief Allocates a new INDI / Nyx switch property.
2524 * @param name Property name.
2525 * @param label Property label.
2526 * @param value Initial value.
2527 * @return The new property object.
2528 */
2529
2531 STR_t name,
2532 __NYX_NULLABLE__ STR_t label,
2533 nyx_onoff_t value
2534);
2535
2536/*--------------------------------------------------------------------------------------------------------------------*/
2537
2538/**
2539 * @brief Sets the new value of the provided property object.
2540 * @param prop Property object.
2541 * @param value New value.
2542 * @return `true` if the value was modified, `false` otherwise.
2543 */
2544
2546 const nyx_dict_t *prop,
2547 nyx_onoff_t value
2548);
2549
2550/*--------------------------------------------------------------------------------------------------------------------*/
2551
2552/**
2553 * @brief Gets the value of the provided property object.
2554 * @param prop Property object.
2555 * @return The value.
2556 */
2557
2559 const nyx_dict_t *prop
2560);
2561
2562/*--------------------------------------------------------------------------------------------------------------------*/
2563
2564/**
2565 * @brief Allocates a new INDI / Nyx switch vector.
2566 * @param device Device name.
2567 * @param name Vector name.
2568 * @param state Vector state.
2569 * @param perm Vector permissions.
2570 * @param rule Vector rules.
2571 * @param props Array of properties with `NULL` sentinel.
2572 * @param opts Options (group, label, hints, timeout, message).
2573 * @return The new vector object.
2574 */
2575
2577 STR_t device,
2578 STR_t name,
2579 nyx_state_t state,
2580 nyx_perm_t perm,
2581 nyx_rule_t rule,
2582 nyx_dict_t *props[],
2583 __NYX_NULLABLE__ const nyx_opts_t *opts
2584);
2585
2586/*--------------------------------------------------------------------------------------------------------------------*/
2587
2588/**
2589 * @private
2590 */
2591
2592nyx_dict_t *nyx_switch_set_vector_new(
2593 const nyx_dict_t *vector
2594);
2595
2596/*--------------------------------------------------------------------------------------------------------------------*/
2597/** @}
2598 * @defgroup NYX_BLOB Nyx BLOB Message
2599 * @ingroup NYX
2600 * Nyx BLOB Message
2601 * @{
2602 */
2603/*--------------------------------------------------------------------------------------------------------------------*/
2604
2605/**
2606 * @brief Allocates a new INDI / Nyx BLOB property.
2607 * @param name Property name.
2608 * @param label Property label.
2609 * @param format Payload format.
2610 * @param size Number of initial payload bytes.
2611 * @param buff Initial payload buffer.
2612 * @param managed If `true`, ownership of the provided buffer is transferred to the property object.
2613 * @return The new property object.
2614 * @note If a format ends with `.z`, the payload is automatically ZLib+Base64-compressed, otherwise, the payload is automatically Base64-encoded.
2615 */
2616
2618 STR_t name,
2619 __NYX_NULLABLE__ STR_t label,
2620 __NYX_NULLABLE__ STR_t format,
2621 __NYX_ZEROABLE__ size_t size,
2622 __NYX_NULLABLE__ BUFF_t buff,
2623 bool managed
2624);
2625
2626/*--------------------------------------------------------------------------------------------------------------------*/
2627
2628/**
2629 * @brief Sets the payload of the provided property object.
2630 * @param prop Property object.
2631 * @param size Number of payload bytes.
2632 * @param buff Payload buffer.
2633 * @param managed If `true`, ownership of the provided buffer is transferred to the object.
2634 * @return `true` if the value was modified, `false` otherwise.
2635 */
2636
2638 const nyx_dict_t *prop,
2639 __NYX_ZEROABLE__ size_t size,
2640 __NYX_NULLABLE__ BUFF_t buff,
2641 bool managed
2642);
2643
2644/*--------------------------------------------------------------------------------------------------------------------*/
2645
2646/**
2647 * @brief Gets the payload of the provided property object.
2648 * @param prop Property object.
2649 * @param size Optional pointer receiving the number of payload bytes.
2650 * @param buff Optional pointer receiving the payload buffer.
2651 * @note The returned buffer remains valid until the property object is modified or released.
2652 */
2653
2655 const nyx_dict_t *prop,
2656 __NYX_NULLABLE__ size_t *size,
2657 __NYX_NULLABLE__ buff_t *buff
2658);
2659
2660/*--------------------------------------------------------------------------------------------------------------------*/
2661
2662/**
2663 * @brief Allocates a new INDI / Nyx BLOB vector.
2664 * @param device Device name.
2665 * @param name Vector name.
2666 * @param state Vector state.
2667 * @param perm Vector permissions.
2668 * @param props Array of properties with `NULL` sentinel.
2669 * @param opts Options (group, label, hints, timeout, message).
2670 * @return The new vector object.
2671 */
2672
2674 STR_t device,
2675 STR_t name,
2676 nyx_state_t state,
2677 nyx_perm_t perm,
2678 nyx_dict_t *props[],
2679 __NYX_NULLABLE__ const nyx_opts_t *opts
2680);
2681
2682/*--------------------------------------------------------------------------------------------------------------------*/
2683
2684/**
2685 * @private
2686 */
2687
2688nyx_dict_t *nyx_blob_set_vector_new(
2689 const nyx_dict_t *vector
2690);
2691
2692/*--------------------------------------------------------------------------------------------------------------------*/
2693/** @}
2694 * @defgroup NYX_STREAM Nyx Stream Message
2695 * @ingroup NYX
2696 * Nyx Stream Message
2697 * @{
2698 */
2699/*--------------------------------------------------------------------------------------------------------------------*/
2700
2701/**
2702 * @brief Allocates a new Nyx Stream property.
2703 * @param name Property name.
2704 * @param label Property label.
2705 * @return The new property object.
2706 * @note If the property name ends with `.b`, the payload is automatically Base64-encoded.
2707 * @note If the property name ends with `.z`, the payload is automatically ZLib-compressed.
2708 */
2709
2711 STR_t name,
2712 __NYX_NULLABLE__ STR_t label
2713);
2714
2715/*--------------------------------------------------------------------------------------------------------------------*/
2716
2717/**
2718 * @brief Allocates a new Nyx Stream vector.
2719 * @param device Device name.
2720 * @param name Vector name.
2721 * @param state Vector state.
2722 * @param props Array of properties with `NULL` sentinel.
2723 * @param opts Options (group, label, hints, timeout, message).
2724 * @return The new vector object.
2725 */
2726
2728 STR_t device,
2729 STR_t name,
2730 nyx_state_t state,
2731 nyx_dict_t *props[],
2732 __NYX_NULLABLE__ const nyx_opts_t *opts
2733);
2734
2735/*--------------------------------------------------------------------------------------------------------------------*/
2736
2737/**
2738 * @brief If Nyx Stream is enabled, publishes an entry to a stream.
2739 * @param vector Nyx stream vector.
2740 * @param n_fields Number of fields. Must match the number of properties in the vector.
2741 * @param field_sizes Array of payload byte counts, one per field.
2742 * @param field_buffs Array of payload buffers, one per field.
2743 * @return `true` if the provided fields match the vector content, `false` otherwise.
2744 * @note Field payloads may contain arbitrary binary data.
2745 */
2746
2748 const nyx_dict_t *vector,
2749 __NYX_ZEROABLE__ size_t n_fields,
2750 const size_t field_sizes[],
2751 const buff_t field_buffs[]
2752);
2753
2754/*--------------------------------------------------------------------------------------------------------------------*/
2755
2756/**
2757 * @private
2758 */
2759
2760nyx_dict_t *nyx_stream_set_vector_new(
2761 const nyx_dict_t *vector
2762);
2763
2764/*--------------------------------------------------------------------------------------------------------------------*/
2765/** @}
2766 * @defgroup NYX_MESSAGE Other Nyx Messages
2767 * @ingroup NYX
2768 * Other Nyx Messages
2769 * @{
2770 */
2771/*--------------------------------------------------------------------------------------------------------------------*/
2772
2773/**
2774 * @brief Allocates a new INDI / Nyx human-oriented message object.
2775 * @param device Device name.
2776 * @param message Human-oriented message.
2777 * @return The new human-oriented message object.
2778 * @note Prefer using @ref nyx_node_send_message.
2779 */
2780
2782 STR_t device,
2783 __NYX_NULLABLE__ STR_t message
2784);
2785
2786/*--------------------------------------------------------------------------------------------------------------------*/
2787
2788/**
2789 * @brief Allocates a new INDI / Nyx `delete-property` message object.
2790 * @param device Device name.
2791 * @param name Optional vector name (`NULL` means the whole device).
2792 * @param message Optional human-oriented message.
2793 * @return The new `delete-property` message object.
2794 * @note Prefer using @ref nyx_node_send_del_property.
2795 */
2796
2798 STR_t device,
2799 __NYX_NULLABLE__ STR_t name,
2800 __NYX_NULLABLE__ STR_t message
2801);
2802
2803/*--------------------------------------------------------------------------------------------------------------------*/
2804/* NODE */
2805/*--------------------------------------------------------------------------------------------------------------------*/
2806/** @}
2807 * @defgroup NODE Nyx node
2808 * Nyx node.
2809 * @{
2810 */
2811/*--------------------------------------------------------------------------------------------------------------------*/
2812
2813/**
2814 * @struct nyx_node_t
2815 * @brief Opaque struct describing a Nyx node.
2816 */
2817
2818typedef struct nyx_node_s nyx_node_t;
2819
2820/*--------------------------------------------------------------------------------------------------------------------*/
2821
2822/**
2823 * @memberof nyx_node_t
2824 * @brief TCP or MQTT event type.
2825 */
2826
2827typedef enum
2828{
2829 NYX_NODE_EVENT_OPEN = 1100, //!< A connection is opened.
2830 NYX_NODE_EVENT_MSG = 1101, //!< A message is received.
2831
2832} nyx_event_type_t;
2833
2834/*--------------------------------------------------------------------------------------------------------------------*/
2835
2836/**
2837 * @memberof nyx_node_t
2838 * @brief MQTT event handler.
2839 * @param node Nyx node.
2840 * @param event_type Event type.
2841 * @param topic_size Number of MQTT topic bytes.
2842 * @param topic_buff MQTT topic buffer.
2843 * @param message_size Number of message payload bytes.
2844 * @param message_buff Message payload buffer.
2845 * @note The message payload may contain arbitrary binary data.
2846 */
2847
2848typedef void (* nyx_mqtt_handler_t)(
2849 nyx_node_t *node,
2850 nyx_event_type_t event_type,
2851 size_t topic_size,
2852 BUFF_t topic_buff,
2853 size_t message_size,
2854 BUFF_t message_buff
2855);
2856
2857/*--------------------------------------------------------------------------------------------------------------------*/
2858
2859/**
2860 * @memberof nyx_node_t
2861 * @brief Allocates and initializes a new Nyx node.
2862 * @param node_id Unique node identifier.
2863 * @param vectors Array of vectors with `NULL` sentinel.
2864 * @param indi_url Optional INDI URL (e.g., tcp://0.0.0.0:7625).
2865 * @param mqtt_url Optional MQTT URL (e.g., mqtt://localhost:1883).
2866 * @param nss_url Optional Nyx Stream URL (e.g., tcp://localhost:6379).
2867 * @param mqtt_username Optional MQTT username.
2868 * @param mqtt_password Optional MQTT password.
2869 * @param mqtt_handler Optional MQTT handler.
2870 * @param retry_ms Connect retry time [milliseconds].
2871 * @param enable_xml Enables the XML messages for INDI compatibility.
2872 * @return The new Nyx node.
2873 */
2874
2876 STR_t node_id,
2877 nyx_dict_t *vectors[],
2878 /**/
2879 __NYX_NULLABLE__ STR_t indi_url,
2880 __NYX_NULLABLE__ STR_t mqtt_url,
2881 __NYX_NULLABLE__ STR_t nss_url,
2882 /**/
2883 __NYX_NULLABLE__ STR_t mqtt_username,
2884 __NYX_NULLABLE__ STR_t mqtt_password,
2885 /**/
2886 __NYX_NULLABLE__ nyx_mqtt_handler_t mqtt_handler,
2887 /**/
2888 uint32_t retry_ms,
2889 bool enable_xml
2890);
2891
2892/*--------------------------------------------------------------------------------------------------------------------*/
2893
2894/**
2895 * @memberof nyx_node_t
2896 * @brief Finalizes a Nyx node.
2897 * @param node Nyx node.
2898 * @param free_vectors If `true`, the previously registered vectors are freed.
2899 */
2900
2902 nyx_node_t *node,
2903 bool free_vectors
2904);
2905
2906/*--------------------------------------------------------------------------------------------------------------------*/
2907
2908/**
2909 * @memberof nyx_node_t
2910 * @brief Adds a new timer.
2911 * @param node Nyx node.
2912 * @param interval_ms Interval [milliseconds].
2913 * @param callback Callback to be invoked.
2914 * @param arg Callback argument.
2915 * @note Timers are triggered by the @ref nyx_node_poll method.
2916 */
2917
2919 const nyx_node_t *node,
2920 uint32_t interval_ms,
2921 void(* callback)(void *),
2922 void *arg
2923);
2924
2925/*--------------------------------------------------------------------------------------------------------------------*/
2926
2927/**
2928 * @memberof nyx_node_t
2929 * @brief Performs a single poll iteration.
2930 * @param node Nyx node.
2931 * @param timeout_ms Timeout [milliseconds].
2932 * @note \c timeout_ms determines the minimum timer resolution.
2933 */
2934
2935void nyx_node_poll(
2936 const nyx_node_t *node,
2937 uint32_t timeout_ms
2938);
2939
2940/*--------------------------------------------------------------------------------------------------------------------*/
2941
2942/**
2943 * @memberof nyx_node_t
2944 * @brief Enables a device or a vector and notifies clients.
2945 * @param node Nyx node.
2946 * @param device Device name.
2947 * @param name Optional vector name (`NULL` means the whole device).
2948 * @param message Optional human-oriented message.
2949 */
2950
2952 const nyx_node_t *node,
2953 /*------------*/ STR_t device,
2954 __NYX_NULLABLE__ STR_t name,
2955 __NYX_NULLABLE__ STR_t message
2956);
2957
2958/*--------------------------------------------------------------------------------------------------------------------*/
2959
2960/**
2961 * @memberof nyx_node_t
2962 * @brief Disables a device or a vector and notifies clients.
2963 * @param node Nyx node.
2964 * @param device Device name.
2965 * @param name Optional vector name (`NULL` means the whole device).
2966 * @param message Optional human-oriented message.
2967 */
2968
2970 const nyx_node_t *node,
2971 /*------------*/ STR_t device,
2972 __NYX_NULLABLE__ STR_t name,
2973 __NYX_NULLABLE__ STR_t message
2974);
2975
2976/*--------------------------------------------------------------------------------------------------------------------*/
2977
2978/**
2979 * @memberof nyx_node_t
2980 * @brief Sends a human-oriented message to the clients.
2981 * @param node Nyx node.
2982 * @param device Device name.
2983 * @param message Human-oriented message.
2984 * @anchor nyx_node_send_message
2985 */
2986
2988 const nyx_node_t *node,
2989 STR_t device,
2990 __NYX_NULLABLE__ STR_t message
2991);
2992
2993/*--------------------------------------------------------------------------------------------------------------------*/
2994
2995/**
2996 * @memberof nyx_node_t
2997 * @brief Sends a `del-property` message to the clients.
2998 * @param node Nyx node.
2999 * @param device Device name.
3000 * @param name Optional vector name (`NULL` means the whole device).
3001 * @param message Optional human-oriented message.
3002 * @anchor nyx_node_send_del_property
3003 */
3004
3006 const nyx_node_t *node,
3007 STR_t device,
3008 __NYX_NULLABLE__ STR_t name,
3009 __NYX_NULLABLE__ STR_t message
3010);
3011
3012/*--------------------------------------------------------------------------------------------------------------------*/
3013
3014/**
3015 * @memberof nyx_node_t
3016 * @brief If MQTT is enabled, subscribes to an MQTT topic.
3017 * @param node Nyx node.
3018 * @param topic MQTT topic.
3019 * @param qos MQTT Quality Of Service.
3020 * @note `mqtt_handler` has to be defined in @ref nyx_node_initialize.
3021 */
3022
3023void nyx_mqtt_sub(
3024 const nyx_node_t *node,
3025 STR_t topic,
3026 int qos
3027);
3028
3029/*--------------------------------------------------------------------------------------------------------------------*/
3030
3031/**
3032 * @memberof nyx_node_t
3033 * @brief If MQTT is enabled, publishes an MQTT message.
3034 * @param node Nyx node.
3035 * @param topic MQTT topic.
3036 * @param message_size Number of message payload bytes.
3037 * @param message_buff Message payload buffer.
3038 * @param qos MQTT Quality Of Service.
3039 * @note The message payload may contain arbitrary binary data.
3040 */
3041
3043 const nyx_node_t *node,
3044 STR_t topic,
3045 __NYX_ZEROABLE__ size_t message_size,
3046 __NYX_NULLABLE__ BUFF_t message_buff,
3047 int qos
3048);
3049
3050/*--------------------------------------------------------------------------------------------------------------------*/
3051
3052/**
3053 * @memberof nyx_node_t
3054 * @brief If Nyx Stream is enabled, publishes an entry to a stream.
3055 * @param node Nyx node.
3056 * @param device Device name.
3057 * @param stream Stream name.
3058 * @param n_fields Number of fields.
3059 * @param field_hashes Array of field name hashes, one per field.
3060 * @param field_sizes Array of payload byte counts, one per field.
3061 * @param field_buffs Array of payload buffers, one per field.
3062 * @warning Field hashes must be computed with @ref nyx_hash.
3063 * @warning Unless performance is critical, prefer using @ref nyx_stream_pub.
3064 * @note Field payloads may contain arbitrary binary data.
3065 */
3066
3068 const nyx_node_t *node,
3069 STR_t device,
3070 STR_t stream,
3071 __NYX_ZEROABLE__ size_t n_fields,
3072 const uint32_t field_hashes[],
3073 const size_t field_sizes[],
3074 const buff_t field_buffs[]
3075);
3076
3077/*--------------------------------------------------------------------------------------------------------------------*/
3078/** @} */
3079/*--------------------------------------------------------------------------------------------------------------------*/
3080
3081#if defined(__clang__) && !defined(ARDUINO)
3082# pragma clang diagnostic pop
3083#endif
3084
3085/*--------------------------------------------------------------------------------------------------------------------*/
3086
3087#ifdef __cplusplus
3088}
3089#endif
3090
3091/*--------------------------------------------------------------------------------------------------------------------*/
3092
3093#endif /* NYX_NODE_H */
3094
3095/*--------------------------------------------------------------------------------------------------------------------*/
bool value
Boolean payload.
Definition nyx_node.h:824
nyx_object_t base
Common object header for JSON objects.
Definition nyx_node.h:822
__NYX_INLINE__ nyx_boolean_t * nyx_boolean_from(bool value)
Returns a JSON boolean object holding the value of the provided argument.
Definition nyx_node.h:889
nyx_boolean_t * nyx_boolean_new(void)
Allocates a new JSON boolean object.
bool nyx_boolean_set(nyx_boolean_t *object, bool value)
Sets the value of the provided JSON boolean object.
Struct describing a JSON boolean object.
Definition nyx_node.h:821
size_t idx
Current zero-based iteration index.
Definition nyx_node.h:1113
struct nyx_dict_node_s * head
Next JSON object to visit.
Definition nyx_node.h:1115
__NYX_INLINE__ bool nyx_dict_set_number(const nyx_dict_t *dict, STR_t key, double value)
Sets a number value of an existing key holding a number.
Definition nyx_node.h:1359
__NYX_INLINE__ bool nyx_dict_set_buff(const nyx_dict_t *dict, STR_t key, size_t size, BUFF_t buff, bool managed)
Sets the content of an existing key holding a string from a byte buffer.
Definition nyx_node.h:1402
__NYX_INLINE__ bool nyx_dict_set_string(const nyx_dict_t *dict, STR_t key, STR_t value, bool managed)
Sets a text value of an existing key holding a string.
Definition nyx_node.h:1380
__NYX_INLINE__ double nyx_dict_get_number(const nyx_dict_t *dict, STR_t key)
Gets a number value of the provided key.
Definition nyx_node.h:1280
__NYX_INLINE__ STR_t nyx_dict_get_string(const nyx_dict_t *dict, STR_t key)
Gets a text value of the provided key.
Definition nyx_node.h:1300
__NYX_INLINE__ bool nyx_dict_set_boolean(const nyx_dict_t *dict, STR_t key, bool value)
Sets a boolean value of an existing key holding a boolean.
Definition nyx_node.h:1339
nyx_object_t * nyx_dict_get(const nyx_dict_t *object, STR_t key)
Gets the JSON object of the provided key.
Definition json_dict.c:159
__NYX_INLINE__ bool nyx_dict_get_boolean(const nyx_dict_t *object, STR_t key)
Gets a boolean value of the provided key.
Definition nyx_node.h:1261
__NYX_INLINE__ void nyx_dict_get_buff(const nyx_dict_t *dict, STR_t key, __NYX_NULLABLE__ size_t *result_size, __NYX_NULLABLE__ buff_t *result_buff)
Gets the content of the provided key as a byte buffer.
Definition nyx_node.h:1321
Struct describing a JSON dict iterator.
Definition nyx_node.h:1112
Struct describing a JSON dict object.
struct nyx_list_node_s * head
Next JSON object to visit.
Definition nyx_node.h:1446
size_t idx
Current zero-based iteration index.
Definition nyx_node.h:1444
__NYX_INLINE__ void nyx_list_get_buff(const nyx_list_t *list, size_t idx, __NYX_NULLABLE__ size_t *result_size, __NYX_NULLABLE__ buff_t *result_buff)
Gets the content of the provided index as a byte buffer.
Definition nyx_node.h:1662
__NYX_INLINE__ double nyx_list_get_number(const nyx_list_t *list, size_t idx)
Gets a number value at the provided index.
Definition nyx_node.h:1621
__NYX_INLINE__ bool nyx_list_push(nyx_list_t *object, void *value)
Pushes a JSON object in the provided JSON list object.
Definition nyx_node.h:1560
__NYX_INLINE__ STR_t nyx_list_get_string(const nyx_list_t *list, size_t idx)
Gets a text value at the provided index.
Definition nyx_node.h:1641
__NYX_INLINE__ bool nyx_list_get_boolean(const nyx_list_t *object, size_t idx)
Gets a boolean value at the provided index.
Definition nyx_node.h:1602
__NYX_INLINE__ bool nyx_list_set_string(const nyx_list_t *list, size_t idx, STR_t value, bool managed)
Sets a text value of an existing index holding a string.
Definition nyx_node.h:1721
__NYX_INLINE__ bool nyx_list_set_number(const nyx_list_t *list, size_t idx, double value)
Sets a number value of an existing index holding a number.
Definition nyx_node.h:1700
nyx_object_t * nyx_list_get(const nyx_list_t *object, size_t idx)
Gets the JSON object at the provided index.
Definition json_list.c:157
__NYX_INLINE__ bool nyx_list_set_boolean(const nyx_list_t *list, size_t idx, bool value)
Sets a boolean value of an existing index holding a boolean.
Definition nyx_node.h:1680
__NYX_INLINE__ bool nyx_list_set_buff(const nyx_list_t *list, size_t idx, size_t size, BUFF_t buff, bool managed)
Sets the content of an existing index holding a string from a byte buffer.
Definition nyx_node.h:1743
Struct describing a JSON list iterator.
Definition nyx_node.h:1443
Struct describing a JSON list object.
nyx_log_level_e
Nyx log levels.
Definition nyx_node.h:162
void nyx_set_log_level(nyx_log_level_t level)
Sets the log level threshold.
Definition logger.c:41
enum nyx_log_level_e nyx_log_level_t
Nyx log levels.
@ NYX_LOG_LEVEL_NONE
Logging disabled.
Definition nyx_node.h:163
@ NYX_LOG_LEVEL_ERROR
Error level.
Definition nyx_node.h:165
@ NYX_LOG_LEVEL_DEBUG
Debug level.
Definition nyx_node.h:168
@ NYX_LOG_LEVEL_TRACE
Trace level.
Definition nyx_node.h:169
@ NYX_LOG_LEVEL_INFO
Log level.
Definition nyx_node.h:167
@ NYX_LOG_LEVEL_WARN
Warning level.
Definition nyx_node.h:166
@ NYX_LOG_LEVEL_FATAL
Fatal level.
Definition nyx_node.h:164
#define STR_t
Alias for const char *.
Definition nyx_node.h:71
__NYX_NULLABLE__ buff_t nyx_memory_alloc(__NYX_ZEROABLE__ size_t size)
Similar to libc malloc except that a memory overflow causes the node to stop.
__NYX_ZEROABLE__ size_t nyx_memory_free(__NYX_NULLABLE__ buff_t buff)
Similar to libc free except that it returns the amount of memory freed.
#define buff_t
Alias for void *.
Definition nyx_node.h:67
#define BUFF_t
Alias for const void *.
Definition nyx_node.h:68
void nyx_memory_initialize(void)
Initializes the memory subsystem.
Definition object.c:37
bool nyx_memory_finalize(void)
Finalizes the memory subsystem.
Definition object.c:50
__NYX_NULLABLE__ str_t nyx_string_dup(__NYX_NULLABLE__ STR_t s)
Similar to libc strdup.
__NYX_NULLABLE__ str_t nyx_string_ndup(__NYX_NULLABLE__ STR_t s, __NYX_ZEROABLE__ size_t n)
Similar to libc strndup.
__NYX_NULLABLE__ buff_t nyx_memory_realloc(__NYX_NULLABLE__ buff_t buff, __NYX_ZEROABLE__ size_t size)
Similar to libc realloc except that a memory overflow causes the node to stop.
#define str_t
Alias for char *.
Definition nyx_node.h:70
void nyx_node_add_timer(const nyx_node_t *node, uint32_t interval_ms, void(*callback)(void *), void *arg)
Adds a new timer.
Definition mongoose.c:390
nyx_event_type_t
TCP or MQTT event type.
Definition nyx_node.h:2828
void nyx_node_send_message(const nyx_node_t *node, STR_t device, __NYX_NULLABLE__ STR_t message)
Sends a human-oriented message to the clients.
void nyx_node_disable(const nyx_node_t *node, STR_t device, __NYX_NULLABLE__ STR_t name, __NYX_NULLABLE__ STR_t message)
Disables a device or a vector and notifies clients.
void nyx_mqtt_pub(const nyx_node_t *node, STR_t topic, __NYX_ZEROABLE__ size_t message_size, __NYX_NULLABLE__ BUFF_t message_buff, int qos)
If MQTT is enabled, publishes an MQTT message.
void nyx_nss_pub(const nyx_node_t *node, STR_t device, STR_t stream, __NYX_ZEROABLE__ size_t n_fields, const uint32_t field_hashes[], const size_t field_sizes[], const buff_t field_buffs[])
If Nyx Stream is enabled, publishes an entry to a stream.
__NYX_NULLABLE__ nyx_node_t * nyx_node_initialize(STR_t node_id, nyx_dict_t *vectors[], __NYX_NULLABLE__ STR_t indi_url, __NYX_NULLABLE__ STR_t mqtt_url, __NYX_NULLABLE__ STR_t nss_url, __NYX_NULLABLE__ STR_t mqtt_username, __NYX_NULLABLE__ STR_t mqtt_password, __NYX_NULLABLE__ nyx_mqtt_handler_t mqtt_handler, uint32_t retry_ms, bool enable_xml)
Allocates and initializes a new Nyx node.
void nyx_mqtt_sub(const nyx_node_t *node, STR_t topic, int qos)
If MQTT is enabled, subscribes to an MQTT topic.
Definition mqtt.c:12
void(* nyx_mqtt_handler_t)(nyx_node_t *node, nyx_event_type_t event_type, size_t topic_size, BUFF_t topic_buff, size_t message_size, BUFF_t message_buff)
MQTT event handler.
Definition nyx_node.h:2848
void nyx_node_send_del_property(const nyx_node_t *node, STR_t device, __NYX_NULLABLE__ STR_t name, __NYX_NULLABLE__ STR_t message)
Sends a del-property message to the clients.
void nyx_node_poll(const nyx_node_t *node, uint32_t timeout_ms)
Performs a single poll iteration.
Definition mongoose.c:397
void nyx_node_finalize(nyx_node_t *node, bool free_vectors)
Finalizes a Nyx node.
Definition node.c:1030
void nyx_node_enable(const nyx_node_t *node, STR_t device, __NYX_NULLABLE__ STR_t name, __NYX_NULLABLE__ STR_t message)
Enables a device or a vector and notifies clients.
Opaque struct describing a Nyx node.
nyx_object_t base
Common object header for JSON objects.
Definition nyx_node.h:681
str_t nyx_null_to_string(const nyx_null_t *object)
Returns a string representing the provided JSON null object.
Struct describing a JSON null object.
Definition nyx_node.h:680
double value
Number payload.
Definition nyx_node.h:729
nyx_object_t base
Common object header for JSON objects.
Definition nyx_node.h:727
__NYX_INLINE__ nyx_number_t * nyx_number_from(double value)
Returns a JSON number object holding the value of the provided argument.
Definition nyx_node.h:796
nyx_number_t * nyx_number_new(void)
Allocates a new JSON number object.
Definition json_number.c:12
bool nyx_number_set(nyx_number_t *object, double value)
Sets the value of the provided JSON number object.
Definition json_number.c:47
Struct describing a JSON number object.
Definition nyx_node.h:726
nyx_dict_t * nyx_blob_prop_new(STR_t name, __NYX_NULLABLE__ STR_t label, __NYX_NULLABLE__ STR_t format, __NYX_ZEROABLE__ size_t size, __NYX_NULLABLE__ BUFF_t buff, bool managed)
Allocates a new INDI / Nyx BLOB property.
void nyx_blob_prop_get(const nyx_dict_t *prop, __NYX_NULLABLE__ size_t *size, __NYX_NULLABLE__ buff_t *buff)
Gets the payload of the provided property object.
bool nyx_blob_prop_set(const nyx_dict_t *prop, __NYX_ZEROABLE__ size_t size, __NYX_NULLABLE__ BUFF_t buff, bool managed)
Sets the payload of the provided property object.
nyx_dict_t * nyx_blob_vector_new(STR_t device, STR_t name, nyx_state_t state, nyx_perm_t perm, nyx_dict_t *props[], __NYX_NULLABLE__ const nyx_opts_t *opts)
Allocates a new INDI / Nyx BLOB vector.
nyx_dict_t * nyx_light_prop_new(STR_t name, __NYX_NULLABLE__ STR_t label, nyx_state_t value)
Allocates a new INDI / Nyx light property.
bool nyx_light_prop_set(const nyx_dict_t *prop, nyx_state_t value)
Sets the new value of the provided property object.
Definition indi_light.c:49
nyx_state_t nyx_light_prop_get(const nyx_dict_t *prop)
Gets the value of the provided property object.
Definition indi_light.c:56
nyx_dict_t * nyx_light_vector_new(STR_t device, STR_t name, nyx_state_t state, nyx_dict_t *props[], __NYX_NULLABLE__ const nyx_opts_t *opts)
Allocates a new INDI / Nyx light vector.
nyx_dict_t * nyx_message_new(STR_t device, __NYX_NULLABLE__ STR_t message)
Allocates a new INDI / Nyx human-oriented message object.
nyx_dict_t * nyx_del_property_new(STR_t device, __NYX_NULLABLE__ STR_t name, __NYX_NULLABLE__ STR_t message)
Allocates a new INDI / Nyx delete-property message object.
nyx_dict_t * nyx_number_prop_new_int(STR_t name, __NYX_NULLABLE__ STR_t label, STR_t format, int32_t min, int32_t max, int32_t step, int32_t value)
Allocates a new INDI / Nyx int32_t number property.
int64_t nyx_number_prop_get_long(const nyx_dict_t *prop)
Gets the value of the provided property object.
int32_t nyx_number_prop_get_int(const nyx_dict_t *prop)
Gets the value of the provided property object.
nyx_dict_t * nyx_number_prop_new_long(STR_t name, __NYX_NULLABLE__ STR_t label, STR_t format, int64_t min, int64_t max, int64_t step, int64_t value)
Allocates a new INDI / Nyx int64_t number property.
nyx_dict_t * nyx_number_prop_new_double(STR_t name, __NYX_NULLABLE__ STR_t label, STR_t format, double min, double max, double step, double value)
Allocates a new INDI / Nyx double number property.
nyx_dict_t * nyx_number_prop_new_ulong(STR_t name, __NYX_NULLABLE__ STR_t label, STR_t format, uint64_t min, uint64_t max, uint64_t step, uint64_t value)
Allocates a new INDI / Nyx uint64_t number property.
bool nyx_number_prop_set_int(nyx_dict_t *prop, int32_t value)
Sets the new value of the provided property object.
Definition indi_number.c:90
double nyx_number_prop_get_double(const nyx_dict_t *prop)
Gets the value of the provided property object.
uint64_t nyx_number_prop_get_ulong(const nyx_dict_t *prop)
Gets the value of the provided property object.
bool nyx_number_prop_set_ulong(nyx_dict_t *prop, uint64_t value)
Sets the new value of the provided property object.
nyx_dict_t * nyx_number_prop_new_uint(STR_t name, __NYX_NULLABLE__ STR_t label, STR_t format, uint32_t min, uint32_t max, uint32_t step, uint32_t value)
Allocates a new INDI / Nyx uint32_t number property.
bool nyx_number_prop_set_long(nyx_dict_t *prop, int64_t value)
Sets the new value of the provided property object.
bool nyx_number_prop_set_uint(nyx_dict_t *prop, uint32_t value)
Sets the new value of the provided property object.
Definition indi_number.c:95
nyx_dict_t * nyx_number_vector_new(STR_t device, STR_t name, nyx_state_t state, nyx_perm_t perm, nyx_dict_t *props[], __NYX_NULLABLE__ const nyx_opts_t *opts)
Allocates a new INDI / Nyx number vector.
uint32_t nyx_number_prop_get_uint(const nyx_dict_t *prop)
Gets the value of the provided property object.
bool nyx_number_prop_set_double(nyx_dict_t *prop, double value)
Sets the new value of the provided property object.
nyx_dict_t * nyx_stream_vector_new(STR_t device, STR_t name, nyx_state_t state, nyx_dict_t *props[], __NYX_NULLABLE__ const nyx_opts_t *opts)
Allocates a new Nyx Stream vector.
nyx_dict_t * nyx_stream_prop_new(STR_t name, __NYX_NULLABLE__ STR_t label)
Allocates a new Nyx Stream property.
bool nyx_stream_pub(const nyx_dict_t *vector, __NYX_ZEROABLE__ size_t n_fields, const size_t field_sizes[], const buff_t field_buffs[])
If Nyx Stream is enabled, publishes an entry to a stream.
bool nyx_switch_prop_set(const nyx_dict_t *prop, nyx_onoff_t value)
Sets the new value of the provided property object.
Definition indi_switch.c:49
nyx_dict_t * nyx_switch_vector_new(STR_t device, STR_t name, nyx_state_t state, nyx_perm_t perm, nyx_rule_t rule, nyx_dict_t *props[], __NYX_NULLABLE__ const nyx_opts_t *opts)
Allocates a new INDI / Nyx switch vector.
nyx_dict_t * nyx_switch_prop_new(STR_t name, __NYX_NULLABLE__ STR_t label, nyx_onoff_t value)
Allocates a new INDI / Nyx switch property.
nyx_onoff_t nyx_switch_prop_get(const nyx_dict_t *prop)
Gets the value of the provided property object.
Definition indi_switch.c:56
STR_t nyx_text_prop_get(const nyx_dict_t *prop)
Gets the text value of the provided property object.
Definition indi_text.c:70
nyx_dict_t * nyx_text_vector_new(STR_t device, STR_t name, nyx_state_t state, nyx_perm_t perm, nyx_dict_t *props[], __NYX_NULLABLE__ const nyx_opts_t *opts)
Allocates a new INDI / Nyx text vector.
nyx_dict_t * nyx_text_prop_new(STR_t name, __NYX_NULLABLE__ STR_t label, __NYX_NULLABLE__ STR_t value, bool managed)
Allocates a new INDI / Nyx text property.
bool nyx_text_prop_set(const nyx_dict_t *prop, __NYX_NULLABLE__ STR_t value, bool managed)
Sets the text value of the provided property object.
__NYX_ZEROABLE__ double timeout
Worst-case time [sec] to apply, 0 by default, N/A for RO.
Definition nyx_node.h:2054
__NYX_NULLABLE__ STR_t label
GUI label, if NULL, replaced by the device name.
Definition nyx_node.h:2051
__NYX_NULLABLE__ STR_t hints
GUI Markdown description.
Definition nyx_node.h:2052
__NYX_NULLABLE__ STR_t message
Free comment.
Definition nyx_node.h:2053
__NYX_NULLABLE__ STR_t group
GUI group membership, if NULL, replaced by "Main".
Definition nyx_node.h:2050
nyx_perm_t
Vector permission hint.
Definition nyx_node.h:1948
nyx_state_t
Vector state hint.
Definition nyx_node.h:1913
nyx_onoff_t
Switch state.
Definition nyx_node.h:2016
nyx_rule_t
Switch vector rule hint.
Definition nyx_node.h:1982
@ NYX_PERM_RW
Read & write.
Definition nyx_node.h:1951
@ NYX_PERM_WO
Write only.
Definition nyx_node.h:1950
@ NYX_PERM_RO
Read only.
Definition nyx_node.h:1949
@ NYX_STATE_IDLE
State is idle.
Definition nyx_node.h:1914
@ NYX_STATE_BUSY
State is busy.
Definition nyx_node.h:1916
@ NYX_STATE_OK
State is ok.
Definition nyx_node.h:1915
@ NYX_STATE_ALERT
State is alert.
Definition nyx_node.h:1917
@ NYX_ONOFF_ON
Switch is ON.
Definition nyx_node.h:2017
@ NYX_ONOFF_OFF
Switch is OFF.
Definition nyx_node.h:2018
@ NYX_RULE_ONE_OF_MANY
Only one switch of many can be ON (e.g., radio buttons).
Definition nyx_node.h:1983
@ NYX_RULE_ANY_OF_MANY
Any number of switches can be ON (e.g., check boxes).
Definition nyx_node.h:1985
@ NYX_RULE_AT_MOST_ONE
At most one switch can be ON, but all switches can be OFF.
Definition nyx_node.h:1984
Struct describing the options for INDI / Nyx vectors.
Definition nyx_node.h:2049
str_t nyx_object_to_cstring(__NYX_NULLABLE__ const nyx_object_t *object)
Returns a C string, without special character escaping, representing the provided JSON object.
__NYX_NULLABLE__ nyx_object_t * nyx_object_ref(__NYX_NULLABLE__ void *object)
Increments the reference counter of the provided JSON object.
__NYX_NULLABLE__ nyx_object_t * nyx_object_unref(__NYX_NULLABLE__ void *object)
Decrements the reference counter of the provided JSON object and frees it when it reaches zero.
nyx_type_t
JSON object types.
Definition nyx_node.h:433
bool nyx_object_notify(__NYX_NULLABLE__ const nyx_object_t *object)
Notifies the provided Nyx / INDI object to the clients.
__NYX_NULLABLE__ nyx_object_t * nyx_object_parse(__NYX_NULLABLE__ STR_t string)
Parses a JSON object from a C string.
bool nyx_object_equal(__NYX_NULLABLE__ const nyx_object_t *object1, __NYX_NULLABLE__ const nyx_object_t *object2)
Compares two JSON objects.
__NYX_NULLABLE__ nyx_object_t * nyx_object_parse_buff(__NYX_ZEROABLE__ size_t size, __NYX_NULLABLE__ BUFF_t buff)
Parses a JSON object from a string buffer.
str_t nyx_object_to_string(__NYX_NULLABLE__ const nyx_object_t *object)
Returns a string, with the special character escaping, representing the provided JSON object.
#define NYX_OBJECT_MAGIC
Magic number for identifying JSON objects.
Definition nyx_node.h:413
nyx_type_t nyx_object_get_type(__NYX_NULLABLE__ const nyx_object_t *object)
Gets the type of the provided JSON object.
@ NYX_TYPE_DICT
Dict object.
Definition nyx_node.h:438
@ NYX_TYPE_LIST
List object.
Definition nyx_node.h:439
@ NYX_TYPE_BOOLEAN
Boolean object.
Definition nyx_node.h:435
@ NYX_TYPE_NUMBER
Number object.
Definition nyx_node.h:436
@ NYX_TYPE_NULL
Null object.
Definition nyx_node.h:434
@ NYX_TYPE_STRING
String object.
Definition nyx_node.h:437
Struct describing a JSON object.
str_t value
C string payload.
Definition nyx_node.h:919
nyx_object_t base
Common object header for JSON objects.
Definition nyx_node.h:915
size_t length
C string length excluding NULL.
Definition nyx_node.h:918
bool managed
true if the value is freed with this object.
Definition nyx_node.h:917
void nyx_string_get_buff(const nyx_string_t *object, __NYX_NULLABLE__ size_t *result_size, __NYX_NULLABLE__ buff_t *result_buff)
Gets the content of the provided JSON string object as a byte buffer.
size_t nyx_string_length(const nyx_string_t *object)
Returns the number of content bytes of the provided JSON string object.
__NYX_INLINE__ nyx_string_t * nyx_string_from_buff(size_t size, BUFF_t buff, bool managed)
Returns a JSON string object holding the provided content bytes.
Definition nyx_node.h:1071
bool nyx_string_set(nyx_string_t *object, STR_t value, bool managed)
Sets the text value of the provided JSON string object.
Definition json_string.c:76
str_t nyx_string_to_string(const nyx_string_t *object)
Returns a C string, with the special character escaping, representing the provided JSON string object...
str_t nyx_string_to_cstring(const nyx_string_t *object)
Returns a C string, without special character escaping, representing the provided JSON string object.
nyx_string_t * nyx_string_new(void)
Allocates a new JSON string object.
Definition json_string.c:14
bool nyx_string_set_buff(nyx_string_t *object, size_t size, BUFF_t buff, bool managed)
Sets the content of the provided JSON string object from a byte buffer.
__NYX_INLINE__ nyx_string_t * nyx_string_from(STR_t value, bool managed)
Returns a JSON string object holding the provided text value.
Definition nyx_node.h:1051
Struct describing a JSON string object.
Definition nyx_node.h:914
__NYX_NULLABLE__ nyx_object_t * nyx_xmldoc_to_object(__NYX_NULLABLE__ const nyx_xmldoc_t *xmldoc)
Converts an XML Nyx / INDI command to the JSON one.
__NYX_NULLABLE__ nyx_xmldoc_t * nyx_object_to_xmldoc(__NYX_NULLABLE__ const nyx_object_t *object)
Converts a JSON Nyx / INDI command to the XML one.
__NYX_NULLABLE__ buff_t nyx_zlib_inflate(__NYX_NOTNULL__ size_t *result_size, __NYX_ZEROABLE__ size_t size, __NYX_NULLABLE__ BUFF_t buff)
Decompresses a buffer using the ZLib algorithm.
uint32_t nyx_hash(__NYX_ZEROABLE__ size_t size, __NYX_NULLABLE__ BUFF_t buff, uint32_t seed)
Hashes a buffer using the MurmurHash2 algorithm.
__NYX_NULLABLE__ buff_t nyx_zlib_base64_inflate(__NYX_NOTNULL__ size_t *result_size, __NYX_ZEROABLE__ size_t len, __NYX_NULLABLE__ STR_t str)
Decompresses a string using the ZLib+Base64 algorithm.
__NYX_NULLABLE__ buff_t nyx_zlib_deflate(__NYX_NULLABLE__ size_t *result_size, __NYX_ZEROABLE__ size_t size, __NYX_NULLABLE__ BUFF_t buff)
Compresses a buffer using the ZLib algorithm.
__NYX_NULLABLE__ str_t nyx_base64_encode(__NYX_NULLABLE__ size_t *result_len, __NYX_ZEROABLE__ size_t size, __NYX_NULLABLE__ BUFF_t buff)
Encodes a buffer using the Base64 algorithm.
__NYX_NULLABLE__ str_t nyx_zlib_base64_deflate(__NYX_NULLABLE__ size_t *result_len, __NYX_ZEROABLE__ size_t size, __NYX_NULLABLE__ BUFF_t buff)
Compresses a buffer using the ZLib+Base64 algorithm.
__NYX_NULLABLE__ buff_t nyx_base64_decode(__NYX_NULLABLE__ size_t *result_size, __NYX_ZEROABLE__ size_t len, __NYX_NULLABLE__ STR_t str)
Decodes a string using the Base64 algorithm.
void nyx_generate_mac_addr(uint8_t result_mac[6], uint8_t mac0, uint8_t mac1, STR_t node_id)
Generates a MAC address based on a node identifier.
Definition addr.c:14
nyx_xml_type_t
XML node types.
Definition nyx_node.h:1770
str_t nyx_xmldoc_to_string(const nyx_xmldoc_t *xmldoc)
Returns a string representing the provided XML document.
Definition dom.c:284
void nyx_xmldoc_free(__NYX_NULLABLE__ nyx_xmldoc_t *xmldoc)
Frees memory of the provided XML document.
__NYX_NULLABLE__ nyx_xmldoc_t * nyx_xmldoc_parse(__NYX_NULLABLE__ STR_t string)
Parses an XML document from a C string.
__NYX_NULLABLE__ nyx_xmldoc_t * nyx_xmldoc_parse_buff(__NYX_ZEROABLE__ size_t size, __NYX_NULLABLE__ BUFF_t buff)
Parses an XML document from a string buffer.
Struct describing an XML document.