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