serialize(obj, context) {
		const keys = /** @type {(keyof T)[]} */ (Object.keys(obj));
		if (keys.length > 128) {
			// Objects with so many keys are unlikely to share structure
			// with other objects
			context.write(keys);
			for (const key of keys) {
				context.write(obj[key]);
			}
		} else if (keys.length > 1) {
			context.write(getCachedKeys(keys, context.write));
			for (const key of keys) {
				context.write(obj[key]);
			}
		} else if (keys.length === 1) {
			const key = keys[0];
			context.write(key);
			context.write(obj[key]);
		} else {
			context.write(null);
		}
	}
@template {object} T
@param {T} obj plain object
@param {ObjectSerializerContext} context context