From 04b0f3b8460035b6100db35616330569e40962f0 Mon Sep 17 00:00:00 2001 From: Yury Bayda Date: Thu, 13 Aug 2026 00:05:17 -0700 Subject: [PATCH] chore: complete repository baseline --- .github/CODEOWNERS | 1 + README.md | 56 +++++++++++++++++++++++----------------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index e656eab..d0ffdce 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1,2 @@ * @Coding-Cuddles/kata-maintainers +/.github/CODEOWNERS @Coding-Cuddles/kata-maintainers diff --git a/README.md b/README.md index 214c8e8..5eef352 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ [![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) +Implement compact integer encoding for a nine-byte telemetry buffer in Python +3.11 or later with pytest. Setup is complete when the existing test suite passes. + ## Overview This kata complements [Clean Code: Advanced TDD, Ep. 20](https://cleancoders.com/episode/clean-code-episode-20) @@ -18,12 +21,12 @@ We will work on a telemetry system for a remote control car project. Bandwidth in the telemetry system is at a premium and you have been asked to implement a message protocol for communicating telemetry data. -Data is transmitted in a buffer (byte array). When integers are sent, the size -of the buffer is reduced by employing the protocol described below. +Data is transmitted in a buffer (byte array). When integers are sent, the +number of payload bytes is reduced by employing the protocol described below. Each value should be represented in the smallest possible C integral type -(types of `char` and `unsigned char` are not included as the saving would be -trivial): +(types of `char` and `unsigned char` are not included because the space savings +would be trivial): | From | To | Type | |:---------------------------|:------------------------- |:-----------------| @@ -38,19 +41,19 @@ trivial): The value should be converted to the appropriate number of bytes for its assigned type. The complete internal 9-byte buffer comprises three parts: -- _prefix byte_: a byte indicating the number of the payload bytes in the +- _prefix byte_: a byte indicating the number of payload bytes in the buffer; - _payload bytes_: the bytes holding the integer; - _trailing bytes_: the zero-fill bytes to complete the buffer. To distinguish between signed and unsigned types, the protocol introduces a -little trick: for signed types, their _prefix byte_ value is `256` minus the -number of _payload bytes_ in the buffer. +little trick: for signed types, the _prefix byte_ is `256` minus the number of +_payload bytes_ in the buffer. ### Exercise 1 -Implement the static method `TelemetryBuffer.to_buffer()` to encode a buffer -taking an integer value passed to the method. +Implement the static method `TelemetryBuffer.to_buffer()` to encode an integer +value into a buffer. ```python # Type: unsigned short, bytes: 2, signed: no, prefix byte: 2 @@ -69,15 +72,15 @@ TelemetryBuffer.to_buffer(2_147_483_647) ### Exercise 2 -Implement the static method `TelemetryBuffer.from_buffer()` to decode the -buffer received, and return the value in the form of an integer. +Implement the static method `TelemetryBuffer.from_buffer()` to decode a +received buffer and return its integer value. ```python TelemetryBuffer.from_buffer([0xfc, 0xff, 0xff, 0xff, 0x7f, 0x0, 0x0, 0x0, 0x0]) # => 2_147_483_647 ``` -If the prefix byte is of unexpected value, then return `0`. +If the prefix byte has an unexpected value, return `0`. ## Integral numbers in C @@ -85,22 +88,19 @@ If the prefix byte is of unexpected value, then return `0`. > > For type sizes, we assume a typical 64-bit system. -The C language provides a number of types that represent integers, each with -its own range of values. The ranges are determined by the storage width of the -type as allocated by the system: - -| Type | Width | Minimum | Maximum | -|:-----------------|:-------|:---------------------------|:--------------------------- | -| `char` | 8 bit | -128 | +127 | -| `short` | 16 bit | -32,768 | +32,767 | -| `int` | 32 bit | -2,147,483,648 | +2,147,483,647 | -| `long` | 64 bit | -9,223,372,036,854,775,808 | +9,223,372,036,854,775,807 | -| `unsigned char` | 8 bit | 0 | +255 | -| `unsigned short` | 16 bit | 0 | +65,535 | -| `unsigned int` | 32 bit | 0 | +4,294,967,295 | -| `unsigned long` | 64 bit | 0 | +18,446,744,073,709,551,615 | - -Setup is complete when the existing test suite passes. +The C language provides several integer types, each with its own range of +values. The system's storage width for each type determines its range: + +| Type | Width | Minimum | Maximum | +|:-----------------|:--------|:---------------------------|:--------------------------- | +| `char` | 8 bits | -128 | +127 | +| `short` | 16 bits | -32,768 | +32,767 | +| `int` | 32 bits | -2,147,483,648 | +2,147,483,647 | +| `long` | 64 bits | -9,223,372,036,854,775,808 | +9,223,372,036,854,775,807 | +| `unsigned char` | 8 bits | 0 | +255 | +| `unsigned short` | 16 bits | 0 | +65,535 | +| `unsigned int` | 32 bits | 0 | +4,294,967,295 | +| `unsigned long` | 64 bits | 0 | +18,446,744,073,709,551,615 | ## Prerequisites