Closed connor4312 closed 8 years ago
I like this one :) I'm just wondering what the best name for the function is. Can you give me a usage example of how you use this? I suspect you're using it somehow :)
It might even be reasonable to have this replace the old method, I'm not sure?
Maybe IntBytes makes sense in a way that isn't clicking in my head :) Which is very possible :)
Yea, I would have preferred to use Bytes()
, but that was taken 😉
The idea is that this would be useful any time consumers need to store the snowflake ID in any kind of binary storage (such as BoltDB keys, perhaps), or transmit them over the network. It's more efficient to use an 8-byte array, which is easily sortable and monotonic (a boon for B+-tree based stores like BoltDB or MySQL) than to marshal the ID to a string then convert that to a 20-byte sequence.
I think it would be reasonable to replace the old method, but that is a breaking change, so it should be done with care...
Thanks! 😄
You're welcome! Sorry I was slow.
Previously there was a method called
Bytes() []byte
, but that simply returned the string representation as a byte slice. Not too efficient for storage and transport. This PR adds a method which returns a raw representation of the ID as an 8-bit byte array.Also marshalling it into a byte array is ~10x faster than the JSON marshaller, since it looks like you folks like benchmarks 😉