Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement encoding flags and deep-doc encoding #33

Merged
merged 9 commits into from
Dec 12, 2023

Conversation

sarvalabs-manish
Copy link
Member

This PR significantly revamps the document encoding/decoding implementations to support deep document encoding as well as enables the ability to use encoding options flags when using automatic serialization and deserialization functions.

  • Polorize and Depolorize functions as well as the NewPolorizer and NewDepolorizer constructors now accept a variadic set of EncodingOptions to alter buffer behavior.
  • DocumentEncode function has been replaced by PolorizeDocument which only performs shallow doc encoding on the highest order type (if supported). Deep document encoding will require buffer altering flags to the regular Polorize function
  • The NewPackPolorizer function has been removed.
  • readbuffer has new methods decodeBytesFromPack and decodeDocument (replaces the documentEncode function)
  • A wireConfig type and a private encoding option inheritCfg enable the new encoding flags mechanic.

The currently available EncodingOption functions are as follows:

  • DocStructs: Encode all structs encountered with document encoding
  • DocStringMaps: Encode all string-keyed maps encountered with document encoding
  • PackedBytes: Encode all []byte typed values with pack-encoding instead of word-encoding (increases wire size)

- added a wireConfig type and EncodingOptions option function type
- refactored NewPolorizer and Polorize functions to accept EncodingOptions
- added the PackedBytes option that can be used to serialise bytes as a packed wire comprised of uint8 items instead of a singular word
- refactored Polorizer.PolorizeBytes method to check the wire config for packed bytes status and serialize using the the polorizeByteAsPack method
- refactor NewDepolorizer to allow passing EncodingOptions
- removed the NewPackDepolorizer constructor
- added a method decodeBytesFromPack to decode a pack encoded uint values into an array of bytes
- refactored testObject into testSerialization that accepts EncodingOptions and tests the serialization consistency by applying the options at every step
- added test cases for packed encoding of bytes in TestWord and TestSequence
- added new encoding options for enforcing doc encoding of structs and string maps respectively
- added a new encoding options to accept a wireConfig to inherit, which can be used to pass on configurations to nested encoding buffers
- added methods polorizeStructIntoDocument and polorizeStrMapIntoDocument to encode the appropriate types into Document objects
- refactor polorizeMapValue and polorizeStructValue to check for config cases to encode documents
- refactored document encoding test cases and examples
- refactored DocumentEncode to PolorizeDocument only serializes the top level struct into a Document if compatible and it now accepts encoding options
- refactor document.Set method to accept encoding options
- refactored documentDecode function into a method of readbuffer called decodeDocument
- refactor depolorizeMapValue and depolorizeStructValue methods to handle encoding config cases for document encoding
@sarvalabs-manish sarvalabs-manish added enhancement New feature or request bugfix Fix for bug labels Dec 12, 2023
@sarvalabs-manish sarvalabs-manish added this to the Go POLO v0.4.0 milestone Dec 12, 2023
@sarvalabs-manish sarvalabs-manish self-assigned this Dec 12, 2023
@sarvalabs-manish sarvalabs-manish merged commit cdbf969 into develop Dec 12, 2023
2 checks passed
@sarvalabs-manish sarvalabs-manish deleted the feature/encoding-flags branch December 12, 2023 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fix for bug enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants