···288288 ))
289289 }
290290}
291291+292292+/// Integers larger than 64 bits are truncated to 64 bits
293293+///
294294+/// Gleam floats are 64 bit so they are always encoded as a 64 bit float in CBOR.
295295+pub fn to_bit_array(cbor: Cbor) -> BitArray {
296296+ case cbor {
297297+ UnsignedInt(num:) ->
298298+ case num {
299299+ x if x <= 24 -> <<0b000:size(3), x:size(5)>>
300300+ x if x <= 255 -> <<0b000:size(3), 24:size(5), x:size(8)>>
301301+ x if x <= 65_535 -> <<0b000:size(3), 25:size(5), x:size(16)>>
302302+ x if x <= 4_294_967_295 -> <<0b000:size(3), 26:size(5), x:size(32)>>
303303+ x -> <<0b000:size(3), 27:size(5), x:size(64)>>
304304+ }
305305+306306+ NegativeInt(num:) ->
307307+ case -1 - num {
308308+ x if x <= 24 -> <<0b001:size(3), x:size(5)>>
309309+ x if x <= 255 -> <<0b001:size(3), 24:size(5), x:size(8)>>
310310+ x if x <= 65_535 -> <<0b001:size(3), 25:size(5), x:size(16)>>
311311+ x if x <= 4_294_967_295 -> <<0b001:size(3), 26:size(5), x:size(32)>>
312312+ x -> <<0b001:size(3), 27:size(5), x:size(64)>>
313313+ }
314314+315315+ ByteString(bytes:) -> todo as "byte string"
316316+ TextString(text:) -> todo as "text string"
317317+ Array(items:) -> todo as "array"
318318+ Map(items:) -> todo as "map"
319319+ Tag(num:) -> todo as "tag"
320320+ Float(num:) ->
321321+ case num {
322322+ Infinity -> <<
323323+ 0b111:size(3),
324324+ 27:size(5),
325325+ 0b0_11111111111_0000000000000000000000000000000000000000000000000000:size(64),
326326+ >>
327327+ NegativeInfinity -> <<
328328+ 0b111:size(3),
329329+ 27:size(5),
330330+ 0b1_11111111111_0000000000000000000000000000000000000000000000000000:size(64),
331331+ >>
332332+ Number(num:) -> <<
333333+ 0b111:size(3),
334334+ 27:size(5),
335335+ num:float-size(64),
336336+ >>
337337+ }
338338+ SimpleValue(value:) -> todo as "simple value"
339339+ }
340340+}