8000 dbc: accept json.Number through shared scalar conversions by tomrford · Pull Request #86 · tomrford/gocan · GitHub
[go: up one dir, main page]

Skip to content

dbc: accept json.Number through shar 8000 ed scalar conversions - #86

Merged
tomrford merged 2 commits into
mainfrom
dbc/json-number
Sep 24, 2026
Merged

tomrford merged 2 commits into
mainfrom
dbc/json-number

Conversation

@tomrford
@tomrford tomrford commented Sep 24, 2026 •
Copy link
Copy Markdown
Owner

Values decoded with json.Decoder.UseNumber() currently reach DBC encoding as string labels. Recognise json.Number in the existing scalar helpers so Encode, EncodePayload and Patch accept numeric JSON inputs; the shared CDD codec gains the same support for numeric fields and arrays.

Unscaled integer conversions preserve the full signed/unsigned 64-bit range and accept equivalent decimal and exponent forms. Plain integers use Int64/strconv.ParseUint. Decimal/exponent forms use math/big.Rat after a cheap float magnitude check rejects overflow and nonzero magnitudes below one; zero mantissas bypass rational parsing. The approximate magnitude never supplies the integer result, so fractional and out-of-range values still fail exact checks, including around rounded 64-bit boundaries.

Scaled and floating-point conversions validate JSON syntax and use Number.Float64(), accepting normal rounding and underflow to zero while rejecting overflow. Huge-exponent zero literals and negative zero are supported. Existing range and quantisation rules remain in place. Ordinary strings retain label/text semantics; json.Number is always numeric, including in CDD ASCII-field validation. No dependencies or public API signatures added.

Validation: full go test -race ./..., go vet ./..., formatting and diff checks passed. Windows amd64, arm64 and 386 compilation passed; Windows binaries were not executed. Focused scalar and DBC/CDD lifecycle tests cover UseNumber input, fixed payload bytes, integer boundaries, decimal/exponent forms, malformed literals, huge-exponent zero, float underflow/rounding, and unchanged frames after rejected patches.

Temporary microbenchmarks on Apple M4 / Go 1.26.6, two 100 ms samples per case, compared the initial PR with this revision:

Conversion Initial PR Revised
Unsigned 1e100000 rejection ~260 µs / 248–249 KB ~95 ns / 88 B
Unsigned 1e-100000 rejection ~258 µs / 216 KB ~152 ns / 112 B
Plain uint64 maximum ~245 ns ~72 ns
Exact uint64 maximum in exponent form ~277 ns ~323 ns
Float 0.1 ~188 ns ~33 ns

The exact exponent fallback pays a small cost for the magnitude check; ordinary integers and floating-point inputs avoid rational parsing.

@chatgpt-codex-connector
chatgpt-codex-connector Bot commented Sep 24, 2026 •
Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-24T13:05:29.473119Z 1d6ef67 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a4dfbed8f4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/scalar/scalar.go Resolved
Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 1d6ef677d8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@tomrford
tomrford merged commit 1fbf567 into main Sep 24, 2026
1 check passed
@tomrford
tomrford deleted the dbc/json-number branch September 24, 2026 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0