Channel Input Encoding

This page explains a system for encoding HTML form input configurations into 64-bit numbers, allowing compact representation of forms with up to 32 fields using 22 input types. Each 64-bit encoding captures the number of fields (\( k \)) and up to 11 fields' types, with arrays of encodings enabling any configuration.

Code Structure and Function Calls

Constants and Defines

Structs

Functions

Bit Definitions

Below is the bit layout for 0x3c5140c506148000 (15 fields: text, email, checkbox, date, number, password, radio, submit, tel, url, file). The pattern 1111111111111 (13 bits) highlights bits 54–42 as an example.

Bit Position 63–58 57–55 54–50 49–45 44–40 39–35 34–30 29–25 24–20 19–15 14–10 9–5 4–0
Purpose \( k \) (Num Fields) Unused Field 1 Field 2 Field 3 Field 4 Field 5 Field 6 Field 7 Field 8 Field 9 Field 10 Field 11
Binary 001111 000 10010 00101 00001 00011 01010 01011 01100 10000 10001 10100 00110
Value 15 0 18 (text) 5 (email) 1 (checkbox) 3 (date) 10 (number) 11 (password) 12 (radio) 16 (submit) 17 (tel) 20 (url) 6 (file)

Input Types

The 22 HTML input types are mapped to 5-bit values (0–21) as follows:

Input Type Value C Define
button 0 INPUT_TYPE_BUTTON
checkbox 1 INPUT_TYPE_CHECKBOX
color 2 INPUT_TYPE_COLOR
date 3 INPUT_TYPE_DATE
datetime-local 4 INPUT_TYPE_DATETIME_LOCAL
email 5 INPUT_TYPE_EMAIL
file 6 INPUT_TYPE_FILE
hidden 7 INPUT_TYPE_HIDDEN
image 8 INPUT_TYPE_IMAGE
month 9 INPUT_TYPE_MONTH
number 10 INPUT_TYPE_NUMBER
password 11 INPUT_TYPE_PASSWORD
radio 12 INPUT_TYPE_RADIO
range 13 INPUT_TYPE_RANGE
reset 14 INPUT_TYPE_RESET
search 15 INPUT_TYPE_SEARCH
submit 16 INPUT_TYPE_SUBMIT
tel 17 INPUT_TYPE_TEL
text 18 INPUT_TYPE_TEXT
time 19 INPUT_TYPE_TIME
url 20 INPUT_TYPE_URL
week 21 INPUT_TYPE_WEEK

Custom Interface Potential: With 5 bits, up to 32 types (0–31) can be encoded. The 22 HTML types use values 0–21, leaving 9 unused values (22–31) available for custom interface elements, such as specialized widgets or application-specific controls.

Arrays for Flexibility

For forms exceeding 11 fields, an array of encodings is used. For example, a 15-field form splits into:

What Chunks Represent: Each chunk is a 64-bit encoding of a subset of the form’s fields. Chunk 1 encodes the first 11 fields (text, email, checkbox, date, number, password, radio, submit, tel, url, file), with \( k = 11 \) (bits 63–58 = 001011). Chunk 2 encodes the last 4 fields (hidden, button, color, reset), with \( k = 4 \) (bits 63–58 = 000100). Together, they fully specify all 15 fields without defaults.

Why 11 Often Suffices: Most web forms (e.g., login, registration) have fewer than 11 fields—studies suggest 5–10 fields optimize usability. A single 64-bit encoding handles these common cases efficiently (61 bits used: 6 for \( k \), 55 for 11 types). For larger forms, arrays scale seamlessly, but 11 covers the majority of practical scenarios.

C Structs

Struct Name Members Description
struct Input uint8_t type A single input field with a type ID (0–21).
struct Form uint8_t num_fields
struct Input fields[32]
A form with up to 32 fields and their count.
struct FormEncodingResult uint64_t encoding
uint8_t type_counts[22]
int error
Result of encoding: 64-bit value, type counts, and error flag.
struct FormArrayEncoding uint64_t* encodings
uint32_t num_encodings
An array of 64-bit encodings for multiple chunks.

Function Names

Function Name Description
encode_form(const struct Form* form) Encodes a form into a 64-bit number.
decode_form(uint64_t encoded, struct Form* form) Decodes a 64-bit number into a form.
GetFormEncoding(struct Form* form) Gets encoding and type counts, handles invalid forms.
encode_form_array(const struct Form* form) Splits a form into an array of encodings.
decode_form_array(const struct FormArrayEncoding* array, struct Form* form) Reconstructs a form from an array of encodings.

Example

Aspect Details
Input Form 3 fields: text, email, checkbox
Single Encoding 0x0c51404000000000 (k = 3, fields fully encoded)
Type Counts text: 1, email: 1, checkbox: 1
Array Encoding 1 chunk: 0x0c51404000000000 (3 fields)
Decoded Form 3 fields: text, email, checkbox

W3C Schema Links