1616#include "pet_encode.h"
1717#include "zcbor_print.h"
1818
19- #if DEFAULT_MAX_QTY != 3
19+ #if ZCBOR_GENERATED_DEFAULT_MAX_QTY != 3
2020#error "The type file was generated with a different default_max_qty than this file"
2121#endif
2222
2929 } \
3030} while(0)
3131
32+ /* Streaming io struct (internal, schema-wide). */
33+ struct cbor_stream_io {
34+ /* Repeated fields (iterator) */
35+ struct zcbor_stream_iter_io Pet_name_names ;
36+
37+ /* Text string fields (chunk_out) */
38+ /* no tstr chunk_out io */
39+
40+ /* Byte string fields (chunk_out) */
41+ struct zcbor_chunk_out chunks_out_Timestamp ;
42+
43+ /* Text string fields (chunk_in) */
44+ /* no tstr chunk_in io */
45+
46+ /* Byte string fields (chunk_in) */
47+ struct zcbor_chunk_in chunks_in_Timestamp ;
48+ };
49+
3250static bool encode_Pet (zcbor_state_t * state , const struct Pet * input );
3351
3452
@@ -37,27 +55,53 @@ static bool encode_Pet(
3755{
3856 zcbor_log ("%s\r\n" , __func__ );
3957
40- bool res = (((zcbor_list_start_encode (state , 3 ) && ((((zcbor_list_start_encode (state , 3 ) && ((zcbor_multi_encode_minmax (1 , 3 , & (* input ).names_count , (zcbor_encoder_t * )zcbor_tstr_encode , state , (* & (* input ).names ), sizeof (struct zcbor_string ))) || (zcbor_list_map_end_force_encode (state ), false)) && zcbor_list_end_encode (state , 3 )))
58+ bool res = (((zcbor_list_start_encode (state , ZCBOR_VALUE_IS_INDEFINITE_LENGTH ) && ((((zcbor_list_start_encode (state , ZCBOR_VALUE_IS_INDEFINITE_LENGTH ) && (((((( const struct cbor_stream_io * ) zcbor_get_stream_io ( state )) && (( const struct cbor_stream_io * ) zcbor_get_stream_io ( state )) -> Pet_name_names . next ) ? ( zcbor_multi_encode_iter_minmax ( 1 , DEFAULT_MAX_QTY , ( zcbor_encoder_t * ) zcbor_tstr_encode , state , (( const struct cbor_stream_io * ) zcbor_get_stream_io ( state )) -> Pet_name_names . next , (( const struct cbor_stream_io * ) zcbor_get_stream_io ( state )) -> Pet_name_names . ctx )) : ( zcbor_multi_encode_minmax (1 , DEFAULT_MAX_QTY , & (* input ).names_count , (zcbor_encoder_t * )zcbor_tstr_encode , state , (* & (* input ).names ), sizeof (struct zcbor_string ))))) || (zcbor_list_map_end_force_encode (state ), false)) && zcbor_list_end_encode (state , ZCBOR_VALUE_IS_INDEFINITE_LENGTH )))
4159 && (((((((* input ).birthday .len == 8 )) || (zcbor_error (state , ZCBOR_ERR_WRONG_RANGE ), false))) || (zcbor_error (state , ZCBOR_ERR_WRONG_RANGE ), false))
4260 && (zcbor_bstr_encode (state , (& (* input ).birthday ))))
4361 && ((((* input ).species_choice == Pet_species_cat_c ) ? ((zcbor_uint32_put (state , (1 ))))
4462 : (((* input ).species_choice == Pet_species_dog_c ) ? ((zcbor_uint32_put (state , (2 ))))
4563 : (((* input ).species_choice == Pet_species_other_c ) ? ((zcbor_uint32_put (state , (3 ))))
46- : false))))) || (zcbor_list_map_end_force_encode (state ), false)) && zcbor_list_end_encode (state , 3 ))));
64+ : false))))) || (zcbor_list_map_end_force_encode (state ), false)) && zcbor_list_end_encode (state , ZCBOR_VALUE_IS_INDEFINITE_LENGTH ))));
4765
4866 log_result (state , res , __func__ );
4967 return res ;
5068}
5169
52-
53-
5470int cbor_encode_Pet (
5571 uint8_t * payload , size_t payload_len ,
5672 const struct Pet * input ,
5773 size_t * payload_len_out )
5874{
59- zcbor_state_t states [4 ];
75+ zcbor_state_t states [3 + ZCBOR_CONST_STATE_SLOTS ];
6076
6177 return zcbor_entry_function (payload , payload_len , (void * )input , payload_len_out , states ,
6278 (zcbor_decoder_t * )encode_Pet , sizeof (states ) / sizeof (zcbor_state_t ), 1 );
6379}
80+
81+ int cbor_stream_encode_Pet (
82+ zcbor_stream_write_fn stream_write , void * stream_user_data ,
83+ const struct Pet * input ,
84+ const cbor_stream_io_Pet * io ,
85+ size_t * bytes_written_out )
86+ {
87+ zcbor_state_t states [ZCBOR_STREAM_STATE_ARRAY_SIZE ];
88+ zcbor_new_encode_state_streaming (states , sizeof (states ) / sizeof (states [0 ]),
89+ stream_write , stream_user_data , 1 );
90+ struct cbor_stream_io io_local = {0 };
91+ if (io ) {
92+ io_local .Pet_name_names = io -> Pet_name_names ;
93+ io_local .chunks_out_Timestamp = io -> chunks_out_Timestamp ;
94+ zcbor_set_stream_io (& states [0 ], & io_local );
95+ } else {
96+ zcbor_set_stream_io (& states [0 ], NULL );
97+ }
98+ bool ok = encode_Pet (& states [0 ], input );
99+ if (!ok ) {
100+ int err = zcbor_pop_error (& states [0 ]);
101+ return (err == ZCBOR_SUCCESS ) ? ZCBOR_ERR_UNKNOWN : err ;
102+ }
103+ if (bytes_written_out ) {
104+ * bytes_written_out = zcbor_stream_bytes_written (& states [0 ]);
105+ }
106+ return ZCBOR_SUCCESS ;
107+ }
0 commit comments