MemoryBlock - maybe an unusual use

Hi all


I need to create a Memory Block consisting of various type data.
More specifically, I need to have a memory block with the following structure:
At the begining, it holds the raw contents of a two or more uint32 vars, indicating the length of the consecutive data.
The consecutive data are plain Strings with the appropriate size, as indicated by uint32 vars.
When I try to copy these data using the Memory Block::copy From() function, what I take is a completely unexpected result.

Any idea about it ?

Thanks in advance

George

     

  

 

  


I thing it's the encoding..


I'll try with that and if I have no a desired result I'll be back !

Not a problem with MemoryBlock, it'll be something else you're doing wrong, though impossible to say exactly what..

Finally, I spent a hole day, but I can't solve my problem.

Here is a piece of code to write a Memory block to a file :

static bool writeKeyFile(String& JSON_Keys)

    {
        MemoryBlock Mb(JSON_Keys.toUTF8(),  JSON_Keys.getNumBytesAsUTF8());
        FileOutputStream Out(File("Some_File");

        size_t S1 = Keys.getSize();                          // it returns the size of memory block
        if (Out.openedOk())
        {
            Out.setPosition(0);
            return  Out.write(&Keys, Keys.getSize());
        }
  }
 


I don't understand what am I doing wrong. The following piece of code has the following unexpected results :
- the keys.getSize() returns a value less than the actual size of its content (i.e. the actual size of data is 253 chars, the .getSize() returns a value of 203 ( chars).
- As a result, the data written to Out file, has a length of 203 chars instead of its actual size. 
- Even though the MemoryBlock's data seem to be ok, after turned them to UTF8 format , unfortunatelly, when I read back the data, the following  jassert (CharPointer_UTF8::isValidString (buffer, bufferSizeBytes)), interrupts the proccess of reading.. 

Any idea please ?

George

  

Almost none of your code makes any sense, I'm afraid!

Perhaps:

static bool writeKeyFile (const String& keys)
{
    return File ("my_file").replaceWithText (keys);
}

?

 

Ah, I need to have a holliday for a few days ..

 

29/2/2016 : Finally it was an illegal use of the encoding