* Handle all conversion and typechecking of variables here. * In the case of saving, read in the actual value from the struct * and then write them to file, endian safely. Loading a value * goes exactly the opposite way * @param ptr The object being filled/read * @param conv VarType type of the current element of the struct */
| 860 | * @param conv VarType type of the current element of the struct |
| 861 | */ |
| 862 | static void SlSaveLoadConv(void *ptr, VarType conv) |
| 863 | { |
| 864 | switch (_sl.action) { |
| 865 | case SLA_SAVE: { |
| 866 | int64_t x = ReadValue(ptr, conv); |
| 867 | |
| 868 | /* Write the value to the file and check if its value is in the desired range */ |
| 869 | switch (GetVarFileType(conv)) { |
| 870 | case SLE_FILE_I8: assert(x >= -128 && x <= 127); SlWriteByte(x);break; |
| 871 | case SLE_FILE_U8: assert(x >= 0 && x <= 255); SlWriteByte(x);break; |
| 872 | case SLE_FILE_I16:assert(x >= -32768 && x <= 32767); SlWriteUint16(x);break; |
| 873 | case SLE_FILE_STRINGID: |
| 874 | case SLE_FILE_U16:assert(x >= 0 && x <= 65535); SlWriteUint16(x);break; |
| 875 | case SLE_FILE_I32: |
| 876 | case SLE_FILE_U32: SlWriteUint32((uint32_t)x);break; |
| 877 | case SLE_FILE_I64: |
| 878 | case SLE_FILE_U64: SlWriteUint64(x);break; |
| 879 | default: NOT_REACHED(); |
| 880 | } |
| 881 | break; |
| 882 | } |
| 883 | case SLA_LOAD_CHECK: |
| 884 | case SLA_LOAD: { |
| 885 | int64_t x; |
| 886 | /* Read a value from the file */ |
| 887 | switch (GetVarFileType(conv)) { |
| 888 | case SLE_FILE_I8: x = (int8_t )SlReadByte(); break; |
| 889 | case SLE_FILE_U8: x = (uint8_t )SlReadByte(); break; |
| 890 | case SLE_FILE_I16: x = (int16_t )SlReadUint16(); break; |
| 891 | case SLE_FILE_U16: x = (uint16_t)SlReadUint16(); break; |
| 892 | case SLE_FILE_I32: x = (int32_t )SlReadUint32(); break; |
| 893 | case SLE_FILE_U32: x = (uint32_t)SlReadUint32(); break; |
| 894 | case SLE_FILE_I64: x = (int64_t )SlReadUint64(); break; |
| 895 | case SLE_FILE_U64: x = (uint64_t)SlReadUint64(); break; |
| 896 | case SLE_FILE_STRINGID: x = RemapOldStringID((uint16_t)SlReadUint16()); break; |
| 897 | default: NOT_REACHED(); |
| 898 | } |
| 899 | |
| 900 | /* Write The value to the struct. These ARE endian safe. */ |
| 901 | WriteValue(ptr, conv, x); |
| 902 | break; |
| 903 | } |
| 904 | case SLA_PTRS: break; |
| 905 | case SLA_NULL: break; |
| 906 | default: NOT_REACHED(); |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | /** |
| 911 | * Calculate the gross length of the string that it |
no test coverage detected