25 DCSimpleParameter::NestedFieldMap DCSimpleParameter::_nested_field_map;
37 _pack_type = PT_invalid;
38 _nested_type = ST_invalid;
39 _has_nested_fields =
false;
40 _bytes_per_element = 0;
41 _num_length_bytes = 2;
48 _pack_type = PT_array;
49 _nested_type = ST_int8;
50 _has_nested_fields =
true;
51 _bytes_per_element = 1;
55 _pack_type = PT_array;
56 _nested_type = ST_int16;
57 _has_nested_fields =
true;
58 _bytes_per_element = 2;
62 _pack_type = PT_array;
63 _nested_type = ST_int32;
64 _has_nested_fields =
true;
65 _bytes_per_element = 4;
69 _pack_type = PT_array;
70 _nested_type = ST_uint8;
71 _has_nested_fields =
true;
72 _bytes_per_element = 1;
76 _pack_type = PT_array;
77 _nested_type = ST_uint16;
78 _has_nested_fields =
true;
79 _bytes_per_element = 2;
83 _pack_type = PT_array;
84 _nested_type = ST_uint32;
85 _has_nested_fields =
true;
86 _bytes_per_element = 4;
89 case ST_uint32uint8array:
90 _pack_type = PT_array;
91 _has_nested_fields =
true;
92 _bytes_per_element = 5;
96 _num_length_bytes = 4;
101 _pack_type = PT_blob;
102 _nested_type = ST_uint8;
103 _has_nested_fields =
true;
104 _bytes_per_element = 1;
108 _pack_type = PT_string;
109 _nested_type = ST_char;
110 _has_nested_fields =
true;
111 _bytes_per_element = 1;
117 _has_fixed_byte_size =
true;
118 _fixed_byte_size = 1;
123 _has_fixed_byte_size =
true;
124 _fixed_byte_size = 2;
129 _has_fixed_byte_size =
true;
130 _fixed_byte_size = 4;
134 _pack_type = PT_int64;
135 _has_fixed_byte_size =
true;
136 _fixed_byte_size = 8;
140 _pack_type = PT_string;
141 _has_fixed_byte_size =
true;
142 _fixed_byte_size = 1;
146 _pack_type = PT_uint;
147 _has_fixed_byte_size =
true;
148 _fixed_byte_size = 1;
152 _pack_type = PT_uint;
153 _has_fixed_byte_size =
true;
154 _fixed_byte_size = 2;
158 _pack_type = PT_uint;
159 _has_fixed_byte_size =
true;
160 _fixed_byte_size = 4;
164 _pack_type = PT_uint64;
165 _has_fixed_byte_size =
true;
166 _fixed_byte_size = 8;
170 _pack_type = PT_double;
171 _has_fixed_byte_size =
true;
172 _fixed_byte_size = 8;
178 _has_fixed_structure = _has_fixed_byte_size;
180 set_divisor(divisor);
182 if (_nested_type != ST_invalid) {
183 _nested_field = create_nested_field(_nested_type, _divisor);
185 }
else if (_type == ST_uint32uint8array) {
188 _nested_field = create_uint32uint8_type();
191 _nested_field =
nullptr;
202 _divisor(copy._divisor),
203 _nested_field(copy._nested_field),
204 _bytes_per_element(copy._bytes_per_element),
205 _orig_range(copy._orig_range),
206 _has_modulus(copy._has_modulus),
207 _orig_modulus(copy._orig_modulus),
208 _int_range(copy._int_range),
209 _uint_range(copy._uint_range),
210 _int64_range(copy._int64_range),
211 _uint64_range(copy._uint64_range),
212 _double_range(copy._double_range),
213 _uint_modulus(copy._uint_modulus),
214 _uint64_modulus(copy._uint64_modulus),
215 _double_modulus(copy._double_modulus)
223 as_simple_parameter() {
231 as_simple_parameter()
const {
249 return _type != ST_invalid;
277 return _orig_modulus;
297 return !(_pack_type == PT_string || _pack_type == PT_blob);
309 if (_pack_type == PT_string || _pack_type == PT_blob || modulus <= 0.0) {
314 _orig_modulus = modulus;
316 bool range_error =
false;
317 _double_modulus = modulus * _divisor;
318 _uint64_modulus = (uint64_t)floor(_double_modulus + 0.5);
319 _uint_modulus = (
unsigned int)_uint64_modulus;
326 validate_uint64_limits(_uint64_modulus - 1, 7, range_error);
331 validate_uint64_limits(_uint64_modulus - 1, 15, range_error);
336 validate_uint64_limits(_uint64_modulus - 1, 31, range_error);
340 validate_uint64_limits(_uint64_modulus - 1, 63, range_error);
346 validate_uint64_limits(_uint64_modulus - 1, 8, range_error);
351 validate_uint64_limits(_uint64_modulus - 1, 16, range_error);
356 validate_uint64_limits(_uint64_modulus - 1, 32, range_error);
377 if (_pack_type == PT_string || _pack_type == PT_blob || divisor == 0) {
382 if ((_divisor != 1) &&
383 (_pack_type == PT_int || _pack_type == PT_int64 ||
384 _pack_type == PT_uint || _pack_type == PT_uint64)) {
385 _pack_type = PT_double;
388 if (_has_range_limits) {
389 set_range(_orig_range);
392 set_modulus(_orig_modulus);
406 bool range_error =
false;
410 _has_range_limits = (num_ranges != 0);
417 for (i = 0; i < num_ranges; i++) {
418 int64_t min = (int64_t)floor(range.
get_min(i) * _divisor + 0.5);
419 int64_t max = (int64_t)floor(range.
get_max(i) * _divisor + 0.5);
420 validate_int64_limits(min, 8, range_error);
421 validate_int64_limits(max, 8, range_error);
422 _int_range.add_range((
int)min, (
int)max);
429 for (i = 0; i < num_ranges; i++) {
430 int64_t min = (int64_t)floor(range.
get_min(i) * _divisor + 0.5);
431 int64_t max = (int64_t)floor(range.
get_max(i) * _divisor + 0.5);
432 validate_int64_limits(min, 16, range_error);
433 validate_int64_limits(max, 16, range_error);
434 _int_range.add_range((
int)min, (
int)max);
441 for (i = 0; i < num_ranges; i++) {
442 int64_t min = (int64_t)floor(range.
get_min(i) * _divisor + 0.5);
443 int64_t max = (int64_t)floor(range.
get_max(i) * _divisor + 0.5);
444 validate_int64_limits(min, 32, range_error);
445 validate_int64_limits(max, 32, range_error);
446 _int_range.add_range((
int)min, (
int)max);
451 _int64_range.clear();
452 for (i = 0; i < num_ranges; i++) {
453 int64_t min = (int64_t)floor(range.
get_min(i) * _divisor + 0.5);
454 int64_t max = (int64_t)floor(range.
get_max(i) * _divisor + 0.5);
455 _int64_range.add_range(min, max);
463 for (i = 0; i < num_ranges; i++) {
464 uint64_t min = (uint64_t)floor(range.
get_min(i) * _divisor + 0.5);
465 uint64_t max = (uint64_t)floor(range.
get_max(i) * _divisor + 0.5);
466 validate_uint64_limits(min, 8, range_error);
467 validate_uint64_limits(max, 8, range_error);
468 _uint_range.add_range((
unsigned int)min, (
unsigned int)max);
475 for (i = 0; i < num_ranges; i++) {
476 uint64_t min = (uint64_t)floor(range.
get_min(i) * _divisor + 0.5);
477 uint64_t max = (uint64_t)floor(range.
get_max(i) * _divisor + 0.5);
478 validate_uint64_limits(min, 16, range_error);
479 validate_uint64_limits(max, 16, range_error);
480 _uint_range.add_range((
unsigned int)min, (
unsigned int)max);
487 for (i = 0; i < num_ranges; i++) {
488 uint64_t min = (uint64_t)floor(range.
get_min(i) * _divisor + 0.5);
489 uint64_t max = (uint64_t)floor(range.
get_max(i) * _divisor + 0.5);
490 validate_uint64_limits(min, 32, range_error);
491 validate_uint64_limits(max, 32, range_error);
492 _uint_range.add_range((
unsigned int)min, (
unsigned int)max);
497 _uint64_range.clear();
498 for (i = 0; i < num_ranges; i++) {
499 uint64_t min = (uint64_t)floor(range.
get_min(i) * _divisor + 0.5);
500 uint64_t max = (uint64_t)floor(range.
get_max(i) * _divisor + 0.5);
501 _uint64_range.add_range(min, max);
506 _double_range.clear();
507 for (i = 0; i < num_ranges; i++) {
508 double min = range.
get_min(i) * _divisor;
509 double max = range.
get_max(i) * _divisor;
510 _double_range.add_range(min, max);
517 for (i = 0; i < num_ranges; i++) {
518 uint64_t min = (uint64_t)floor(range.
get_min(i) * _divisor + 0.5);
519 uint64_t max = (uint64_t)floor(range.
get_max(i) * _divisor + 0.5);
520 validate_uint64_limits(min, 16, range_error);
521 validate_uint64_limits(max, 16, range_error);
522 _uint_range.add_range((
unsigned int)min, (
unsigned int)max);
524 if (_uint_range.has_one_value()) {
527 _num_length_bytes = 0;
528 _has_fixed_byte_size =
true;
529 _fixed_byte_size = _uint_range.get_one_value();
530 _has_fixed_structure =
true;
532 _num_length_bytes = 2;
533 _has_fixed_byte_size =
false;
534 _has_fixed_structure =
false;
540 for (i = 0; i < num_ranges; i++) {
541 uint64_t min = (uint64_t)floor(range.
get_min(i) * _divisor + 0.5);
542 uint64_t max = (uint64_t)floor(range.
get_max(i) * _divisor + 0.5);
543 validate_uint64_limits(min, 32, range_error);
544 validate_uint64_limits(max, 32, range_error);
545 _uint_range.add_range((
unsigned int)min, (
unsigned int)max);
547 if (_uint_range.has_one_value()) {
550 _num_length_bytes = 0;
551 _has_fixed_byte_size =
true;
552 _fixed_byte_size = _uint_range.get_one_value();
553 _has_fixed_structure =
true;
555 _num_length_bytes = 4;
556 _has_fixed_byte_size =
false;
557 _has_fixed_structure =
false;
576 if (_bytes_per_element != 0) {
577 return length_bytes / _bytes_per_element;
589 return _nested_field;
597 bool &pack_error,
bool &range_error)
const {
598 double real_value = value * _divisor;
600 if (real_value < 0.0) {
601 real_value = _double_modulus - fmod(-real_value, _double_modulus);
602 if (real_value == _double_modulus) {
606 real_value = fmod(real_value, _double_modulus);
613 int int_value = (int)floor(real_value + 0.5);
614 _int_range.validate(int_value, range_error);
615 validate_int_limits(int_value, 8, range_error);
622 int int_value = (int)floor(real_value + 0.5);
623 _int_range.validate(int_value, range_error);
624 validate_int_limits(int_value, 16, range_error);
631 int int_value = (int)floor(real_value + 0.5);
632 _int_range.validate(int_value, range_error);
639 int64_t int64_value = (int64_t)floor(real_value + 0.5);
640 _int64_range.validate(int64_value, range_error);
648 unsigned int int_value = (
unsigned int)floor(real_value + 0.5);
649 _uint_range.validate(int_value, range_error);
650 validate_uint_limits(int_value, 8, range_error);
657 unsigned int int_value = (
unsigned int)floor(real_value + 0.5);
658 _uint_range.validate(int_value, range_error);
659 validate_uint_limits(int_value, 16, range_error);
666 unsigned int int_value = (
unsigned int)floor(real_value + 0.5);
667 _uint_range.validate(int_value, range_error);
674 uint64_t int64_value = (uint64_t)floor(real_value + 0.5);
675 _uint64_range.validate(int64_value, range_error);
681 _double_range.validate(real_value, range_error);
695 bool &pack_error,
bool &range_error)
const {
696 int int_value = value * _divisor;
698 if (value != 0 && (int_value / value) != (
int)_divisor) {
701 pack_int64(pack_data, (int64_t)value, pack_error, range_error);
705 if (_has_modulus && _uint_modulus != 0) {
707 int_value = _uint_modulus - 1 - (-int_value - 1) % _uint_modulus;
709 int_value = int_value % _uint_modulus;
715 _int_range.validate(int_value, range_error);
716 validate_int_limits(int_value, 8, range_error);
721 _int_range.validate(int_value, range_error);
722 validate_int_limits(int_value, 16, range_error);
727 _int_range.validate(int_value, range_error);
732 _int64_range.validate(int_value, range_error);
741 _uint_range.validate((
unsigned int)int_value, range_error);
742 validate_uint_limits((
unsigned int)int_value, 8, range_error);
750 _uint_range.validate((
unsigned int)int_value, range_error);
751 validate_uint_limits((
unsigned int)int_value, 16, range_error);
759 _uint_range.validate((
unsigned int)int_value, range_error);
767 _uint64_range.validate((
unsigned int)int_value, range_error);
772 _double_range.validate(int_value, range_error);
786 bool &pack_error,
bool &range_error)
const {
787 unsigned int int_value = value * _divisor;
788 if (_has_modulus && _uint_modulus != 0) {
789 int_value = int_value % _uint_modulus;
794 if ((
int)int_value < 0) {
797 _int_range.validate((
int)int_value, range_error);
798 validate_int_limits((
int)int_value, 8, range_error);
803 if ((
int)int_value < 0) {
806 _int_range.validate((
int)int_value, range_error);
807 validate_int_limits((
int)int_value, 16, range_error);
812 if ((
int)int_value < 0) {
815 _int_range.validate((
int)int_value, range_error);
820 if ((
int)int_value < 0) {
823 _int64_range.validate((
int)int_value, range_error);
829 _uint_range.validate(int_value, range_error);
830 validate_uint_limits(int_value, 8, range_error);
835 _uint_range.validate(int_value, range_error);
836 validate_uint_limits(int_value, 16, range_error);
841 _uint_range.validate(int_value, range_error);
846 _uint64_range.validate(int_value, range_error);
851 _double_range.validate(int_value, range_error);
865 bool &pack_error,
bool &range_error)
const {
866 int64_t int_value = value * _divisor;
867 if (_has_modulus && _uint64_modulus != 0) {
869 int_value = _uint64_modulus - 1 - (-int_value - 1) % _uint64_modulus;
871 int_value = int_value % _uint64_modulus;
877 _int_range.validate((
int)int_value, range_error);
878 validate_int64_limits(int_value, 8, range_error);
883 _int_range.validate((
int)int_value, range_error);
884 validate_int64_limits(int_value, 16, range_error);
889 _int_range.validate((
int)int_value, range_error);
890 validate_int64_limits(int_value, 32, range_error);
895 _int64_range.validate(int_value, range_error);
904 _uint_range.validate((
unsigned int)(uint64_t)int_value, range_error);
905 validate_uint64_limits((uint64_t)int_value, 8, range_error);
906 do_pack_uint8(pack_data.
get_write_pointer(1), (
unsigned int)(uint64_t)int_value);
913 _uint_range.validate((
unsigned int)(uint64_t)int_value, range_error);
914 validate_uint64_limits((uint64_t)int_value, 16, range_error);
915 do_pack_uint16(pack_data.
get_write_pointer(2), (
unsigned int)(uint64_t)int_value);
922 _uint_range.validate((
unsigned int)(uint64_t)int_value, range_error);
923 validate_uint64_limits((uint64_t)int_value, 32, range_error);
924 do_pack_uint32(pack_data.
get_write_pointer(4), (
unsigned int)(uint64_t)int_value);
931 _uint64_range.validate((uint64_t)int_value, range_error);
936 _double_range.validate((
double)int_value, range_error);
950 bool &pack_error,
bool &range_error)
const {
951 uint64_t int_value = value * _divisor;
952 if (_has_modulus && _uint64_modulus != 0) {
953 int_value = int_value % _uint64_modulus;
958 if ((int64_t)int_value < 0) {
961 _int_range.validate((
int)(int64_t)int_value, range_error);
962 validate_int64_limits((int64_t)int_value, 8, range_error);
967 if ((int64_t)int_value < 0) {
970 _int_range.validate((
int)(int64_t)int_value, range_error);
971 validate_int64_limits((int64_t)int_value, 16, range_error);
976 if ((int64_t)int_value < 0) {
979 _int_range.validate((
int)(int64_t)int_value, range_error);
980 validate_int64_limits((int64_t)int_value, 32, range_error);
985 if ((int64_t)int_value < 0) {
988 _int64_range.validate((int64_t)int_value, range_error);
994 _uint_range.validate((
unsigned int)int_value, range_error);
995 validate_uint64_limits(int_value, 8, range_error);
1000 _uint_range.validate((
unsigned int)int_value, range_error);
1001 validate_uint64_limits(int_value, 16, range_error);
1006 _uint_range.validate((
unsigned int)int_value, range_error);
1007 validate_uint64_limits(int_value, 32, range_error);
1012 _uint64_range.validate(int_value, range_error);
1017 _double_range.validate((
double)int_value, range_error);
1031 bool &pack_error,
bool &range_error)
const {
1032 size_t string_length = value.length();
1038 if (string_length == 0) {
1041 if (string_length != 1) {
1044 _uint_range.validate((
unsigned int)value[0], range_error);
1051 _uint_range.validate(string_length, range_error);
1052 validate_uint_limits(string_length, 16, range_error);
1053 if (_num_length_bytes != 0) {
1056 pack_data.
append_data(value.data(), string_length);
1060 _uint_range.validate(string_length, range_error);
1061 if (_num_length_bytes != 0) {
1064 pack_data.
append_data(value.data(), string_length);
1077 bool &pack_error,
bool &range_error)
const {
1078 size_t blob_size = value.size();
1084 if (blob_size == 0) {
1087 if (blob_size != 1) {
1090 _uint_range.validate((
unsigned int)value[0], range_error);
1097 _uint_range.validate(blob_size, range_error);
1098 validate_uint_limits(blob_size, 16, range_error);
1099 if (_num_length_bytes != 0) {
1102 pack_data.
append_data((
const char *)value.data(), blob_size);
1106 _uint_range.validate(blob_size, range_error);
1107 if (_num_length_bytes != 0) {
1110 pack_data.
append_data((
const char *)value.data(), blob_size);
1126 if (has_default_value()) {
1130 if (_has_nested_fields) {
1135 unsigned int minimum_length = 0;
1136 if (!_uint_range.is_empty()) {
1137 minimum_length = _uint_range.get_min(0);
1143 for (
unsigned int i = 0; i < minimum_length; i++) {
1161 if (_int_range.is_in_range(0)) {
1162 pack_int(pack_data, 0, pack_error, pack_error);
1164 pack_int(pack_data, _int_range.get_min(0), pack_error, pack_error);
1169 if (_int64_range.is_in_range(0)) {
1170 pack_int64(pack_data, 0, pack_error, pack_error);
1172 pack_int64(pack_data, _int64_range.get_min(0), pack_error, pack_error);
1180 if (_uint_range.is_in_range(0)) {
1181 pack_uint(pack_data, 0, pack_error, pack_error);
1183 pack_uint(pack_data, _uint_range.get_min(0), pack_error, pack_error);
1188 if (_uint64_range.is_in_range(0)) {
1189 pack_uint64(pack_data, 0, pack_error, pack_error);
1191 pack_uint64(pack_data, _uint64_range.get_min(0), pack_error, pack_error);
1196 if (_double_range.is_in_range(0.0)) {
1197 pack_double(pack_data, 0.0, pack_error, pack_error);
1199 pack_double(pack_data, _double_range.get_min(0), pack_error, pack_error);
1217 bool &pack_error,
bool &range_error)
const {
1221 if (p + 1 > length) {
1225 int int_value = do_unpack_int8(data + p);
1226 _int_range.validate(int_value, range_error);
1234 if (p + 2 > length) {
1238 int int_value = do_unpack_int16(data + p);
1239 _int_range.validate(int_value, range_error);
1247 if (p + 4 > length) {
1251 int int_value = do_unpack_int32(data + p);
1252 _int_range.validate(int_value, range_error);
1260 if (p + 8 > length) {
1264 int64_t int_value = do_unpack_int64(data + p);
1265 _int64_range.validate(int_value, range_error);
1266 value = (double)int_value;
1274 if (p + 1 > length) {
1278 unsigned int uint_value = do_unpack_uint8(data + p);
1279 _uint_range.validate(uint_value, range_error);
1287 if (p + 2 > length) {
1291 unsigned int uint_value = do_unpack_uint16(data + p);
1292 _uint_range.validate(uint_value, range_error);
1300 if (p + 4 > length) {
1304 unsigned int uint_value = do_unpack_uint32(data + p);
1305 _uint_range.validate(uint_value, range_error);
1313 if (p + 8 > length) {
1317 uint64_t uint_value = do_unpack_uint64(data + p);
1318 _uint64_range.validate(uint_value, range_error);
1319 value = (double)uint_value;
1326 if (p + 8 > length) {
1330 value = do_unpack_float64(data + p);
1331 _double_range.validate(value, range_error);
1341 if (_divisor != 1) {
1342 value = value / _divisor;
1352 unpack_int(
const char *data,
size_t length,
size_t &p,
int &value,
1353 bool &pack_error,
bool &range_error)
const {
1356 if (p + 1 > length) {
1360 value = do_unpack_int8(data + p);
1361 _int_range.validate(value, range_error);
1366 if (p + 2 > length) {
1370 value = do_unpack_int16(data + p);
1371 _int_range.validate(value, range_error);
1376 if (p + 4 > length) {
1380 value = do_unpack_int32(data + p);
1381 _int_range.validate(value, range_error);
1387 if (p + 8 > length) {
1391 int64_t int_value = do_unpack_uint64(data + p);
1392 _int64_range.validate(int_value, range_error);
1393 value = (int)int_value;
1394 if (value != int_value) {
1405 if (p + 1 > length) {
1409 unsigned int uint_value = do_unpack_uint8(data + p);
1410 _uint_range.validate(uint_value, range_error);
1418 if (p + 2 > length) {
1422 unsigned int uint_value = do_unpack_uint16(data + p);
1423 _uint_range.validate(uint_value, range_error);
1424 value = (int)uint_value;
1431 if (p + 4 > length) {
1435 unsigned int uint_value = do_unpack_uint32(data + p);
1436 _uint_range.validate(uint_value, range_error);
1437 value = (int)uint_value;
1447 if (p + 8 > length) {
1451 uint64_t uint_value = do_unpack_uint64(data + p);
1452 _uint64_range.validate(uint_value, range_error);
1453 value = (int)(
unsigned int)uint_value;
1454 if ((
unsigned int)value != uint_value || value < 0) {
1463 if (p + 8 > length) {
1467 double real_value = do_unpack_float64(data + p);
1468 _double_range.validate(real_value, range_error);
1469 value = (int)real_value;
1479 if (_divisor != 1) {
1480 value = value / _divisor;
1490 unpack_uint(
const char *data,
size_t length,
size_t &p,
unsigned int &value,
1491 bool &pack_error,
bool &range_error)
const {
1495 if (p + 1 > length) {
1499 int int_value = do_unpack_int8(data + p);
1500 _int_range.validate(int_value, range_error);
1501 if (int_value < 0) {
1504 value = (
unsigned int)int_value;
1511 if (p + 2 > length) {
1515 int int_value = do_unpack_int16(data + p);
1516 _int_range.validate(int_value, range_error);
1517 if (int_value < 0) {
1520 value = (
unsigned int)int_value;
1527 if (p + 4 > length) {
1531 int int_value = do_unpack_int32(data + p);
1532 _int_range.validate(int_value, range_error);
1533 if (int_value < 0) {
1536 value = (
unsigned int)int_value;
1543 if (p + 8 > length) {
1547 int64_t int_value = do_unpack_int64(data + p);
1548 _int64_range.validate(int_value, range_error);
1549 if (int_value < 0) {
1552 value = (
unsigned int)(
int)int_value;
1553 if (value != int_value) {
1562 if (p + 1 > length) {
1566 value = do_unpack_uint8(data + p);
1567 _uint_range.validate(value, range_error);
1572 if (p + 2 > length) {
1576 value = do_unpack_uint16(data + p);
1577 _uint_range.validate(value, range_error);
1582 if (p + 4 > length) {
1586 value = do_unpack_uint32(data + p);
1587 _uint_range.validate(value, range_error);
1593 if (p + 8 > length) {
1597 uint64_t uint_value = do_unpack_uint64(data + p);
1598 _uint64_range.validate(uint_value, range_error);
1599 value = (
unsigned int)uint_value;
1600 if (value != uint_value) {
1609 if (p + 8 > length) {
1613 double real_value = do_unpack_float64(data + p);
1614 _double_range.validate(real_value, range_error);
1615 value = (
unsigned int)real_value;
1625 if (_divisor != 1) {
1626 value = value / _divisor;
1637 bool &pack_error,
bool &range_error)
const {
1641 if (p + 1 > length) {
1645 int int_value = do_unpack_int8(data + p);
1646 _int_range.validate(int_value, range_error);
1647 value = (int64_t)int_value;
1654 if (p + 2 > length) {
1658 int int_value = do_unpack_int16(data + p);
1659 _int_range.validate(int_value, range_error);
1660 value = (int64_t)int_value;
1667 if (p + 4 > length) {
1671 int int_value = do_unpack_int32(data + p);
1672 _int_range.validate(int_value, range_error);
1673 value = (int64_t)int_value;
1679 if (p + 8 > length) {
1683 value = do_unpack_int64(data + p);
1684 _int64_range.validate(value, range_error);
1691 if (p + 1 > length) {
1695 unsigned int uint_value = do_unpack_uint8(data + p);
1696 _uint_range.validate(uint_value, range_error);
1697 value = (int64_t)(
int)uint_value;
1704 if (p + 2 > length) {
1708 unsigned int uint_value = do_unpack_uint16(data + p);
1709 _uint_range.validate(uint_value, range_error);
1710 value = (int64_t)(
int)uint_value;
1717 if (p + 4 > length) {
1721 unsigned int uint_value = do_unpack_uint32(data + p);
1722 _uint_range.validate(uint_value, range_error);
1723 value = (int64_t)(
int)uint_value;
1730 if (p + 8 > length) {
1734 uint64_t uint_value = do_unpack_uint64(data + p);
1735 _uint64_range.validate(uint_value, range_error);
1736 value = (int64_t)uint_value;
1746 if (p + 8 > length) {
1750 double real_value = do_unpack_float64(data + p);
1751 _double_range.validate(real_value, range_error);
1752 value = (int64_t)real_value;
1762 if (_divisor != 1) {
1763 value = value / _divisor;
1774 bool &pack_error,
bool &range_error)
const {
1778 if (p + 1 > length) {
1782 int int_value = do_unpack_int8(data + p);
1783 _int_range.validate(int_value, range_error);
1784 if (int_value < 0) {
1787 value = (uint64_t)(
unsigned int)int_value;
1794 if (p + 2 > length) {
1798 int int_value = do_unpack_int16(data + p);
1799 _int_range.validate(int_value, range_error);
1800 if (int_value < 0) {
1803 value = (uint64_t)(
unsigned int)int_value;
1810 if (p + 4 > length) {
1814 int int_value = do_unpack_int32(data + p);
1815 _int_range.validate(int_value, range_error);
1816 if (int_value < 0) {
1819 value = (uint64_t)(
unsigned int)int_value;
1826 if (p + 8 > length) {
1830 int64_t int_value = do_unpack_int64(data + p);
1831 _int64_range.validate(int_value, range_error);
1832 if (int_value < 0) {
1835 value = (uint64_t)int_value;
1843 if (p + 1 > length) {
1847 unsigned int uint_value = do_unpack_uint8(data + p);
1848 _uint_range.validate(uint_value, range_error);
1849 value = (uint64_t)uint_value;
1856 if (p + 2 > length) {
1860 unsigned int uint_value = do_unpack_uint16(data + p);
1861 _uint_range.validate(uint_value, range_error);
1862 value = (uint64_t)uint_value;
1869 if (p + 4 > length) {
1873 unsigned int uint_value = do_unpack_uint32(data + p);
1874 _uint_range.validate(uint_value, range_error);
1875 value = (uint64_t)uint_value;
1881 if (p + 8 > length) {
1885 value = do_unpack_uint64(data + p);
1886 _uint64_range.validate(value, range_error);
1892 if (p + 8 > length) {
1896 double real_value = do_unpack_float64(data + p);
1897 _double_range.validate(real_value, range_error);
1898 value = (uint64_t)real_value;
1908 if (_divisor != 1) {
1909 value = value / _divisor;
1920 bool &pack_error,
bool &range_error)
const {
1927 if (p + 1 > length) {
1931 unsigned int int_value = do_unpack_uint8(data + p);
1932 _uint_range.validate(int_value, range_error);
1933 value.assign(1, int_value);
1942 size_t string_length;
1944 if (_num_length_bytes == 0) {
1945 string_length = _fixed_byte_size;
1951 if (p + 2 > length) {
1955 string_length = do_unpack_uint16(data + p);
1960 if (p + 4 > length) {
1964 string_length = do_unpack_uint32(data + p);
1974 _uint_range.validate(string_length, range_error);
1976 if (p + string_length > length) {
1980 value.assign(data + p, string_length);
1990 unpack_blob(
const char *data,
size_t length,
size_t &p, vector_uchar &value,
1991 bool &pack_error,
bool &range_error)
const {
1998 if (p + 1 > length) {
2002 unsigned int int_value = do_unpack_uint8(data + p);
2003 _uint_range.validate(int_value, range_error);
2005 value[0] = int_value;
2016 if (_num_length_bytes == 0) {
2017 blob_size = _fixed_byte_size;
2023 if (p + 2 > length) {
2027 blob_size = do_unpack_uint16(data + p);
2032 if (p + 4 > length) {
2036 blob_size = do_unpack_uint32(data + p);
2046 _uint_range.validate(blob_size, range_error);
2048 if (p + blob_size > length) {
2052 value = vector_uchar((
const unsigned char *)data + p,
2053 (
const unsigned char *)data + p + blob_size);
2067 bool &pack_error,
bool &range_error)
const {
2068 if (!_has_range_limits) {
2069 return unpack_skip(data, length, p, pack_error);
2074 if (p + 1 > length) {
2078 int int_value = do_unpack_int8(data + p);
2079 _int_range.validate(int_value, range_error);
2086 if (p + 2 > length) {
2090 int int_value = do_unpack_int16(data + p);
2091 _int_range.validate(int_value, range_error);
2098 if (p + 4 > length) {
2102 int int_value = do_unpack_int32(data + p);
2103 _int_range.validate(int_value, range_error);
2110 if (p + 8 > length) {
2114 int64_t int_value = do_unpack_int64(data + p);
2115 _int64_range.validate(int_value, range_error);
2123 if (p + 1 > length) {
2127 unsigned int uint_value = do_unpack_uint8(data + p);
2128 _uint_range.validate(uint_value, range_error);
2135 if (p + 2 > length) {
2139 unsigned int uint_value = do_unpack_uint16(data + p);
2140 _uint_range.validate(uint_value, range_error);
2147 if (p + 4 > length) {
2151 unsigned int uint_value = do_unpack_uint32(data + p);
2152 _uint_range.validate(uint_value, range_error);
2159 if (p + 8 > length) {
2163 uint64_t uint_value = do_unpack_uint64(data + p);
2164 _uint64_range.validate(uint_value, range_error);
2171 if (p + 8 > length) {
2175 double real_value = do_unpack_float64(data + p);
2176 _double_range.validate(real_value, range_error);
2183 if (_num_length_bytes == 0) {
2184 p += _fixed_byte_size;
2187 if (p + 2 > length) {
2191 size_t string_length = do_unpack_uint16(data + p);
2192 _uint_range.validate(string_length, range_error);
2193 p += 2 + string_length;
2198 if (_num_length_bytes == 0) {
2199 p += _fixed_byte_size;
2202 if (p + 4 > length) {
2206 size_t string_length = do_unpack_uint32(data + p);
2207 _uint_range.validate(string_length, range_error);
2208 p += 4 + string_length;
2226 bool &pack_error)
const {
2227 size_t string_length;
2254 if (_num_length_bytes == 0) {
2255 p += _fixed_byte_size;
2258 if (p + 2 > length) {
2261 string_length = do_unpack_uint16(data + p);
2262 p += 2 + string_length;
2267 if (_num_length_bytes == 0) {
2268 p += _fixed_byte_size;
2271 if (p + 4 > length) {
2274 string_length = do_unpack_uint32(data + p);
2275 p += 4 + string_length;
2296 const string &name,
const string &postname)
const {
2297 if (get_typedef() !=
nullptr) {
2298 output_typedef_name(out, brief, prename, name, postname);
2303 out <<
"%" << _orig_modulus;
2305 if (_divisor != 1) {
2306 out <<
"/" << _divisor;
2313 if (!_int_range.is_empty()) {
2315 _int_range.output(out, _divisor);
2321 if (!_int64_range.is_empty()) {
2323 _int64_range.output(out, _divisor);
2331 if (!_uint_range.is_empty()) {
2333 _uint_range.output(out, _divisor);
2339 if (!_uint_range.is_empty()) {
2341 _uint_range.output_char(out, _divisor);
2347 if (!_uint64_range.is_empty()) {
2349 _uint64_range.output(out, _divisor);
2355 if (!_double_range.is_empty()) {
2357 _double_range.output(out, _divisor);
2365 if (!_uint_range.is_empty()) {
2367 _uint_range.output(out, _divisor);
2375 if (!prename.empty() || !name.empty() || !postname.empty()) {
2376 out <<
" " << prename << name << postname;
2391 hashgen.
add_int((
int)_double_modulus);
2394 _int_range.generate_hash(hashgen);
2395 _int64_range.generate_hash(hashgen);
2396 _uint_range.generate_hash(hashgen);
2397 _uint64_range.generate_hash(hashgen);
2398 _double_range.generate_hash(hashgen);
2406 bool DCSimpleParameter::
2415 bool DCSimpleParameter::
2417 if (_divisor != other->_divisor) {
2421 if (_type == other->_type) {
2429 switch (other->_type) {
2441 switch (other->_type) {
2460 bool DCSimpleParameter::
2466 if (_nested_field ==
nullptr) {
2480 DivisorMap &divisor_map = _nested_field_map[type];
2481 DivisorMap::iterator di;
2482 di = divisor_map.find(divisor);
2483 if (di != divisor_map.end()) {
2484 return (*di).second;
2488 divisor_map[divisor] = nested_field;
2489 return nested_field;
2497 create_uint32uint8_type() {
2498 if (_uint32uint8_type ==
nullptr) {
2504 return _uint32uint8_type;
virtual void unpack_uint64(const char *data, size_t length, size_t &p, uint64_t &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
char * get_write_pointer(size_t size)
Adds the indicated number of bytes to the end of the data without initializing them,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of this type into the hash.
This is a block of data that receives the results of DCPacker.
DCSubatomicType
This defines the numeric type of each element of a DCAtomicField; that is, the particular values that...
void append_data(const char *buffer, size_t size)
Adds the indicated bytes to the end of the data.
bool set_divisor(unsigned int divisor)
Assigns the indicated divisor to the simple type.
int get_array_size() const
Returns the fixed number of elements in this array, or -1 if the array may contain a variable number ...
double get_modulus() const
Returns the modulus associated with this type, if any.
void add_int(int num)
Adds another integer to the hash so far.
This represents a class (or struct) object used as a parameter itself.
This is the most fundamental kind of parameter type: a single number or string, one of the DCSubatomi...
virtual bool unpack_validate(const char *data, size_t length, size_t &p, bool &pack_error, bool &range_error) const
Internally unpacks the current numeric or string value and validates it against the type range limits...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual DCPackerInterface * get_nested_field(int n) const
Returns the DCPackerInterface object that represents the nth nested field.
virtual bool pack_default_value(DCPackData &pack_data, bool &pack_error) const
Packs the field's specified default value (or a sensible default if no value is specified) into the s...
virtual void unpack_double(const char *data, size_t length, size_t &p, double &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void pack_blob(DCPackData &pack_data, const vector_uchar &value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
Defines a particular DistributedClass as read from an input .dc file.
virtual bool do_check_match_simple_parameter(const DCSimpleParameter *other) const
Returns true if this field matches the indicated simple parameter, false otherwise.
DCSubatomicType get_type() const
Returns the particular subatomic type represented by this instance.
size_t get_length() const
Returns the current length of the buffer.
virtual void pack_uint(DCPackData &pack_data, unsigned int value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void unpack_blob(const char *data, size_t length, size_t &p, vector_uchar &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
int get_num_ranges() const
Returns the number of minmax components in the range description.
Represents the type specification for a single parameter within a field specification.
virtual void pack_uint64(DCPackData &pack_data, uint64_t value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
void pack_default_value()
Adds the default value for the current element into the stream.
This represents an array of some other kind of object, meaning this parameter type accepts an arbitra...
bool set_range(const DCDoubleRange &range)
Sets the parameter with the indicated range.
Number get_max(int n) const
Returns the maximum value defined by the nth component.
bool has_modulus() const
Returns true if there is a modulus associated, false otherwise.,.
void push()
Marks the beginning of a nested series of fields.
Number get_min(int n) const
Returns the minimum value defined by the nth component.
const char * get_data() const
Returns the beginning of the data buffer.
virtual void pack_string(DCPackData &pack_data, const std::string &value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
This class generates an arbitrary hash number from a sequence of ints.
virtual bool unpack_skip(const char *data, size_t length, size_t &p, bool &pack_error) const
Increments p to the end of the current field without actually unpacking any data or performing any ra...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void output_instance(std::ostream &out, bool brief, const std::string &prename, const std::string &name, const std::string &postname) const
Formats the parameter in the C++-like dc syntax as a typename and identifier.
virtual void unpack_int64(const char *data, size_t length, size_t &p, int64_t &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
void begin_pack(const DCPackerInterface *root)
Begins a packing session.
virtual void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of this type into the hash.
virtual bool is_valid() const
Returns false if the type is an invalid type (e.g.
bool is_numeric_type() const
Returns true if the type is a numeric type (and therefore can accept a divisor and/or a modulus),...
This class can be used for packing a series of numeric and string data into a binary stream,...
virtual void pack_int64(DCPackData &pack_data, int64_t value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
DCParameter * get_element_type() const
Returns the type of the individual elements of this array.
bool add_field(DCField *field)
Adds the newly-allocated field to the class.
int get_divisor() const
Returns the divisor associated with this type.
virtual void unpack_string(const char *data, size_t length, size_t &p, std::string &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
bool end_pack()
Finishes a packing session.
virtual void pack_int(DCPackData &pack_data, int value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
void pop()
Marks the end of a nested series of fields.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void pack_double(DCPackData &pack_data, double value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
virtual void unpack_int(const char *data, size_t length, size_t &p, int &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
virtual bool pack_default_value(DCPackData &pack_data, bool &pack_error) const
Packs the simpleParameter's specified default value (or a sensible default if no value is specified) ...
This defines the internal interface for packing values into a DCField.
bool set_modulus(double modulus)
Assigns the indicated modulus to the simple type.
virtual void unpack_uint(const char *data, size_t length, size_t &p, unsigned int &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
virtual int calc_num_nested_fields(size_t length_bytes) const
This flavor of get_num_nested_fields is used during unpacking.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.