ValveKeyValue icon indicating copy to clipboard operation
ValveKeyValue copied to clipboard

Collapsed ints in binary kv1 implemented in CS:GO

Open xPaw opened this issue 4 years ago • 1 comments

	// Data type
	enum types_t
	{
		TYPE_NONE = 0,
		TYPE_STRING,
		TYPE_INT,
		TYPE_FLOAT,
		TYPE_PTR,
		TYPE_WSTRING,
		TYPE_COLOR,
		TYPE_UINT64,
		TYPE_COMPILED_INT_BYTE,			// hack to collapse 1 byte ints in the compiled format
		TYPE_COMPILED_INT_0,			// hack to collapse 0 in the compiled format
		TYPE_COMPILED_INT_1,			// hack to collapse 1 in the compiled format
		TYPE_NUMTYPES, 
	};

Looks like they ported this back from Source 2. This is not great beacuse the enum has conflicting values.

xPaw avatar Jan 19 '21 09:01 xPaw

		case TYPE_COMPILED_INT_0:
			{
				// only for dense storage purposes, flip back to preferred internal format
				dat->m_iDataType = TYPE_INT;
				dat->m_iValue = 0;
				break;
			}

 		case TYPE_COMPILED_INT_1:
			{
				// only for dense storage purposes, flip back to preferred internal format
				dat->m_iDataType = TYPE_INT;
				dat->m_iValue = 1;
				break;
			}

 		case TYPE_COMPILED_INT_BYTE:
			{
				// only for dense storage purposes, flip back to preferred internal format
				dat->m_iDataType = TYPE_INT;
				dat->m_iValue = buffer.GetChar();
				break;
			}

its just an int but using less space on disk (2 bytes) for a single byte value or (1 byte) boolean value. plus the key name of course.

yaakov-h avatar Jan 19 '21 11:01 yaakov-h