|
27 | 27 | +rt jvm org.eolang:eo-runtime:0.0.0 |
28 | 28 | +rt node eo2js-runtime:0.0.0 |
29 | 29 | +version 0.0.0 |
30 | | -+unlint object-has-data |
31 | | -+unlint broken-alias-second |
32 | 30 |
|
33 | 31 | # The object encapsulates a chain of bytes, adding a few |
34 | 32 | # convenient operations to it. Objects like `int`, `string`, |
|
37 | 35 | data > @ |
38 | 36 | $ > as-bytes |
39 | 37 | eq 01- > as-bool |
40 | | - |
41 | 38 | # Turn this chain of eight bytes into a number. |
42 | 39 | # If there are less or more than eight bytes, there will |
43 | 40 | # be an error returned. |
44 | | - [] > as-number |
45 | | - if. > @ |
46 | | - eq nan.as-bytes |
47 | | - nan |
| 41 | + if. > as-number |
| 42 | + eq nan.as-bytes |
| 43 | + nan |
| 44 | + if. |
| 45 | + eq positive-infinity.as-bytes |
| 46 | + positive-infinity |
48 | 47 | if. |
49 | | - eq positive-infinity.as-bytes |
50 | | - positive-infinity |
| 48 | + eq negative-infinity.as-bytes |
| 49 | + negative-infinity |
51 | 50 | if. |
52 | | - eq negative-infinity.as-bytes |
53 | | - negative-infinity |
54 | | - if. |
55 | | - size.eq 8 |
56 | | - number ^ |
57 | | - error |
58 | | - sprintf |
59 | | - "Can't convert non 8 length bytes to a number, bytes are %x" |
60 | | - * ^ |
| 51 | + size.eq 8 |
| 52 | + number $ |
| 53 | + error |
| 54 | + sprintf |
| 55 | + "Can't convert non 8 length bytes to a number, bytes are %x" |
| 56 | + * $ |
| 57 | + # Turn this chain of eight bytes into a i64 number. |
| 58 | + # If there are less or more than eight bytes, there will |
| 59 | + # be an error returned. |
| 60 | + if. > as-i64 |
| 61 | + size.eq 8 |
| 62 | + i64 $ |
| 63 | + error |
| 64 | + sprintf |
| 65 | + "Can't convert non 8 length bytes to i64, bytes are %x" |
| 66 | + * $ |
| 67 | + # Turn this chain of four bytes into a i32 number. |
| 68 | + # If there are less or more than four bytes, there will |
| 69 | + # be an error returned. |
| 70 | + if. > as-i32 |
| 71 | + size.eq 4 |
| 72 | + i32 $ |
| 73 | + error |
| 74 | + sprintf |
| 75 | + "Can't convert non 4 length bytes to i32, bytes are %x" |
| 76 | + * $ |
| 77 | + # Turn this chain of two bytes into a i16 number. |
| 78 | + # If there are less or more than two bytes, there will |
| 79 | + # be an error returned. |
| 80 | + if. > as-i16 |
| 81 | + size.eq 2 |
| 82 | + i16 $ |
| 83 | + error |
| 84 | + sprintf |
| 85 | + "Can't convert non 2 length bytes to i16, bytes are %x" |
| 86 | + * $ |
61 | 87 |
|
62 | 88 | # Equals to another object. |
63 | 89 | # A condition where two objects have the same value or content. |
|
70 | 96 | # Represents a sub-sequence inside the current one. |
71 | 97 | [start len] > slice /org.eolang.bytes |
72 | 98 |
|
73 | | - # Turn this chain of eight bytes into a i64 number. |
74 | | - # If there are less or more than eight bytes, there will |
75 | | - # be an error returned. |
76 | | - [] > as-i64 |
77 | | - if. > @ |
78 | | - size.eq 8 |
79 | | - i64 ^ |
80 | | - error |
81 | | - sprintf |
82 | | - "Can't convert non 8 length bytes to i64, bytes are %x" |
83 | | - * ^ |
84 | | - |
85 | | - # Turn this chain of four bytes into a i32 number. |
86 | | - # If there are less or more than four bytes, there will |
87 | | - # be an error returned. |
88 | | - [] > as-i32 |
89 | | - if. > @ |
90 | | - size.eq 4 |
91 | | - i32 ^ |
92 | | - error |
93 | | - sprintf |
94 | | - "Can't convert non 4 length bytes to i32, bytes are %x" |
95 | | - * ^ |
96 | | - |
97 | | - # Turn this chain of two bytes into a i16 number. |
98 | | - # If there are less or more than two bytes, there will |
99 | | - # be an error returned. |
100 | | - [] > as-i16 |
101 | | - if. > @ |
102 | | - size.eq 2 |
103 | | - i16 ^ |
104 | | - error |
105 | | - sprintf |
106 | | - "Can't convert non 2 length bytes to i16, bytes are %x" |
107 | | - * ^ |
108 | | - |
109 | 99 | # Calculate the bitwise and operation. |
110 | 100 | [b] > and /org.eolang.bytes |
111 | 101 |
|
|
0 commit comments