question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Encoding error for single item Enums

See original GitHub issue

Substrate encodes a single item Enum with an added leading zero while Polkadot encodes a single item Enum with an unnecessary (?) extra 255, breaking interchangeability between both ends.

hex::encode(some_single_item_enum.encode()); // Gives, for example, 001234
someSingleItemEnum.toHex(); // Gives 0x00ff1234

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jacogrcommented, Dec 13, 2019

The Address encoding is very explicit and has a special serialization, enum-like - the first byte indicates if it is an AccountId or AccountIndex. AccountId by itself will be without, since there is not “one or the other”.

TL;DR Address !== AccountId, these are distinct types

1reaction
jacogrcommented, Dec 13, 2019

Ok, has a single-entry test added here - https://github.com/polkadot-js/api/pull/1670 - all encoded exactly as expected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Is Encoding not an enumeration? - Stack Overflow
No, it is not an enum. It is a class with static properties. Something like this: public class Encoding { public static Encoding...
Read more >
Split error enums based on operations · Issue #205 - GitHub
Currently the source has one large enum for decoding and another for encoding. It likely would be cleaner if there were enums specific...
Read more >
Serialization of enum with associated type | topolog's tech blog
When encoding an object we put all the properties to the container and then this container is being serialised to the binary data....
Read more >
Splitting a JSON object into an enum and an associated object ...
Once the associated value is decoded, I can assign the appropriate enum case and associated value to self , and the decoding is...
Read more >
Build Enumerations of Constants With Python's Enum
Providing a single source of truth and consistency throughout the code. Now that you know the basics of enumerations in programming and in ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found