Skip to content

feat: add float/double encoding support and Google protobuf types#47

Open
allenday wants to merge 1 commit intodatachainlab:masterfrom
allenday:feat/runtime-enhancements
Open

feat: add float/double encoding support and Google protobuf types#47
allenday wants to merge 1 commit intodatachainlab:masterfrom
allenday:feat/runtime-enhancements

Conversation

@allenday
Copy link

feat: add float/double encoding support and Google protobuf types

Summary

  • Add native float/double encoding/decoding functions to ProtoBufRuntime
  • Include Google well-known types runtime libraries
  • Enable proper handling of validation constraints from buf/validate

Changes

Float/Double Support

  • Added _decode_float() and _encode_float() functions for 32-bit float support
  • Added _decode_double() and _encode_double() functions for 64-bit double support
  • Enables proper handling of floating-point validation constraints

Google Well-Known Types

  • GoogleProtobufDuration.sol - Support for google.protobuf.Duration messages
  • GoogleProtobufTimestamp.sol - Support for google.protobuf.Timestamp messages
  • GoogleProtobufFieldDescriptorProto.sol - Support for google.protobuf.FieldDescriptorProto messages
  • GoogleProtobufAny.sol - Existing support documented

Technical Details

Files Modified:

  • protobuf-solidity/src/protoc/plugin/runtime/ProtoBufRuntime.sol - Added float/double encode/decode functions
  • README.md - Added Runtime Enhancements documentation section

Files Added:

  • protobuf-solidity/src/protoc/plugin/runtime/GoogleProtobufDuration.sol
  • protobuf-solidity/src/protoc/plugin/runtime/GoogleProtobufTimestamp.sol
  • protobuf-solidity/src/protoc/plugin/runtime/GoogleProtobufFieldDescriptorProto.sol

New Functions:

  • _decode_float(uint256 p, bytes memory bs) -> (bytes4, uint256)
  • _encode_float(bytes4 x, uint256 p, bytes memory bs) -> uint256
  • _decode_double(uint256 p, bytes memory bs) -> (bytes8, uint256)
  • _encode_double(bytes8 x, uint256 p, bytes memory bs) -> uint256

Use Cases

This enhancement enables:

  • Protobuf schemas with float/double fields to compile successfully
  • buf/validate constraints on floating-point fields
  • Integration with Google well-known types in Solidity contracts
  • Full protobuf type coverage in generated Solidity code

Test Plan

  • Verify float/double functions compile and work correctly
  • Test integration with buf/validate floating-point constraints
  • Confirm Google protobuf types generate proper runtime imports
  • Validate backward compatibility with existing integer-only schemas

Impact

Expands the plugin's protobuf type support to include all standard types, enabling more comprehensive protobuf schema usage in Solidity projects.

- Add _decode_float and _encode_float functions for 32-bit float support
- Add _decode_double and _encode_double functions for 64-bit double support
- Include GoogleProtobufDuration.sol runtime library
- Include GoogleProtobufTimestamp.sol runtime library
- Include GoogleProtobufFieldDescriptorProto.sol runtime library
- Update documentation with runtime enhancements section
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