Serde icon indicating copy to clipboard operation
Serde copied to clipboard

Protobuf Formatter

Open withinboredom opened this issue 7 months ago • 1 comments

Description

This contains and merges with https://github.com/Crell/Serde/pull/84.

This adds the formatter for protobuf and provides serialization for all the different types introduced in #84. Each type has slightly different encoding which needs to be correct for other systems to communicate with PHP. The only issue is that PHP doesn’t support unsigned integers. This means that any negative number in PHP going to the unsigned integer types is not actually negative (see: twos-complement), but the "sign-bit" is used as part of the number. Further, this support also needs to function on 32-bit systems; thus it allows using "large numbers" in a string — assuming the developer is using bcmath or gmp for large integers.

Motivation and context

Protobuffers are a binary format for storing structured data, and Serde is well suited for this.

How has this been tested?

This is from a larger work and I’m migrating it out. It’s battletested, but formal tests will come when I finish porting the deformatter.

Screenshots (if appropriate)

Types of changes

What types of changes does your code introduce? Put an x in all the boxes that apply:

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

Go over all the following points, and put an x in all the boxes that apply.

Please, please, please, don't send your pull request until all of the boxes are ticked. Once your pull request is created, it will trigger a build on our continuous integration server to make sure your tests and code style pass.

  • [x] I have read the CONTRIBUTING document.
  • [x] My pull request addresses exactly one patch/feature.
  • [x] I have created a branch for this patch/feature.
  • [x] Each individual commit in the pull request is meaningful.
  • [ ] I have added tests to cover my changes.
  • [ ] If my change requires a change to the documentation, I have updated it accordingly.

If you're unsure about any of these, don't hesitate to ask. We're here to help!

withinboredom avatar May 30 '25 17:05 withinboredom