- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
正在关注 this问题,我决定序列化一些我需要通过 TCP/IP 连接发送的数据。
数据非常简单:
typedef struct whiteboard {
int palladium, platine, zirconium, erbium, astate, californium;
} sharedData;
我的序列化函数也很简单:
void serializeWhiteboard (sharedData* message, char** packet) {
int* r = (int*) packet;
*r = (int)VALUE_FROM_ENUM; // just some enum to get the type of message sent
r++;
char* q = (char*) r;
*q = '/'; q++; // delimitors for parsing
*q = '/'; q++; // the message on the other end
int* p = (int*) q;
*p = message->palladium; p++;
*p = message->platine; p++;
*p = message->zirconium; p++;
*p = message->erbium; p++;
*p = message->astate; p++;
*p = message->californium; p++;
return;
}
在我的调用程序中,我有以下代码:
int main() {
sharedData data = {0};
// define the data values ...
char* dest = malloc(sizeof(int) + 2*sizeof(char) + 6*sizeof(int));
serialiseWhiteboard(&data, &dest);
// And here, the first two fields of 'data' have changed
// as if by magic, since I do not touch the fields in
// serializeWhiteboard() .
return 0;
}
我一辈子都弄不明白为什么当我只从数据中读取值时,前两个数据字段会发生变化。然而,通过一些打印值,我能够将其追踪到 serializeWhiteboard()
中的倒数第二行,就在 return;
之前,这并没有有任何意义。在调用 return
之前数据都很好。
有没有人遇到过这样的问题?
最佳答案
您有 char** 数据包
,它是指向某些字符的指针。
然后您将其视为 int *
,它是指向某些整数的指针。
然后您覆盖第一个 int
- 所以您写入的是“dest”本身,而不是它指向的内容。因为在那之后你写了更多,你正在破坏堆栈。
关于C - 将结构序列化为 char* 会更改原始数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53688450/
在更大的应用程序的上下文中,我的小程序需要将一些数据打印到 Zebra 或 Dymo(取决于用户安装的内容)标签打印机。 我收到的数据是转义形式,我只需要发送到打印机并让它解释它的数据。 搜索我找到了
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭去年。 Improve th
我正在尝试使用 GetUserMedia() 从用户麦克风录制和保存声音片段和 AudioContext蜜蜂。 我已经能够使用 MediaRecorder 做到这一点API,但不幸的是,Safari/
我想编写一个将十六进制数据转换为音频文件的小型Web应用程序。 音频文件的数据将采用十六进制格式,如下所示: DA1FFFF8B3AEEE2E23BBB9A2221F10400180001EF1C1E
在其中一个 API 中,我收到以下 Json 响应:您可以在此处查看此响应示例 Sample Json resopnse { "histogram" : { "1" : "12
如何在 python 上使用 Resuests 库发布原始数据?我正在尝试登录。 Json 抛出异常 TypeError: set(['"clienteLogin":{"Token":"b94261f
有人告诉我,无论何时使用字节,都应该将变量声明为无符号字符。在 Windows 的数据类型中,BYTE 被声明为 unsigned char。 我的问题: 为什么? Unsigned 是从 0 到 2
如何读取 GPS 原始数据,更具体地说,我需要卫星伪距。此数据不提供 NMEA 格式。 最佳答案 卫星伪距在 official API 中不可用 ,既不通过 GpsStatus.Listener 也不
给定以下 XML: 1424 我正在尝试获取
我使用了以下代码将十进制的 bigint 转换为 bytearray(原始数据),但我得到了错误的结果。 这里有什么错误吗? 我正在 Apple Mac 中尝试此操作(适用于 Iphone 应用程序)
我在 iOS 应用程序中使用 Firebase 登录时遇到了表格 View 问题。该表从子提要加载内容。当我第一次登录时,表加载正常,但如果我注销并再次登录,表会重新加载所有数据,将原始数据添加到表的
我正在使用 Apache BCEL动态创建 java 类,每个类都有自己的关联图像。这些生成的类实现了以下接口(interface): interface ImageOwner { byte[
有没有办法读取 Sim 卡的“原始”数据?类似于如何使用 Pdu 的 SmsMessage 原始数据读取原始数据? 最佳答案 阅读SIM卡相关信息需要TelephonyManager API . Te
有没有办法在命令行 curl 中将数据 POST 或 GET(插入您最喜欢的 HTTP 方法)数据到 URL 并包含在原始发布的数据 header 值中,而不是发出 -H 选项? 例如: $curl
我正在开展一个项目,尝试使用 Myo Gesture Control Armband 识别一些用于康复治疗的 Action /姿势。 . 我有三个问题: EMG Raw Data 返回的最大值和最小值
我有 flv 文件,其中包含带有 aac 原始数据的音频标签。每个音频标签都有一组 aac 原始数据。原始数据有不同的大小。我想通过 RTP 发送。我添加了 13 位大小的 AU header 。它是
我使用制造商提供的库通过 USB 访问相机。我通过结构接收有关图像的信息: typedef struct { /*! Buffer handle which contains new data
我正在从事 BLE 项目,其中录音机硬件连续流式传输数据并发送到 iOS 应用程序。从 iOS 应用程序端,我需要读取传输的数据。 硬件向 iOS 应用程序发送 HEX 数据,我们需要创建 .mp3/
我正在尝试使用 AFNetworking 发出 HTTP PUT 请求以在 CouchDB 服务器中创建附件。服务器需要 HTTP 正文中的 base64 编码字符串。如何在不使用 AFNetwork
我有一些 Graylog2 使用 syslog 输入插件接收的日志。 我需要以我收到的相同格式导出它们,无需任何解析,以便我可以发送给应用程序支持团队。 我已将 INPUT 设置为保留 full_ma
我是一名优秀的程序员,十分优秀!