Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
cbordevice.h
Go to the documentation of this file.
1// Copyright (C) 2018 Intel Corporation.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef CBORDEVICE_H
5#define CBORDEVICE_H
6
7#include <memory>
8#include <stdio.h>
9
10#define CBOR_API inline
11#define CBOR_PRIVATE_API inline
12#define CBOR_NO_PARSER_API 1
13#include <cbor.h>
14
16{
17public:
18 CborDevice(FILE *out) : out(out) {}
19
20 void nextItem(const char *comment = nullptr)
21 {
22 i = 0;
23 if (comment)
24 fprintf(out, "\n // %s", comment);
25 }
26
27 static CborError callback(void *self, const void *ptr, size_t len, CborEncoderAppendType t)
28 {
29 auto that = static_cast<CborDevice *>(self);
30 auto data = static_cast<const char *>(ptr);
31 if (t == CborEncoderAppendCborData) {
32 while (len--)
33 that->putByte(*data++);
34 } else {
35 while (len--)
36 that->putChar(*data++);
37 }
38 return CborNoError;
39 }
40
41private:
42 FILE *out;
43 int i = 0;
44
45 void putNewline()
46 {
47 if ((i++ % 8) == 0)
48 fputs("\n ", out);
49 }
50
51 void putByte(uint8_t c)
52 {
53 putNewline();
54 fprintf(out, " 0x%02x, ", c);
55 }
56
57 void putChar(char c)
58 {
59 putNewline();
60 if (uchar(c) < 0x20)
61 fprintf(out, " '\\x%x',", uint8_t(c));
62 else if (uchar(c) >= 0x7f)
63 fprintf(out, " uchar('\\x%x'),", uint8_t(c));
64 else if (c == '\'' || c == '\\')
65 fprintf(out, " '\\%c',", c);
66 else
67 fprintf(out, " '%c', ", c);
68 }
69};
70
71#endif // CBORDEVICE_H
static CborError callback(void *self, const void *ptr, size_t len, CborEncoderAppendType t)
Definition cbordevice.h:27
void nextItem(const char *comment=nullptr)
Definition cbordevice.h:20
CborDevice(FILE *out)
Definition cbordevice.h:18
static ControlElement< T > * ptr(QWidget *widget)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
const GLubyte * c
GLenum GLsizei len
GLdouble GLdouble t
Definition qopenglext.h:243
unsigned char uchar
Definition qtypes.h:27
QTextStream out(stdout)
[7]