protocolbuffers / protobuf-javascript

BSD 3-Clause "New" or "Revised" License
330 stars 66 forks source link

Why map.js sort keys? #185

Open start940315 opened 6 months ago

start940315 commented 6 months ago

In some situation, I need to generate different result according to different order that items are inserted. But I read your code and find that you sort the key order, which generate the same result on different order. Can you change the behavior?

dibenede commented 6 months ago

According to the official protobuf spec, map iteration order is undefined. To my knowledge, some implementations do implement insertion order while others (notably golang) do not.

This is something we could potentially change in the future, but you are better off using a repeated field if a particular order matters to you.