liteserver / binn

Binary Serialization
Apache License 2.0
440 stars 58 forks source link

correct syntax for reading binn object from socket #13

Closed markvai closed 6 years ago

markvai commented 6 years ago

Hi,

can you write what is the correct syntax for reading a binn object from a socket?

what i am trying is: sending: binn * obj = binn_object();

binn_object_set_int32(obj, (char*)"dst_enclave", 306768318);

int socket = clSockFd;

if (send(socket, binn_ptr(obj), binn_size(obj), 0) != binn_size(obj)) {
    printf("SENDER -- failed to send msg1 to dest\n");
    abort();
}
binn_free(obj);

reading:

        binn * obj = binn_object();

        if (recv(servSockFd, binn_ptr(obj), binn_size(obj), 0) < 0) {
            printf("LISTENER -- failed to read msg1 from src\n");
            abort();
        }

        int test = binn_object_int32(obj, (char*)"dst_enclave");

but i am getting 0 in test.

kroggen commented 6 years ago

Just use read() as you are used to, reading the data to a buffer.

Then read the binn from the buffer, like this:

int test = binn_object_int32(buf, "dst_enclave");