Skip to content

Main content

BSON Cstring Terminator Offset Tool

Locate a zero terminator in supplied bytes without validating their character encoding.

Loading tool…

Description

Find a BSON cstring terminator from a supplied offset.

Binary and text framing can encode a payload size, container count or terminator. Those fields describe the following data but must still be checked against its actual bytes and complete structure.

Find a BSON cstring terminator from a supplied offset.

When to use this tool

Use BSON Cstring Terminator Offset when decoding one bounded framing or header component.

How to use the tool and how it works

  1. Enter bytes, start. Use the units and conventions below.
  2. Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
  3. Read terminatorIndex, byteLength. Use the output convention below.

Find a BSON cstring terminator from a supplied offset. Require byte-range entries and whole start in [0,bytes.length]; locate the first zero at or after start, rejecting absence; byteLength excludes the terminator.1

A BSON cstring is terminated by a zero octet. Finding that terminator alone does not validate UTF-8 or the surrounding document.2

Input fieldMeaning and unitsAccepted input
bytesOctet values, each from 0 through 255, in the stated byte order.Required. Array of safe integer; maximum items 256.
startStartRequired. Safe integer; minimum 0.
Output fieldInterpretationReturned shape
terminatorIndexZero-based absolute index of the first NUL at or after start.Required. Safe integer.
byteLengthTerminator index minus start; excludes the NUL byte.Required. Safe integer.
json
{
  "input": {
    "bytes": [
      1,
      65,
      66,
      0,
      9
    ],
    "start": 1
  },
  "output": {
    "terminatorIndex": 3,
    "byteLength": 2
  }
}

Limitations and assumptions

  • The result does not validate UTF-8, document framing or bytes before start.
  • Inputs must satisfy both the field types and the cross-field conditions above. Invalid input causes an error; a successful false flag or documented placeholder is a different result.
  • Numeric calculations use binary floating point unless exact decimal-integer arithmetic is explicitly stated. No hidden measurement tolerance or decimal rounding is added; nonfinite or out-of-contract results are rejected. Numeric signed-zero results are exported as zero.

Alternative or Complementary methods

Use a complete parser for payload validity, nested containers, text encoding and record boundaries.

References

  1. Calculation and input contract: decode/bson-cstring-terminator-offset — tool.io

  2. BSON specification 1.1 — BSON

Similar or alternative tools