1
1
/****************************************************************************
2
2
**
3
- ** Copyright (C) 2016 Intel Corporation
3
+ ** Copyright (C) 2017 Intel Corporation
4
4
**
5
5
** Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
** of this software and associated documentation files (the "Software"), to deal
110
110
* If the map length is indeterminate, an underscore ("_") appears immediately after the opening brace.
111
111
*/
112
112
113
+ /**
114
+ * \enum CborPrettyFlags
115
+ * The CborPrettyFlags enum contains flags that control the conversion of CBOR to text format.
116
+ *
117
+ * \value CborPrettyDefaultFlags Default conversion flags.
118
+ */
119
+
113
120
static int hexDump (FILE * out , const uint8_t * buffer , size_t n )
114
121
{
115
122
while (n -- ) {
@@ -238,16 +245,16 @@ static int utf8EscapedDump(FILE *out, const char *buffer, size_t n)
238
245
return CborNoError ;
239
246
}
240
247
241
- static CborError value_to_pretty (FILE * out , CborValue * it );
242
- static CborError container_to_pretty (FILE * out , CborValue * it , CborType containerType )
248
+ static CborError value_to_pretty (FILE * out , CborValue * it , int flags );
249
+ static CborError container_to_pretty (FILE * out , CborValue * it , CborType containerType , int flags )
243
250
{
244
251
const char * comma = "" ;
245
252
while (!cbor_value_at_end (it )) {
246
253
if (fprintf (out , "%s" , comma ) < 0 )
247
254
return CborErrorIO ;
248
255
comma = ", " ;
249
256
250
- CborError err = value_to_pretty (out , it );
257
+ CborError err = value_to_pretty (out , it , flags );
251
258
if (err )
252
259
return err ;
253
260
@@ -257,14 +264,14 @@ static CborError container_to_pretty(FILE *out, CborValue *it, CborType containe
257
264
/* map: that was the key, so get the value */
258
265
if (fprintf (out , ": " ) < 0 )
259
266
return CborErrorIO ;
260
- err = value_to_pretty (out , it );
267
+ err = value_to_pretty (out , it , flags );
261
268
if (err )
262
269
return err ;
263
270
}
264
271
return CborNoError ;
265
272
}
266
273
267
- static CborError value_to_pretty (FILE * out , CborValue * it )
274
+ static CborError value_to_pretty (FILE * out , CborValue * it , int flags )
268
275
{
269
276
CborError err ;
270
277
CborType type = cbor_value_get_type (it );
@@ -286,7 +293,7 @@ static CborError value_to_pretty(FILE *out, CborValue *it)
286
293
it -> ptr = recursed .ptr ;
287
294
return err ; /* parse error */
288
295
}
289
- err = container_to_pretty (out , & recursed , type );
296
+ err = container_to_pretty (out , & recursed , type , flags );
290
297
if (err ) {
291
298
it -> ptr = recursed .ptr ;
292
299
return err ; /* parse error */
@@ -360,7 +367,7 @@ static CborError value_to_pretty(FILE *out, CborValue *it)
360
367
err = cbor_value_advance_fixed (it );
361
368
if (err )
362
369
return err ;
363
- err = value_to_pretty (out , it );
370
+ err = value_to_pretty (out , it , flags );
364
371
if (err )
365
372
return err ;
366
373
if (fprintf (out , ")" ) < 0 )
@@ -465,7 +472,26 @@ static CborError value_to_pretty(FILE *out, CborValue *it)
465
472
*/
466
473
CborError cbor_value_to_pretty_advance (FILE * out , CborValue * value )
467
474
{
468
- return value_to_pretty (out , value );
475
+ return value_to_pretty (out , value , CborPrettyDefaultFlags );
476
+ }
477
+
478
+ /**
479
+ * Converts the current CBOR type pointed by \a value to its textual
480
+ * representation and writes it to the \a out stream. If an error occurs, this
481
+ * function returns an error code similar to CborParsing.
482
+ *
483
+ * The textual representation can be controlled by the \a flags parameter (see
484
+ * CborPrettyFlags for more information).
485
+ *
486
+ * If no error ocurred, this function advances \a value to the next element.
487
+ * Often, concatenating the text representation of multiple elements can be
488
+ * done by appending a comma to the output stream.
489
+ *
490
+ * \sa cbor_value_to_pretty(), cbor_value_to_json_advance()
491
+ */
492
+ CborError cbor_value_to_pretty_advance_flags (FILE * out , CborValue * value , int flags )
493
+ {
494
+ return value_to_pretty (out , value , flags );
469
495
}
470
496
471
497
/** @} */
0 commit comments