19 using namespace basis;
28 for (
int i = 0; i < size_in_bytes; i++) {
29 attach_into +=
abyte(temp % 0x100);
37 for (
int i = 0; i < size_in_bytes; i++) {
39 accumulator += eat_from[size_in_bytes - i - 1];
41 eat_from.
zap(0, size_in_bytes - 1);
47 {
return 2 *
sizeof(int) + packed_form.
length(); }
52 packed_form += to_attach;
59 if (packed_form.
length() < (
int)len)
return false;
60 to_detach = packed_form.
subarray(0, len - 1);
61 packed_form.
zap(0, len - 1);
75 if (packed_form.
length() < 4)
return false;
87 if (packed_form.
length() < 2)
return false;
95 { packed_form += to_attach; }
99 if (packed_form.
length() < 1)
return false;
100 to_detach = packed_form[0];
101 packed_form.
zap(0, 0);
141 {
return detach(packed_form, (
abyte &)to_detach); }
153 if (!
detach(packed_form, chomp))
return false;
164 double mod_part = fmod(input, 1.0);
166 double to_return = input - mod_part;
183 double mantissa = frexp(to_pack, &exponent);
184 abyte pos = mantissa < 0.0? false :
true;
185 mantissa = fabs(mantissa);
188 attach(packed_form, exponent);
193 for (
int i = 0; i < 9; i++) {
198 mantis +=
abyte(dig1 * 16 + dig2);
200 attach(packed_form, mantis);
207 if (packed_form.
length() < 1)
return false;
208 abyte pos = packed_form[0];
210 packed_form.
zap(0, 0);
212 if (!
detach(packed_form, exponent))
return false;
215 if (!
detach(packed_form, mantis))
return false;
217 for (
int i = mantis.
last(); i >= 0; i--) {
218 abyte chop = mantis[i];
219 double dig1 = chop / 16;
221 double dig2 = chop % 16;
229 to_unpack = ldexp(mantissa, exponent);
230 if (!pos) to_unpack = -1.0 * to_unpack;
238 {
attach(packed_form,
double(to_pack)); }
243 bool to_return =
detach(packed_form, real_unpack);
244 to_unpack = (float)real_unpack;
257 first_part = first_part | (to_attach & 0x0000ffff);
259 second_part = second_part | (to_attach & 0xffff0000);
261 attach(packed_form, first_part);
262 attach(packed_form, second_part);
269 if (!
detach(packed_form, first_part))
return false;
270 if (!
detach(packed_form, second_part))
return false;
277 to_detach = int( (second_part & 0xffff0000) + (first_part & 0x0000ffff) );
array subarray(int start, int end) const
Returns the array segment between the indices "start" and "end".
int length() const
Returns the current reported length of the allocated C array.
outcome zap(int start, int end)
Deletes from "this" the objects inclusively between "start" and "end".
int last() const
Returns the last valid element in the array.
A very common template for a dynamic array of bytes.
The guards collection helps in testing preconditions and reporting errors.
unsigned char abyte
A fairly important unit which is seldom defined...
void attach(byte_array &packed_form, const char *to_attach)
Packs a character string "to_attach" into "packed_form".
long int signed_long
Abbreviated name for signed long integers.
unsigned int un_int
Abbreviated name for unsigned integers.
bool detach(byte_array &packed_form, astring &to_detach)
Unpacks a character string "to_attach" from "packed_form".
unsigned short un_short
Abbreviated name for unsigned short integers.
A dynamic container class that holds any kind of object via pointers.
void snag_out(byte_array &eat_from, basis::un_int &accumulator, int size_in_bytes)
int packed_size(double to_pack)
Reports how large the "to_pack" will be as a stream of bytes.
bool obscure_detach(byte_array &packed_form, un_int &to_detach)
shifts the number back and checks validity, false returned if corrupted.
void obscure_attach(byte_array &packed_form, un_int to_attach)
like the normal attach but shifts in some recognizable sentinel data.
double break_off_digit(double &input)
void rotate_in(byte_array &attach_into, int to_attach, int size_in_bytes)