[Tutor] [Fwd: Re: Consistant Overhead Byte Stuffing (COBS)algorithm help]

Alan Gauld alan.gauld at freenet.co.uk
Wed Oct 5 16:42:01 CEST 2005


> 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




More information about the Tutor mailing list