Bencode Foo

Feb 2026

A minimal bencode decoder written in Go.

Tech Stack

Golang

Overview

Bencode Foo is a tiny decoder I wrote to understand bencoding at a low level. It focuses on the core primitives: strings, integers, lists, and dictionaries.

Bencode decoding flow

The Problem

I wanted to understand BitTorrent internals beyond the high-level descriptions. Bencoding is small but subtle, and I wanted to learn it by implementing a decoder from scratch with a manual cursor and recursive parsing. The project is a learning artifact, not a product.

The Solution

I wrote a minimal Go decoder that parses bencode using a cursor-based recursive descent approach. It is binary-safe and returns strings as []byte. The execution flow is the diagram below.

Bencode specs

Technical Details

  • Decodes bencode strings, integers, lists, and dictionaries
  • Binary-safe output (strings are []byte)
  • Recursive descent parser with a manual cursor
  • Minimal main.go for quick testing
  • Learning reference and explanation
  • Thanks to @arpit_bhayani for the in depth explanation
  • If you want more detail, see Bencode