Ticket #1196: message_add_data.cpp

File message_add_data.cpp, 417 bytes (added by axeld, 18 years ago)
Line 
1#include <Message.h>
2
3#include <stdio.h>
4
5
6int
7main()
8{
9 const char* data = "gurkensalat";
10 BMessage a;
11 a.AddData("a", B_RAW_TYPE, data, 5);
12 a.ReplaceData("a", B_RAW_TYPE, data, 12);
13 a.PrintToStream();
14
15 const char* b;
16 ssize_t size;
17 if (a.FindData("a", B_RAW_TYPE, (const void**)&b, &size) == B_OK) {
18 char c[100];
19 memcpy(c, b, size);
20 c[size] = '\0';
21 printf("data found: %s (%ld bytes)\n", c, size);
22 }
23}