java—在c++中,bytearraydatainput和bytearraydataoutput是否有等效的实用程序类?

y3bcpkx1  于 2021-07-08  发布在  Java
关注(0)|答案(1)|浏览(255)

我正在做一些网络,我需要一些组织在我的包。发送原始字节和没有抽象是非常困难的。
对于java开发人员,您知道c++中与bytearraydatainput和bytearraydataoutput等价的类吗?
如果你不熟悉它们,你能告诉我如何编写它们吗。


# pragma once

# include <string>

class packetreader
{
public:
    bool read_bool(int index);

    char read_byte(int index);

    short read_short(int index);

    int read_int(int index);

    long read_long(int index);

    float read_float(int index);

    double read_double(int index);

    std::string read_string(int index);
};

# pragma once

# include <string>

class packetwriter
{
    void write_bool(int index, bool value);

    void write_byte(int index, char value);

    void write_short(int index, short value);

    void write_int(int index, int value);

    void write_long(int index, long value);

    void write_float(int index, float value);

    void write_double(int index, double value);

    void write_string(int index, std::string value);
};

这些是我的头文件,我现在需要帮助实现它们。我怎样才能有效地读写这些类型的数组呢?比如写双数组(array)和读双数组(array)?对数组中的每个元素都用write_double(数组[i])写入它?谢谢。

cnh2zyt3

cnh2zyt31#

c没有用于网络的标准api。如果您的程序在操作系统上运行,那么操作系统可能会提供一个用于联网的api。
c
也没有用于序列化的标准api,这是我的推测 ByteArrayData 上课是为了。串行化可以通过基本的算术运算来实现。

相关问题