[Tutor] [Fwd: Re: Consistant Overhead Byte Stuffing (COBS)algorithm help]
Kent Johnson
kent37 at tds.net
Thu Oct 6 00:48:55 CEST 2005
Michael Cotherman wrote:
> 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...
The above is the decoding code, it does what you describe below. It is adding the zeros back in, that is the dst.append('\0')
Kent
> 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
More information about the Tutor
mailing list