Skip to content

Commit 79247b0

Browse files
committed
Make the default writer and reader conditional
1 parent 75d3e89 commit 79247b0

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

include/tinycbor/cbor.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,19 @@ struct CborEncoder
218218
{
219219
cbor_encoder_writer *writer;
220220
void *writer_arg;
221+
#ifndef NO_DFLT_WRITER
221222
struct cbor_buf_writer wr;
223+
#endif
222224
size_t added;
223225
size_t container_size;
224226
int flags;
225227
};
226228

227229
typedef struct CborEncoder CborEncoder;
228230

229-
231+
#ifndef NO_DFLT_WRITER
230232
CBOR_API void cbor_encoder_init(CborEncoder *encoder, uint8_t *buffer, size_t size, int flags);
233+
#endif
231234
CBOR_API void cbor_encoder_cust_writer_init(CborEncoder *encoder, struct cbor_encoder_writer *w, int flags);
232235
CBOR_API CborError cbor_encode_uint(CborEncoder *encoder, uint64_t value);
233236
CBOR_API CborError cbor_encode_int(CborEncoder *encoder, int64_t value);
@@ -278,7 +281,9 @@ enum CborParserIteratorFlags
278281

279282
struct CborParser
280283
{
284+
#ifndef NO_DFLT_READER
281285
struct cbor_buf_reader br;
286+
#endif
282287
struct cbor_decoder_reader *d;
283288
int end;
284289
int flags;
@@ -296,7 +301,9 @@ struct CborValue
296301
};
297302
typedef struct CborValue CborValue;
298303

304+
#ifndef NO_DFLT_READER
299305
CBOR_API CborError cbor_parser_init(const uint8_t *buffer, size_t size, int flags, CborParser *parser, CborValue *it);
306+
#endif
300307
CBOR_API CborError cbor_parser_cust_reader_init(struct cbor_decoder_reader *r, int flags, CborParser *parser, CborValue *it);
301308

302309
CBOR_API CborError cbor_value_validate_basic(const CborValue *it);

src/cborencoder.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@
194194
* Structure used to encode to CBOR.
195195
*/
196196

197+
#ifndef NO_DFLT_WRITER
197198
/**
198199
* Initializes a CborEncoder structure \a encoder by pointing it to buffer \a
199200
* buffer of size \a size. The \a flags field is currently unused and must be
@@ -205,6 +206,7 @@ void cbor_encoder_init(CborEncoder *encoder, uint8_t *buffer, size_t size, int f
205206

206207
cbor_encoder_cust_writer_init(encoder, &encoder->wr.enc, flags);
207208
}
209+
#endif
208210

209211
/**
210212
* Initializes a CborEncoder structure \a encoder by pointing it to buffer \a

src/cborparser.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ uint64_t _cbor_value_decode_int64_internal(const CborValue *value)
316316
return value->parser->d->get64(value->parser->d, value->offset + 1);
317317
}
318318

319+
#ifndef NO_DFLT_READER
319320
/**
320321
* Initializes the CBOR parser for parsing \a size bytes beginning at \a
321322
* buffer. Parsing will use flags set in \a flags. The iterator to the first
@@ -334,6 +335,7 @@ CborError cbor_parser_init(const uint8_t *buffer, size_t size, int flags, CborPa
334335

335336
return cbor_parser_cust_reader_init(&parser->br.r, flags, parser, it);
336337
}
338+
#endif
337339

338340
/**
339341
* Initializes the CBOR parser for parsing. It uses the \a decoder reader. Parsing will

0 commit comments

Comments
 (0)