forked from net-amqp-rabbitmq/net-amqp-rabbitmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
amqp_debug.c
211 lines (165 loc) · 4.09 KB
/
amqp_debug.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <amqp.h>
#include <errno.h>
#include <stdarg.h>
#include <errno.h>
#include <inttypes.h>
static void dump_row(long count, int numinrow, int *chs) {
int i;
printf("%08lX:", count - numinrow);
if (numinrow > 0) {
for (i = 0; i < numinrow; i++) {
if (i == 8)
printf(" :");
printf(" %02X", chs[i]);
}
for (i = numinrow; i < 16; i++) {
if (i == 8)
printf(" :");
printf(" ");
}
printf(" ");
for (i = 0; i < numinrow; i++) {
if (isprint(chs[i]))
printf("%c", chs[i]);
else
printf(".");
}
}
printf("\n");
}
static int rows_eq(int *a, int *b) {
int i;
for (i=0; i<16; i++)
if (a[i] != b[i])
return 0;
return 1;
}
void amqp_dump(void const *buffer, size_t len) {
unsigned char *buf = (unsigned char *) buffer;
long count = 0;
int numinrow = 0;
int chs[16];
int oldchs[16];
int showed_dots = 0;
int i;
for (i = 0; i < len; i++) {
int ch = buf[i];
if (numinrow == 16) {
int i;
if (rows_eq(oldchs, chs)) {
if (!showed_dots) {
showed_dots = 1;
printf(" .. .. .. .. .. .. .. .. : .. .. .. .. .. .. .. ..\n");
}
} else {
showed_dots = 0;
dump_row(count, numinrow, chs);
}
for (i=0; i<16; i++)
oldchs[i] = chs[i];
numinrow = 0;
}
count++;
chs[numinrow++] = ch;
}
dump_row(count, numinrow, chs);
if (numinrow != 0)
printf("%08lX:\n", count);
}
static void dump_indent(int indent, FILE *out) {
int i;
for (i = 0; i < indent; i++) {
fputc(' ', out);
}
}
void say( char *buffer ) {
fprintf(stderr, "%s", buffer );
}
static void dump_value(int indent, amqp_field_value_t v, FILE *out) {
int i;
dump_indent(indent, out);
fputc(v.kind, out);
switch (v.kind) {
case AMQP_FIELD_KIND_BOOLEAN:
fputs(v.value.boolean ? " true\n" : " false\n", out);
break;
case AMQP_FIELD_KIND_I8:
fprintf(out, " %"PRId8"\n", v.value.i8);
break;
case AMQP_FIELD_KIND_U8:
fprintf(out, " %"PRIu8"\n", v.value.u8);
break;
case AMQP_FIELD_KIND_I16:
fprintf(out, " %"PRId16"\n", v.value.i16);
break;
case AMQP_FIELD_KIND_U16:
fprintf(out, " %"PRIu16"\n", v.value.u16);
break;
case AMQP_FIELD_KIND_I32:
fprintf(out, " %"PRId32"\n", v.value.i32);
break;
case AMQP_FIELD_KIND_U32:
fprintf(out, " %"PRIu32"\n", v.value.u32);
break;
case AMQP_FIELD_KIND_I64:
fprintf(out, " %"PRId64"\n", v.value.i64);
break;
case AMQP_FIELD_KIND_F32:
fprintf(out, " %g\n", (double) v.value.f32);
break;
case AMQP_FIELD_KIND_F64:
fprintf(out, " %g\n", v.value.f64);
break;
case AMQP_FIELD_KIND_DECIMAL:
fprintf(out, " %d:::%u\n", v.value.decimal.decimals,
v.value.decimal.value);
break;
case AMQP_FIELD_KIND_UTF8:
fprintf(out, " %.*s\n", (int)v.value.bytes.len,
(char *)v.value.bytes.bytes);
break;
case AMQP_FIELD_KIND_BYTES:
fputc(' ', out);
for (i = 0; i < (int)v.value.bytes.len; i++) {
fprintf(out, "%02x", ((char *) v.value.bytes.bytes)[i]);
}
fputc('\n', out);
break;
case AMQP_FIELD_KIND_ARRAY:
fputc('\n', out);
for (i = 0; i < v.value.array.num_entries; i++) {
dump_value(indent + 2, v.value.array.entries[i], out);
}
break;
case AMQP_FIELD_KIND_TIMESTAMP:
fprintf(out, " %"PRIu64"\n", v.value.u64);
break;
case AMQP_FIELD_KIND_TABLE:
fputc('\n', out);
for (i = 0; i < v.value.table.num_entries; i++) {
dump_indent(indent + 2, out);
fprintf(out, "%.*s ->\n",
(int)v.value.table.entries[i].key.len,
(char *)v.value.table.entries[i].key.bytes);
dump_value(indent + 4, v.value.table.entries[i].value, out);
}
break;
case AMQP_FIELD_KIND_VOID:
fputc('\n', out);
break;
default:
fprintf(out, "???\n");
break;
}
}
void dump_table(amqp_table_t table) {
fprintf(stderr, "Dump start\n");
amqp_field_value_t val;
val.kind = AMQP_FIELD_KIND_TABLE;
val.value.table = table;
dump_value(0, val, stderr);
}