vendredi 27 novembre 2020

Is there an equivalent utility class for ByteArrayDataInput and ByteArrayDataOutput in C++?

I am doing some networking, and I need some organization in my packets. Sending raw bytes and having no abstraction is real difficult.

For java developers, do you know equivalent classes to ByteArrayDataInput and ByteArrayDataOutput in C++?

If you aren't familiar with them, could you show me how I could go about coding them.

#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);
};

Those are my header files, I now need help implementing them. And how could I go about efficiently reading/writing arrays of these types? like write_double_array(array) and read_double_array(array)? Writing it with write_double(array[i]) for every element in the array? Thanks.

Aucun commentaire:

Enregistrer un commentaire