Skip to content

refactor(encoding): replace msgpack with JSON encoding#115

Merged
AnnatarHe merged 2 commits intomainfrom
refactor/msgpack-to-json-encoding
Oct 2, 2025
Merged

refactor(encoding): replace msgpack with JSON encoding#115
AnnatarHe merged 2 commits intomainfrom
refactor/msgpack-to-json-encoding

Conversation

@AnnatarHe
Copy link
Copy Markdown
Contributor

Summary

  • Replaced msgpack encoding with standard JSON encoding across the codebase
  • Updated daemon sync handler to use JSON marshaling
  • Modified handshake service to use JSON instead of msgpack

Rationale

This change simplifies the serialization format by using standard JSON encoding instead of msgpack. JSON is more widely supported and easier to debug, while still providing adequate performance for our use case.

Changes

  • daemon/handlers.sync.go: Switch from msgpack.Marshal to json.Marshal
  • model/handshake.go: Replace msgpack with JSON in Init and Check methods
  • model/handshake_test.go: Update tests to reflect JSON encoding

Test plan

  • Verify daemon sync functionality works correctly with JSON encoding
  • Test handshake initialization and check operations
  • Run existing test suite to ensure no regressions
  • Validate backward compatibility if needed

🤖 Generated with Claude Code (https://claude.com/claude-code)

- Switch from msgpack to JSON encoding in daemon sync handler
- Replace msgpack with JSON in handshake service
- Update tests to use JSON encoding
- Simplifies serialization and improves compatibility

🤖 Generated with Claude Code (https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @AnnatarHe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the project's serialization mechanism by migrating from msgpack to standard JSON encoding. The primary goal is to leverage JSON's widespread support and ease of debugging, which is deemed sufficient for current performance requirements. This change impacts the daemon's synchronization logic and the handshake service's data handling, along with their respective tests.

Highlights

  • Encoding Standardisation: Replaced msgpack encoding with standard JSON encoding across the codebase for improved compatibility and debugging.
  • Daemon Sync Handler Update: The daemon's sync handler was updated to utilize JSON marshaling for its payload serialization.
  • Handshake Service Modification: The handshake service's Init and Check methods now use JSON for data serialization instead of msgpack.
  • Test Suite Alignment: Corresponding test cases in handshake_test.go were updated to reflect the switch to JSON encoding and Content-Type headers.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aims to replace msgpack with JSON encoding, which is a good move for standardization and debuggability. The changes in the handshake service and tests are a good start, but the refactoring appears to be incomplete and has introduced a critical issue.

Specifically:

  • In model/handshake.go, the send function still sets the Content-Type header to application/msgpack, which will cause the handshake to fail since the payload is now JSON.
  • The refactoring in daemon/handlers.sync.go is partial; the file still contains logic that uses the msgpack library.
  • Several other parts of the codebase, such as model/api.base.go, still have dependencies on msgpack.

I've added specific comments for the critical issue in model/handshake.go and the incomplete refactoring. Please address these issues to ensure the functionality works correctly and consider completing the msgpack to JSON migration across the rest of the codebase for consistency.

Comment thread model/handshake.go
}

jsonData, err := msgpack.Marshal(data)
jsonData, err := json.Marshal(data)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

While you've correctly switched to json.Marshal here, the send function (called on line 111) still hardcodes the Content-Type header as "application/msgpack". This will cause the server to reject the request because the payload is now JSON.

This needs to be updated to "application/json" in the send function.

Additionally, for code cleanup, the msgpack struct tags in handshakeInitRequest (lines 79-81) are now redundant and should be removed.

Comment thread model/handshake.go
}

jsonData, err := msgpack.Marshal(data)
jsonData, err := json.Marshal(data)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

Similar to the Init function, you've switched to json.Marshal here, but the send function (called on line 138) will send the request with an incorrect Content-Type of "application/msgpack". This should be "application/json".

Also, the msgpack tag in the handshakeCheckRequest struct (line 124) should be removed as it's no longer needed.

Comment thread daemon/handlers.sync.go
}

buf, err := msgpack.Marshal(payload)
buf, err := json.Marshal(payload)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While you've updated this Marshal call to use JSON, the function still uses msgpack at the beginning (lines 14-21) to process the socketMsgPayload. To complete the refactoring in this file and fully remove the msgpack dependency, that initial processing should also be updated to use json.Marshal and json.Unmarshal.

Update the HTTP request header from application/msgpack to application/json
as part of the migration from msgpack to JSON encoding.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 20.53% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
daemon/handlers.sync.go 67.04% <100.00%> (ø)
model/handshake.go 61.29% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AnnatarHe AnnatarHe merged commit d7f07ee into main Oct 2, 2025
3 checks passed
@AnnatarHe AnnatarHe deleted the refactor/msgpack-to-json-encoding branch October 2, 2025 16:31
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