def UnStuffData(src,dst,len): for code in src: for i in range(1,code): dst.append(i)
if code < 0xff dst.append('\0') the above is the below code uncommented... it(and the original code) just seem to find the end and puts a zero there... I do not see the existing zeroes replaced..... this is kinda why I wanted to start from the specification... here is how i see the laymans verson of the spec: get a packet (or the first 254 bytes of it) if 254 bytes, put an FF in front of them and send it on its way as a 255 byte packet, repeat this until less than 254 bytes remain. Place a byte in front of the packet that is equal to the count until the first x00 byte is found. At the location where that x00 byte was, put the count until the next x00 byte... and so on and so on... (this is where the imaginary x00 at the end comes in) decoding is: pop the first byte of the packet off and place subsequent bytes into the output until you get to the byte pointed to by the popped byte. When you reach that byte, read its value as the new 'relative' pointer, and copy x00 to the output. Proceed as above, placing bytes to the output until the relative pointer is reached or the end of the packet occurrs. I guess I need to look if I wish for this part of the program to handle the input as one big existing string, or work on it a byte at a time as it comes in. -mike c --- Alan Gauld <[EMAIL PROTECTED]> wrote: > > I am a noob to converting pointers in C++ to > arrays in > > python, although the first time I see it done, I > will > > have no problem. Can you help converting the below > > (what I think is the 'decoder' section) to python? > > It won't be working code but I think this is whats > happening... > > > UINT CCobsPackets::UnStuffData(unsigned char *src, > > unsigned char *dst, UINT length) > > def UnStuffData(src,dst,len): > > > { > > unsigned char *dstStart = dst; > > unsigned char *end = src + length; > > # I don't think these are needed for Pyhon. > > > while (src < end) > > for code in src: > > > { > > int code = *src++; > > for (int i=1; i<code; i++) > > { > > *dst++ = *src++; > > } > > for i in range(1,code): > dst.append(i) > > > if (code < 0xFF) > > { > > *dst++ = 0; > > } > > if code < 0xff > dst.append('\0') # may not be needed in > python... > > > } > > return (UINT)(dst - dstStart); > > } > > This looks odd, I don't think I understand what it > does. > It seems to return an address thats potentially > (probably?!) > before the start of the original dst... > > I think it should probably translate to > return dst > > Does that help? > > Alan G > Author of the learn to program web tutor > http://www.freenetpages.co.uk/hp/alan.gauld > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor