Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

feat: add VersionedMessage.deserializeMessageVersion utility function #27415

Merged
merged 1 commit into from
Aug 29, 2022

Conversation

jstarry
Copy link
Contributor

@jstarry jstarry commented Aug 26, 2022

Problem

Lack of utility function to check the version of a serialized message without fully deserializing the message

Summary of Changes

  • Added VersionedMessage.deserializeMessageVersion

Fixes #

@codecov
Copy link

codecov bot commented Aug 26, 2022

Codecov Report

Merging #27415 (bfa94c0) into master (e779032) will increase coverage by 0.0%.
The diff coverage is n/a.

@@           Coverage Diff            @@
##           master   #27415    +/-   ##
========================================
  Coverage    76.9%    76.9%            
========================================
  Files          48       51     +3     
  Lines        2505     2660   +155     
  Branches      355      364     +9     
========================================
+ Hits         1927     2048   +121     
- Misses        448      481    +33     
- Partials      130      131     +1     

Copy link
Contributor

@steveluscher steveluscher left a comment

Choose a reason for hiding this comment

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

@@ -5,17 +5,26 @@ import {MessageV0} from './v0';
export type VersionedMessage = Message | MessageV0;
// eslint-disable-next-line no-redeclare
export const VersionedMessage = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't checked how tree-shakers treat this. If I do:

import {VersionedMessage} from 'src/message/versioned';
// ...but then only use one function
if (VersionedMessage.deserializeMessageVersion(message) === 'legacy') {
  /* ... */
}

…does the compiler shake out the other methods I haven't used?

I know it definitely works if you export each function.

export function deserializeMessageVersion(...) { ... }

…then

import {deserializeMessageVersion} from 'src/message/versioned';
if (deserializeMessageVersion(message) === 'legacy') {
  /* ... */
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good question, I'd like to punt on this for now and would happily accept / implement a change that's more tree-shaker friendly if it's an issue

@jstarry jstarry merged commit ada493f into solana-labs:master Aug 29, 2022
@jstarry jstarry deleted the web3/get-message-version branch August 29, 2022 20:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants