CChunkRavel
Workflows

Coding workflows · Restricted chunked-body decoding

03
Built around your work

A concrete starting point

Decode a restricted chunked body from at most 65536 bytes with a 4096-byte output limit. Test embedded CRLF and the zero chunk, rejecting truncation, extensions, trailers and bytes after the terminator.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Restricted chunked-body decoding

A concrete starting point
def chunk_body(wire):
    if type(wire) is not bytes or len(wire) > 65536:
        raise ValueError("bounded bytes")
    pos, body = 0, bytearray()
    while True:
        end = wire.find(b"\r\n", pos)
        token = wire[pos:end] if end >= 0 else b""
        if not 1 <= len(token) <= 8 or any(
            c not in b"0123456789abcdefABCDEF" for c in token):
            raise ValueError("plain hexadecimal size")
        size, pos = int(token, 16), end + 2
        if size == 0:
            if wire[pos:] != b"\r\n":
                raise ValueError("no trailers or extra bytes")
            return bytes(body)
        if len(body) + size > 4096:
            raise ValueError("body limit")
        if pos + size + 2 > len(wire):
            raise ValueError("truncated chunk")
        if wire[pos + size:pos + size + 2] != b"\r\n":
            raise ValueError("chunk delimiter")
        body.extend(wire[pos:pos + size])
        pos += size + 2

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗