Menu

Need help in EXI Decoder

Get Help
2013-03-13
2013-03-18
  • Sravana Kumar K

    Sravana Kumar K - 2013-03-13

    Hi Rumen,

    This information is regarding https://sourceforge.net/p/exip/bugs/8/

    I have changed decoder code something like bellow.

    Existing prototype :

    errorCode decode(EXIPSchema* schemaPtr, FILE *infile,
                     size_t (*inputStream)(void* buf, size_t size, void* stream))
    {
      char buf[INPUT_BUFFER_SIZE];
    }
    

    Modified prototype :

    errorCode decode(EXIPSchema* schemaPtr, const char *infile,
                     size_t (*inputStream)(void* buf, size_t size, void* stream))
    {
      char buf[INPUT_BUFFER_SIZE];
    }
    

    Existing readFileInputStream :

    size_t readFileInputStream(void* buf, size_t readSize, void* stream)
    {
      FILE *infile = (FILE*) stream;
      return fread(buf, 1, readSize, infile);
    }
    

    Modified readFileInputStream :

    size_t readFileInputStream(void* buf, size_t readSize, void* stream)
    {
      memcpy (buf, stream, readSize);
      return readSize;
    }
    

    For 'decode' call, I am passing char pointer of exi stream which is length of 850 bytes.
    Since INPUT_BUFFER_SIZE is 200. It is able to decode only 200 bytes of exi stream, later it was stopping.

    If I increase that INPUT_BUFFER_SIZE to 1000. Now I can able to decode that exi stream

    In case of more than 1000 bytes of exi stream, again problem comes.

    If I use code as it is taking FILE pointer, then there was no issue with this size, we can keep INPUT_BUFFER_SIZE as 200.

    But, when pass exi stream as char pointer then problem coming.

    I am writing an interface by using decoder examples which takes char pointer as input(exi) and char pointer as output(xml). As like this

    errorCode decode(EXIPSchema* schemaPtr, const char *inStream, char *outStream
                     size_t (*inputStream)(void* buf, size_t size, void* stream))
    

    User can call this function outside library by passing schemaPtr, inStream which is exi content, outStream which is decoded version of exi content (xml)

    Regards,
    SK

     
  • Denis Froschauer

    Your second function readFileInputStream() must return 200, then 200, 200, 200 and then 50 (indicating to EXIP this is the end of data 50 returned < 200 requested) : total = 850

    Denis

     
  • Sravana Kumar K

    Sravana Kumar K - 2013-03-15

    Hi Denis,

    What you said is correct incase of FILE* as input.

    But in my case, I am getting first 200 only and then it stops.

    Regards,
    SK

     
  • Denis Froschauer

    As I understand, you have a buffer in memory, instead of a file.
    This is the same process : when EXIP ask you X bytes, you must return X bytes.
    If you return less that X bytes, EXIP understand you haven't data anymore and stops.

    Try this :

    typedef struct {
    char *data;
    int len;
    int current;
    } memoryStream_t;

    size_t readMemInputStream(void buf, size_t readSize, void stream) {
    memoryStream_t ms = (memoryStream_t )stream;
    if (!ms->data)
    return 0;
    int how = ms->len - ms->current;
    if (how > readSize)
    how = readSize;
    //printf ("readMemInputStream %d how=%d\n", readSize, how);
    memcpy (buf, ms->data+ms->current, how);
    ms->current += how;
    return how;
    }

    decode() {
    memoryStream_t ms;

        ms.data = <the big buffer>;
        ms.len  = <size of the big buffer>;
        ms.current      = 0;
    
        buffer.ioStrm.readWriteToStream = readMemInputStream;
        buffer.ioStrm.stream = &ms;
    

    ...

    Denis

     

Anonymous
Anonymous

Add attachments
Cancel