Skip to content

[FEAT] Encoding Interfaces#14

Merged
bbengfort merged 1 commit intomainfrom
encoding
Apr 8, 2026
Merged

[FEAT] Encoding Interfaces#14
bbengfort merged 1 commit intomainfrom
encoding

Conversation

@bbengfort
Copy link
Copy Markdown
Contributor

@bbengfort bbengfort commented Apr 8, 2026

Scope of changes

Adds the encoding.TextMarshaler and encoding.BinaryMarshaler interfaces.

Estimated PR Size:

  • Tiny
  • Small
  • Medium
  • Large
  • Huge

Acceptance criteria

This PR will be merged without review.

Author checklist

  • I have manually tested the change and/or added automation in the form of unit tests or integration tests
  • I have updated the dependencies list
  • I have added new test fixtures as needed to support added tests
  • I have added or updated the documentation
  • I have run go generate to update generated code

Note

Medium Risk
Adds new generated MarshalText/UnmarshalText and MarshalBinary/UnmarshalBinary methods and expands parsing of []byte inputs, which can change serialization/deserialization behavior for existing enums.

Overview
Generated enums now optionally implement encoding text and binary marshaling interfaces via new MarshalText/UnmarshalText and MarshalBinary/UnmarshalBinary methods (gated by NoText/NoBinary options).

ParseFactory is extended to handle []byte inputs by treating multi-byte slices as strings and single-byte slices as numeric values, with corresponding unit test coverage added for byte and byte-slice cases.

Reviewed by Cursor Bugbot for commit 9dccb90. Configure here.

@bbengfort bbengfort merged commit 9fc9c10 into main Apr 8, 2026
4 checks passed
@bbengfort bbengfort deleted the encoding branch April 8, 2026 00:25
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9dccb90. Configure here.

case 0:
return unknown, nil
case 1:
return T(v[0]), nil
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Single-byte slice parsing skips range validation

High Severity

The case []byte handler for single-byte slices returns T(v[0]) without validating the value against the enum's defined range. This differs from other numeric type handlers, which correctly check bounds and return an error for out-of-range values.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 9dccb90. Configure here.

),
g.Case(g.Lit(1)).Block(
ptrS.Clone().Op("=").Add(typeID.Clone().Call(g.Id("data").Index(g.Lit(0)))),
g.Return(g.Nil()),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Generated UnmarshalBinary accepts out-of-range byte values

High Severity

The UnmarshalBinary method, when handling single-byte input, directly casts the byte to the enum type. This bypasses the validation logic used by other unmarshalers, allowing invalid byte values to create invalid enum instances.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 9dccb90. Configure here.

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