Serialize data to byte array and put it in OperationRequestParameters

Options
Hi,
I am having some trouble sending data from Unreal 4 to my server solution (c#).
I have:
Created a varable: TArray Param
Param.add(code, my byte array)

Now comes the problem, i have created a parameters, as type OperationRequestParameters, and i want to use put to add my nByte array as parameter.
How do i correctly use ValueObject<>() in the put function to add the nByte* into dictionary?

I have tried something along this:
paramters.put(iter.GetKey(), ValueObject<nByte*( iter.GetValue()))

But all the ways i've tried have given me compilation errors.

I also tried to serialize as string but std::string *data = (std::string *)malloc(message_size) does not allocate message_size but a very large value.

Comments

  • Kaiserludi
    Options
    Hi @Eqric90.

    nByte* is a c-array of type nByte. c-arrays are not classes, but simply pointers to the first element. As such they don't hold any size information. Therefor it is necessary to pass the element count as a separate parameter.

    Therefor your code needs to look like this:
    parameters.put(key, ValueObject<nByte*>(arr, arrsize))


    I also tried to serialize as string but std::string *data = (std::string *)malloc(message_size) does not allocate message_size but a very large value.


    I am absolutely sure malloc() DOES allocate message_size bytes.
    However casting the return value of malloc() to a std::string pointer does not give you an array with an element count that matches the allocated size, but just interprets random unitialized memory as string, so that everything inside that string, including the size, will be a random value.