Stream: beginners

Topic: Num.toBytes


view this post on Zulip Fabian Schmalzried (Dec 26 2023 at 18:31):

Is there a function to turn a Num to a byte array? I could not find anything.

view this post on Zulip Brendan Hansknecht (Dec 26 2023 at 18:36):

I don't think so currently. I believe we want to add a form that goes from numbers to the correct sized tuple.

view this post on Zulip Fabian Schmalzried (Dec 26 2023 at 18:51):

I see, that would make accessing bytes easier. Is there an easy way to turn a tuple to List. The Encoding Ability needs a List U8, so it might be helpful to have.

view this post on Zulip Brendan Hansknecht (Dec 26 2023 at 19:22):

None currenlty

view this post on Zulip Brendan Hansknecht (Dec 26 2023 at 19:22):

Would have to deconstruct and assign

view this post on Zulip Brendan Hansknecht (Dec 26 2023 at 19:24):

(a, b, c, d) = tup
list = [a, b, c, d]

That or use the getters

list = [tup.0, tup.1, tup.2, tup.3]

view this post on Zulip Luke Boswell (Dec 27 2023 at 00:38):

Brendan Hansknecht said:

I don't think so currently. I believe we want to add a form that goes from numbers to the correct sized tuple.

Do we need to discuss this more with a specific proposal? Or can we go straight to an Issue and imementation if it's pretty straightforward? I'm keen to progress this as I would really like to use it.

view this post on Zulip Brendan Hansknecht (Dec 27 2023 at 01:05):

Might be worth discussing a bit due to:

  1. Questions around lists vs tuples
  2. Want to ensure all the to and from byte functions are symmetric and work well together.

Kinda minor, but probably worth discussing. Cause I think as the current plan stands, fromBytes would take a list, but toBytes would generate a tuple. Need to decide the trade off between convenience and avoiding allocation. Might be a case where we also need functions to convert tuples to lists and back, but not fully sure.

view this post on Zulip Fabian Schmalzried (Dec 27 2023 at 01:07):

I assume both toBytes and fromBytes will need an endianness parameter?

view this post on Zulip Brendan Hansknecht (Dec 27 2023 at 01:07):

Yep. That is the plan

view this post on Zulip Luke Boswell (Dec 27 2023 at 04:21):

Ohk, I'm definitely thinking a proposal will help then. My thoughts were both sides should be tuples. I'll try and write something up then.


Last updated: Jul 06 2025 at 12:14 UTC