Merge remote-tracking branch 'upstream/stabilization/2106' into nvsickle/MergeStabilizationJun18
This commit is contained in:
@@ -36,6 +36,12 @@ namespace AZ
|
||||
Color* color = reinterpret_cast<Color*>(outputValue);
|
||||
AZ_Assert(color, "Output value for JsonColorSerializer can't be null.");
|
||||
|
||||
if (IsExplicitDefault(inputValue))
|
||||
{
|
||||
*color = Color::CreateZero();
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::DefaultsUsed, "Color value set to default of zero.");
|
||||
}
|
||||
|
||||
switch (inputValue.GetType())
|
||||
{
|
||||
case rapidjson::kArrayType:
|
||||
@@ -43,10 +49,14 @@ namespace AZ
|
||||
case rapidjson::kObjectType:
|
||||
return LoadObject(*color, inputValue, context);
|
||||
|
||||
case rapidjson::kStringType: // fall through
|
||||
case rapidjson::kNumberType: // fall through
|
||||
case rapidjson::kNullType: // fall through
|
||||
case rapidjson::kFalseType: // fall through
|
||||
case rapidjson::kStringType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kNumberType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kNullType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kFalseType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kTrueType:
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Unsupported,
|
||||
"Unsupported type. Colors can only be read from arrays or objects.");
|
||||
@@ -91,6 +101,11 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
auto JsonColorSerializer::GetOperationsFlags() const -> OperationFlags
|
||||
{
|
||||
return OperationFlags::InitializeNewInstance;
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonColorSerializer::LoadObject(Color& output, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context)
|
||||
{
|
||||
|
||||
@@ -28,6 +28,8 @@ namespace AZ
|
||||
JsonSerializationResult::Result Store(rapidjson::Value& outputValue, const void* inputValue, const void* defaultValue,
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
|
||||
OperationFlags GetOperationsFlags() const override;
|
||||
|
||||
private:
|
||||
enum class LoadAlpha
|
||||
{
|
||||
|
||||
@@ -263,7 +263,7 @@ namespace AZ::JsonMathMatrixSerializerInternal
|
||||
|
||||
template<typename MatrixType, size_t RowCount, size_t ColumnCount>
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId,
|
||||
const rapidjson::Value& inputValue, JsonDeserializerContext& context)
|
||||
const rapidjson::Value& inputValue, JsonDeserializerContext& context, bool isExplicitDefault)
|
||||
{
|
||||
namespace JSR = JsonSerializationResult; // Used remove name conflicts in AzCore in uber builds.
|
||||
|
||||
@@ -279,6 +279,12 @@ namespace AZ::JsonMathMatrixSerializerInternal
|
||||
MatrixType* matrix = reinterpret_cast<MatrixType*>(outputValue);
|
||||
AZ_Assert(matrix, "Output value for JsonMatrix%zux%zuSerializer can't be null.", RowCount, ColumnCount);
|
||||
|
||||
if (isExplicitDefault)
|
||||
{
|
||||
*matrix = MatrixType::CreateIdentity();
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::DefaultsUsed, "Matrix value set to identity matrix.");
|
||||
}
|
||||
|
||||
switch (inputValue.GetType())
|
||||
{
|
||||
case rapidjson::kArrayType:
|
||||
@@ -381,6 +387,16 @@ namespace AZ::JsonMathMatrixSerializerInternal
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
// BaseJsonMatrixSerializer
|
||||
|
||||
AZ_CLASS_ALLOCATOR_IMPL(BaseJsonMatrixSerializer, SystemAllocator, 0);
|
||||
|
||||
auto BaseJsonMatrixSerializer::GetOperationsFlags() const -> OperationFlags
|
||||
{
|
||||
return OperationFlags::InitializeNewInstance;
|
||||
}
|
||||
|
||||
|
||||
// Matrix3x3
|
||||
|
||||
AZ_CLASS_ALLOCATOR_IMPL(JsonMatrix3x3Serializer, SystemAllocator, 0);
|
||||
@@ -389,10 +405,7 @@ namespace AZ
|
||||
const rapidjson::Value& inputValue, JsonDeserializerContext& context)
|
||||
{
|
||||
return JsonMathMatrixSerializerInternal::Load<Matrix3x3, 3, 3>(
|
||||
outputValue,
|
||||
outputValueTypeId,
|
||||
inputValue,
|
||||
context);
|
||||
outputValue, outputValueTypeId, inputValue, context, IsExplicitDefault(inputValue));
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonMatrix3x3Serializer::Store(rapidjson::Value& outputValue, const void* inputValue,
|
||||
@@ -401,11 +414,7 @@ namespace AZ
|
||||
outputValue.SetObject();
|
||||
|
||||
return JsonMathMatrixSerializerInternal::StoreRotationAndScale<Matrix3x3>(
|
||||
outputValue,
|
||||
inputValue,
|
||||
defaultValue,
|
||||
valueTypeId,
|
||||
context);
|
||||
outputValue, inputValue, defaultValue, valueTypeId, context);
|
||||
}
|
||||
|
||||
|
||||
@@ -417,10 +426,7 @@ namespace AZ
|
||||
const rapidjson::Value& inputValue, JsonDeserializerContext& context)
|
||||
{
|
||||
return JsonMathMatrixSerializerInternal::Load<Matrix3x4, 3, 4>(
|
||||
outputValue,
|
||||
outputValueTypeId,
|
||||
inputValue,
|
||||
context);
|
||||
outputValue, outputValueTypeId, inputValue, context, IsExplicitDefault(inputValue));
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonMatrix3x4Serializer::Store(rapidjson::Value& outputValue, const void* inputValue,
|
||||
@@ -428,19 +434,11 @@ namespace AZ
|
||||
{
|
||||
outputValue.SetObject();
|
||||
|
||||
auto result = JsonMathMatrixSerializerInternal::StoreRotationAndScale<Matrix3x4>(
|
||||
outputValue,
|
||||
inputValue,
|
||||
defaultValue,
|
||||
valueTypeId,
|
||||
context);
|
||||
auto result =
|
||||
JsonMathMatrixSerializerInternal::StoreRotationAndScale<Matrix3x4>(outputValue, inputValue, defaultValue, valueTypeId, context);
|
||||
|
||||
auto resultTranslation = JsonMathMatrixSerializerInternal::StoreTranslation<Matrix3x4>(
|
||||
outputValue,
|
||||
inputValue,
|
||||
defaultValue,
|
||||
valueTypeId,
|
||||
context);
|
||||
auto resultTranslation =
|
||||
JsonMathMatrixSerializerInternal::StoreTranslation<Matrix3x4>(outputValue, inputValue, defaultValue, valueTypeId, context);
|
||||
|
||||
result.GetResultCode().Combine(resultTranslation);
|
||||
return result;
|
||||
@@ -454,10 +452,7 @@ namespace AZ
|
||||
const rapidjson::Value& inputValue, JsonDeserializerContext& context)
|
||||
{
|
||||
return JsonMathMatrixSerializerInternal::Load<Matrix4x4, 4, 4>(
|
||||
outputValue,
|
||||
outputValueTypeId,
|
||||
inputValue,
|
||||
context);
|
||||
outputValue, outputValueTypeId, inputValue, context, IsExplicitDefault(inputValue));
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonMatrix4x4Serializer::Store(rapidjson::Value& outputValue, const void* inputValue,
|
||||
@@ -465,19 +460,11 @@ namespace AZ
|
||||
{
|
||||
outputValue.SetObject();
|
||||
|
||||
auto result = JsonMathMatrixSerializerInternal::StoreRotationAndScale<Matrix4x4>(
|
||||
outputValue,
|
||||
inputValue,
|
||||
defaultValue,
|
||||
valueTypeId,
|
||||
context);
|
||||
auto result =
|
||||
JsonMathMatrixSerializerInternal::StoreRotationAndScale<Matrix4x4>(outputValue, inputValue, defaultValue, valueTypeId, context);
|
||||
|
||||
auto resultTranslation = JsonMathMatrixSerializerInternal::StoreTranslation<Matrix4x4>(
|
||||
outputValue,
|
||||
inputValue,
|
||||
defaultValue,
|
||||
valueTypeId,
|
||||
context);
|
||||
auto resultTranslation =
|
||||
JsonMathMatrixSerializerInternal::StoreTranslation<Matrix4x4>(outputValue, inputValue, defaultValue, valueTypeId, context);
|
||||
|
||||
result.GetResultCode().Combine(resultTranslation);
|
||||
return result;
|
||||
|
||||
@@ -16,11 +16,18 @@
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class JsonMatrix3x3Serializer
|
||||
: public BaseJsonSerializer
|
||||
class BaseJsonMatrixSerializer : public BaseJsonSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonMatrix3x3Serializer, "{8C76CD6A-8576-4604-A746-CF7A7F20F366}", BaseJsonSerializer);
|
||||
AZ_RTTI(BaseJsonMatrixSerializer, "{18CA4637-C9B7-454B-9126-107E18A8C096}", BaseJsonSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
OperationFlags GetOperationsFlags() const override;
|
||||
};
|
||||
|
||||
class JsonMatrix3x3Serializer : public BaseJsonMatrixSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonMatrix3x3Serializer, "{8C76CD6A-8576-4604-A746-CF7A7F20F366}", BaseJsonMatrixSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
@@ -28,11 +35,10 @@ namespace AZ
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
};
|
||||
|
||||
class JsonMatrix3x4Serializer
|
||||
: public BaseJsonSerializer
|
||||
class JsonMatrix3x4Serializer : public BaseJsonMatrixSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonMatrix3x4Serializer, "{E801333B-4AF1-4F43-976C-579670B02DC5}", BaseJsonSerializer);
|
||||
AZ_RTTI(JsonMatrix3x4Serializer, "{E801333B-4AF1-4F43-976C-579670B02DC5}", BaseJsonMatrixSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
@@ -40,11 +46,10 @@ namespace AZ
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
};
|
||||
|
||||
class JsonMatrix4x4Serializer
|
||||
: public BaseJsonSerializer
|
||||
class JsonMatrix4x4Serializer : public BaseJsonMatrixSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonMatrix4x4Serializer, "{46E888FC-248A-4910-9221-4E101A10AEA1}", BaseJsonSerializer);
|
||||
AZ_RTTI(JsonMatrix4x4Serializer, "{46E888FC-248A-4910-9221-4E101A10AEA1}", BaseJsonMatrixSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace AZ
|
||||
|
||||
template<typename VectorType, size_t ElementCount>
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context)
|
||||
JsonDeserializerContext& context, bool isExplicitDefault)
|
||||
{
|
||||
namespace JSR = JsonSerializationResult; // Used remove name conflicts in AzCore in uber builds.
|
||||
|
||||
@@ -138,6 +138,12 @@ namespace AZ
|
||||
VectorType* vector = reinterpret_cast<VectorType*>(outputValue);
|
||||
AZ_Assert(vector, "Output value for JsonVector%iSerializer can't be null.", ElementCount);
|
||||
|
||||
if (isExplicitDefault)
|
||||
{
|
||||
*vector = VectorType::CreateZero();
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::DefaultsUsed, "Math vector value set to default of zero.");
|
||||
}
|
||||
|
||||
switch (inputValue.GetType())
|
||||
{
|
||||
case rapidjson::kArrayType:
|
||||
@@ -145,10 +151,14 @@ namespace AZ
|
||||
case rapidjson::kObjectType:
|
||||
return LoadObject<VectorType, ElementCount>(*vector, inputValue, context);
|
||||
|
||||
case rapidjson::kStringType: // fall through
|
||||
case rapidjson::kNumberType: // fall through
|
||||
case rapidjson::kNullType: // fall through
|
||||
case rapidjson::kFalseType: // fall through
|
||||
case rapidjson::kStringType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kNumberType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kNullType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kFalseType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kTrueType:
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Unsupported,
|
||||
"Unsupported type. Math vectors can only be read from arrays or objects.");
|
||||
@@ -189,6 +199,16 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// BaseJsonVectorSerializer
|
||||
|
||||
AZ_CLASS_ALLOCATOR_IMPL(BaseJsonVectorSerializer, SystemAllocator, 0);
|
||||
|
||||
auto BaseJsonVectorSerializer::GetOperationsFlags() const -> OperationFlags
|
||||
{
|
||||
return OperationFlags::InitializeNewInstance;
|
||||
}
|
||||
|
||||
|
||||
// Vector2
|
||||
|
||||
@@ -197,7 +217,8 @@ namespace AZ
|
||||
JsonSerializationResult::Result JsonVector2Serializer::Load(void* outputValue, const Uuid& outputValueTypeId,
|
||||
const rapidjson::Value& inputValue, JsonDeserializerContext& context)
|
||||
{
|
||||
return JsonMathVectorSerializerInternal::Load<Vector2, 2>(outputValue, outputValueTypeId, inputValue, context);
|
||||
return JsonMathVectorSerializerInternal::Load<Vector2, 2>(
|
||||
outputValue, outputValueTypeId, inputValue, context, IsExplicitDefault(inputValue));
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonVector2Serializer::Store(rapidjson::Value& outputValue, const void* inputValue,
|
||||
@@ -214,7 +235,8 @@ namespace AZ
|
||||
JsonSerializationResult::Result JsonVector3Serializer::Load(void* outputValue, const Uuid& outputValueTypeId,
|
||||
const rapidjson::Value& inputValue, JsonDeserializerContext& context)
|
||||
{
|
||||
return JsonMathVectorSerializerInternal::Load<Vector3, 3>(outputValue, outputValueTypeId, inputValue, context);
|
||||
return JsonMathVectorSerializerInternal::Load<Vector3, 3>(
|
||||
outputValue, outputValueTypeId, inputValue, context, IsExplicitDefault(inputValue));
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonVector3Serializer::Store(rapidjson::Value& outputValue, const void* inputValue,
|
||||
@@ -231,7 +253,8 @@ namespace AZ
|
||||
JsonSerializationResult::Result JsonVector4Serializer::Load(void* outputValue, const Uuid& outputValueTypeId,
|
||||
const rapidjson::Value& inputValue, JsonDeserializerContext& context)
|
||||
{
|
||||
return JsonMathVectorSerializerInternal::Load<Vector4, 4>(outputValue, outputValueTypeId, inputValue, context);
|
||||
return JsonMathVectorSerializerInternal::Load<Vector4, 4>(
|
||||
outputValue, outputValueTypeId, inputValue, context, IsExplicitDefault(inputValue));
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonVector4Serializer::Store(rapidjson::Value& outputValue, const void* inputValue,
|
||||
@@ -252,7 +275,7 @@ namespace AZ
|
||||
// check for "yaw, pitch, roll" object
|
||||
if (inputValue.IsObject())
|
||||
{
|
||||
if (inputValue.GetObject().ObjectEmpty())
|
||||
if (IsExplicitDefault(inputValue))
|
||||
{
|
||||
Quaternion* outQuaternion = reinterpret_cast<Quaternion*>(outputValue);
|
||||
*outQuaternion = Quaternion::CreateIdentity();
|
||||
@@ -283,7 +306,7 @@ namespace AZ
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Success, "Successfully read quaternion.");
|
||||
}
|
||||
|
||||
return JsonMathVectorSerializerInternal::Load<Quaternion, 4>(outputValue, outputValueTypeId, inputValue, context);
|
||||
return JsonMathVectorSerializerInternal::Load<Quaternion, 4>(outputValue, outputValueTypeId, inputValue, context, false);
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonQuaternionSerializer::Store(rapidjson::Value& outputValue, const void* inputValue,
|
||||
|
||||
@@ -16,11 +16,18 @@
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class JsonVector2Serializer
|
||||
: public BaseJsonSerializer
|
||||
class BaseJsonVectorSerializer : public BaseJsonSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonVector2Serializer, "{E1EAA209-9682-4120-B26B-3EDD9AD56D6F}", BaseJsonSerializer);
|
||||
AZ_RTTI(BaseJsonVectorSerializer, "{C188D355-E6DF-4590-8B31-F40591F48A8E}", BaseJsonSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
OperationFlags GetOperationsFlags() const override;
|
||||
};
|
||||
|
||||
class JsonVector2Serializer : public BaseJsonVectorSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonVector2Serializer, "{E1EAA209-9682-4120-B26B-3EDD9AD56D6F}", BaseJsonVectorSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
@@ -28,11 +35,10 @@ namespace AZ
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
};
|
||||
|
||||
class JsonVector3Serializer
|
||||
: public BaseJsonSerializer
|
||||
class JsonVector3Serializer : public BaseJsonVectorSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonVector3Serializer, "{BF82BBF3-3CD9-48DA-97CC-E4DF2EF01552}", BaseJsonSerializer);
|
||||
AZ_RTTI(JsonVector3Serializer, "{BF82BBF3-3CD9-48DA-97CC-E4DF2EF01552}", BaseJsonVectorSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
@@ -40,11 +46,10 @@ namespace AZ
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
};
|
||||
|
||||
class JsonVector4Serializer
|
||||
: public BaseJsonSerializer
|
||||
class JsonVector4Serializer : public BaseJsonVectorSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonVector4Serializer, "{05B45EA7-7102-4281-8AA0-2AC72D74AAFD}", BaseJsonSerializer);
|
||||
AZ_RTTI(JsonVector4Serializer, "{05B45EA7-7102-4281-8AA0-2AC72D74AAFD}", BaseJsonVectorSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
@@ -52,11 +57,10 @@ namespace AZ
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
};
|
||||
|
||||
class JsonQuaternionSerializer
|
||||
: public BaseJsonSerializer
|
||||
class JsonQuaternionSerializer : public BaseJsonVectorSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonQuaternionSerializer, "{18604375-3606-49AC-B366-0F6DF9149FF3}", BaseJsonSerializer);
|
||||
AZ_RTTI(JsonQuaternionSerializer, "{18604375-3606-49AC-B366-0F6DF9149FF3}", BaseJsonVectorSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
|
||||
@@ -33,6 +33,12 @@ namespace AZ
|
||||
AZ::Transform* transformInstance = reinterpret_cast<AZ::Transform*>(outputValue);
|
||||
AZ_Assert(transformInstance, "Output value for JsonTransformSerializer can't be null.");
|
||||
|
||||
if (IsExplicitDefault(inputValue))
|
||||
{
|
||||
*transformInstance = AZ::Transform::CreateIdentity();
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::DefaultsUsed, "Transform value set to identity.");
|
||||
}
|
||||
|
||||
JSR::ResultCode result(JSR::Tasks::ReadField);
|
||||
|
||||
{
|
||||
@@ -72,7 +78,7 @@ namespace AZ
|
||||
|
||||
return context.Report(
|
||||
result,
|
||||
result.GetProcessing() != JSR::Processing::Halted ? "Succesfully loaded Transform information."
|
||||
result.GetProcessing() != JSR::Processing::Halted ? "Successfully loaded Transform information."
|
||||
: "Failed to load Transform information.");
|
||||
}
|
||||
|
||||
@@ -140,4 +146,9 @@ namespace AZ
|
||||
: "Failed to store Transform information.");
|
||||
}
|
||||
|
||||
auto JsonTransformSerializer::GetOperationsFlags() const -> OperationFlags
|
||||
{
|
||||
return OperationFlags::InitializeNewInstance;
|
||||
}
|
||||
|
||||
} // namespace AZ
|
||||
|
||||
@@ -30,6 +30,8 @@ namespace AZ
|
||||
rapidjson::Value& outputValue, const void* inputValue, const void* defaultValue, const Uuid& valueTypeId,
|
||||
JsonSerializerContext& context) override;
|
||||
|
||||
OperationFlags GetOperationsFlags() const override;
|
||||
|
||||
private:
|
||||
// Note: These need to be defined as "const char[]" instead of "const char*" so that they can be implicitly converted
|
||||
// to a rapidjson::GenericStringRef<>. (This also lets rapidjson get the string length at compile time)
|
||||
|
||||
@@ -33,6 +33,11 @@ namespace AZ
|
||||
AZStd::regex_constants::icase | AZStd::regex_constants::optimize);
|
||||
}
|
||||
|
||||
auto JsonUuidSerializer::GetOperationsFlags() const -> OperationFlags
|
||||
{
|
||||
return OperationFlags::InitializeNewInstance;
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonUuidSerializer::Load(void* outputValue, const Uuid& outputValueTypeId,
|
||||
const rapidjson::Value& inputValue, JsonDeserializerContext& context)
|
||||
{
|
||||
@@ -53,13 +58,24 @@ namespace AZ
|
||||
|
||||
Uuid* valAsUuid = reinterpret_cast<Uuid*>(outputValue);
|
||||
|
||||
if (IsExplicitDefault(inputValue))
|
||||
{
|
||||
*valAsUuid = AZ::Uuid::CreateNull();
|
||||
return MessageResult("Uuid value set to default of null.", JSR::ResultCode(JSR::Tasks::ReadField, JSR::Outcomes::DefaultsUsed));
|
||||
}
|
||||
|
||||
switch (inputValue.GetType())
|
||||
{
|
||||
case rapidjson::kArrayType: // fallthrough
|
||||
case rapidjson::kObjectType:// fallthrough
|
||||
case rapidjson::kFalseType: // fallthrough
|
||||
case rapidjson::kTrueType: // fallthrough
|
||||
case rapidjson::kNumberType:// fallthrough
|
||||
case rapidjson::kArrayType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kObjectType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kFalseType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kTrueType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kNumberType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kNullType:
|
||||
return MessageResult("Unsupported type. Uuids can only be read from strings.",
|
||||
JSR::ResultCode(JSR::Tasks::ReadField, JSR::Outcomes::Unsupported));
|
||||
|
||||
@@ -41,6 +41,8 @@ namespace AZ
|
||||
JsonSerializationResult::Result Store(rapidjson::Value& outputValue, const void* inputValue, const void* defaultValue,
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
|
||||
OperationFlags GetOperationsFlags() const override;
|
||||
|
||||
//! Does the same as load, but doesn't report through the provided callback in the settings. Instead the final
|
||||
//! ResultCode and message are returned and it's up to the caller to report if need needed.
|
||||
MessageResult UnreportedLoad(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue);
|
||||
|
||||
@@ -406,6 +406,7 @@ namespace AZ
|
||||
AZStd::vector<AZ::BehaviorParameter> eventParamsTypes{ AZStd::initializer_list<AZ::BehaviorParameter>{
|
||||
CreateBehaviorEventParameter<decay_array<T>>()... } };
|
||||
behaviorContext->Class<AZ::Event<T...>>()
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::ListOnly)
|
||||
->Attribute(AZ::Script::Attributes::EventHandlerCreationFunction, createHandlerHolder)
|
||||
->Attribute(AZ::Script::Attributes::EventParameterTypes, eventParamsTypes)
|
||||
->Method("HasHandlerConnected", &AZ::Event<T...>::HasHandlerConnected)
|
||||
@@ -413,6 +414,7 @@ namespace AZ
|
||||
|
||||
behaviorContext->Class<AZ::EventHandler<T...>>()
|
||||
->Method("Disconnect", &AZ::EventHandler<T...>::Disconnect)
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::ListOnly)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,13 +32,24 @@ namespace AZ
|
||||
switch (inputValue.GetType())
|
||||
{
|
||||
case rapidjson::kArrayType:
|
||||
return LoadContainer(outputValue, outputValueTypeId, inputValue, context);
|
||||
return LoadContainer(outputValue, outputValueTypeId, inputValue, false, context);
|
||||
|
||||
case rapidjson::kObjectType: // fall through
|
||||
case rapidjson::kNullType: // fall through
|
||||
case rapidjson::kStringType: // fall through
|
||||
case rapidjson::kFalseType: // fall through
|
||||
case rapidjson::kTrueType: // fall through
|
||||
case rapidjson::kObjectType:
|
||||
if (IsExplicitDefault(inputValue))
|
||||
{
|
||||
// Because this serializer has only the operation flag "InitializeNewInstance" set, the only time this will be called with
|
||||
// an explicit default is when a new instance has been created.
|
||||
return LoadContainer(outputValue, outputValueTypeId, inputValue, true, context);
|
||||
}
|
||||
[[fallthrough]];
|
||||
case rapidjson::kNullType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kStringType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kFalseType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kTrueType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kNumberType:
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Unsupported,
|
||||
"Unsupported type. AZStd::array entries can only be read from an array.");
|
||||
@@ -129,7 +140,16 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonArraySerializer::LoadContainer(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
auto JsonArraySerializer::GetOperationsFlags() const -> OperationFlags
|
||||
{
|
||||
return OperationFlags::InitializeNewInstance;
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonArraySerializer::LoadContainer(
|
||||
void* outputValue,
|
||||
const Uuid& outputValueTypeId,
|
||||
const rapidjson::Value& inputValue,
|
||||
bool isNewInstance,
|
||||
JsonDeserializerContext& context)
|
||||
{
|
||||
namespace JSR = JsonSerializationResult; // Used to remove name conflicts in AzCore in uber builds.
|
||||
@@ -154,14 +174,7 @@ namespace AZ
|
||||
"Unable to retrieve the correct container information for AZStd::array instance.");
|
||||
}
|
||||
|
||||
const size_t size = container->Size(outputValue);
|
||||
if (inputValue.Size() < size)
|
||||
{
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Unsupported,
|
||||
"Not enough entries in JSON array to load an AZStd::array from.");
|
||||
}
|
||||
|
||||
ContinuationFlags flags = ContinuationFlags::None;
|
||||
ContinuationFlags flags = isNewInstance ? ContinuationFlags::LoadAsNewInstance : ContinuationFlags::None;
|
||||
Uuid elementTypeId = Uuid::CreateNull();
|
||||
auto typeEnumCallback = [&elementTypeId, &flags](const Uuid&, const SerializeContext::ClassElement* genericClassElement)
|
||||
{
|
||||
@@ -175,13 +188,23 @@ namespace AZ
|
||||
};
|
||||
container->EnumTypes(typeEnumCallback);
|
||||
|
||||
const size_t size = container->Size(outputValue);
|
||||
if (!isNewInstance && inputValue.Size() < size)
|
||||
{
|
||||
return context.Report(
|
||||
JSR::Tasks::ReadField, JSR::Outcomes::Unsupported, "Not enough entries in JSON array to load an AZStd::array from.");
|
||||
}
|
||||
|
||||
rapidjson::Value explicitDefaultValue = GetExplicitDefault();
|
||||
|
||||
JSR::ResultCode retVal(JSR::Tasks::ReadField);
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
ScopedContextPath subPath(context, i);
|
||||
|
||||
void* element = container->GetElementByIndex(outputValue, nullptr, i);
|
||||
JSR::ResultCode result = ContinueLoading(element, elementTypeId, inputValue[aznumeric_caster(i)], context, flags);
|
||||
JSR::ResultCode result = ContinueLoading(
|
||||
element, elementTypeId, isNewInstance ? explicitDefaultValue : inputValue[aznumeric_caster(i)], context, flags);
|
||||
if (result.GetProcessing() == JSR::Processing::Halted)
|
||||
{
|
||||
return context.Report(result, "Failed to load data to element in AZStd::array.");
|
||||
@@ -189,15 +212,19 @@ namespace AZ
|
||||
retVal.Combine(result);
|
||||
}
|
||||
|
||||
if (container->Size(outputValue) == inputValue.Size())
|
||||
if (isNewInstance)
|
||||
{
|
||||
return context.Report(retVal, "Filled new instance of AZStd::array with defaults.");
|
||||
}
|
||||
else if (container->Size(outputValue) == inputValue.Size())
|
||||
{
|
||||
return context.Report(retVal, "Successfully read entries into AZStd::array.");
|
||||
}
|
||||
else
|
||||
{
|
||||
retVal.Combine(JSR::ResultCode(JSR::Tasks::ReadField, JSR::Outcomes::Skipped));
|
||||
return context.Report(retVal,
|
||||
"Successfully read available entries into AZStd::array, but there were still values left in the JSON array.");
|
||||
return context.Report(
|
||||
retVal, "Successfully read available entries into AZStd::array, but there were still values left in the JSON array.");
|
||||
}
|
||||
}
|
||||
} // namespace AZ
|
||||
|
||||
@@ -30,8 +30,14 @@ namespace AZ
|
||||
JsonSerializationResult::Result Store(rapidjson::Value& outputValue, const void* inputValue, const void* defaultValue,
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
|
||||
OperationFlags GetOperationsFlags() const override;
|
||||
|
||||
protected:
|
||||
JsonSerializationResult::Result LoadContainer(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonSerializationResult::Result LoadContainer(
|
||||
void* outputValue,
|
||||
const Uuid& outputValueTypeId,
|
||||
const rapidjson::Value& inputValue,
|
||||
bool isNewInstance,
|
||||
JsonDeserializerContext& context);
|
||||
};
|
||||
} // namespace AZ
|
||||
|
||||
@@ -216,9 +216,10 @@ namespace AZ
|
||||
JsonSerializationResult::ResultCode BaseJsonSerializer::ContinueLoading(
|
||||
void* object, const Uuid& typeId, const rapidjson::Value& value, JsonDeserializerContext& context, ContinuationFlags flags)
|
||||
{
|
||||
bool loadAsNewInstance = (flags & ContinuationFlags::LoadAsNewInstance) == ContinuationFlags::LoadAsNewInstance;
|
||||
return (flags & ContinuationFlags::ResolvePointer) == ContinuationFlags::ResolvePointer
|
||||
? JsonDeserializer::LoadToPointer(object, typeId, value, context)
|
||||
: JsonDeserializer::Load(object, typeId, value, context);
|
||||
: JsonDeserializer::Load(object, typeId, value, loadAsNewInstance, context);
|
||||
}
|
||||
|
||||
JsonSerializationResult::ResultCode BaseJsonSerializer::ContinueStoring(
|
||||
|
||||
@@ -163,15 +163,20 @@ namespace AZ
|
||||
|
||||
enum class ContinuationFlags
|
||||
{
|
||||
None = 0, //! No extra flags.
|
||||
ResolvePointer = 1 << 0, //! The pointer passed in contains a pointer. The (de)serializer will attempt to resolve to an instance.
|
||||
ReplaceDefault = 1 << 1 //! The default value provided for storing will be replaced with a newly created one.
|
||||
None = 0, //! No extra flags.
|
||||
ResolvePointer = 1 << 0, //! The pointer passed in contains a pointer. The (de)serializer will attempt to resolve to an instance.
|
||||
ReplaceDefault = 1 << 1, //! The default value provided for storing will be replaced with a newly created one.
|
||||
LoadAsNewInstance = 1 << 2 //! Treats the value as if it's a newly created instance. This may trigger serializers marked with
|
||||
//! OperationFlags::InitializeNewInstance. Used for instance by pointers or new instances added to
|
||||
//! an array.
|
||||
};
|
||||
|
||||
enum class OperationFlags
|
||||
{
|
||||
None = 0, //! No flags that control how the custom json serializer is used.
|
||||
ManualDefault = 1 << 0 //! Even if an (explicit) default is found the custom json serializer will still be called.
|
||||
None = 0, //! No flags that control how the custom json serializer is used.
|
||||
ManualDefault = 1 << 0, //! Even if an (explicit) default is found the custom json serializer will still be called.
|
||||
InitializeNewInstance = 1 << 1 //! If set, the custom json serializer will be called with an explicit default if a new
|
||||
//! instance of its target type is created.
|
||||
};
|
||||
|
||||
virtual ~BaseJsonSerializer() = default;
|
||||
|
||||
@@ -34,11 +34,16 @@ namespace AZ
|
||||
case rapidjson::kArrayType:
|
||||
return LoadContainer(outputValue, outputValueTypeId, inputValue, context);
|
||||
|
||||
case rapidjson::kObjectType: // fall through
|
||||
case rapidjson::kNullType: // fall through
|
||||
case rapidjson::kStringType: // fall through
|
||||
case rapidjson::kFalseType: // fall through
|
||||
case rapidjson::kTrueType: // fall through
|
||||
case rapidjson::kObjectType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kNullType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kStringType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kFalseType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kTrueType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kNumberType:
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Unsupported,
|
||||
"Unsupported type. Basic containers can only be read from an array.");
|
||||
@@ -123,6 +128,10 @@ namespace AZ
|
||||
{
|
||||
if (retVal.HasDoneWork())
|
||||
{
|
||||
// If at least one value was written, even if it has all defaults, then the array has
|
||||
// a value written to it and is therefore not in a default state anymore.
|
||||
retVal.Combine(JSR::ResultCode(JSR::Tasks::WriteValue, JSR::Outcomes::Success));
|
||||
|
||||
outputValue = AZStd::move(array);
|
||||
return context.Report(retVal, "Content written to basic container.");
|
||||
}
|
||||
@@ -165,6 +174,7 @@ namespace AZ
|
||||
ContinuationFlags flags = classElement->m_flags & SerializeContext::ClassElement::Flags::FLG_POINTER
|
||||
? ContinuationFlags::ResolvePointer
|
||||
: ContinuationFlags::None;
|
||||
flags |= ContinuationFlags::LoadAsNewInstance;
|
||||
|
||||
const size_t capacity = container->IsFixedCapacity() ? container->Capacity(outputValue) : std::numeric_limits<size_t>::max();
|
||||
|
||||
@@ -243,6 +253,11 @@ namespace AZ
|
||||
}
|
||||
|
||||
size_t addedCount = container->Size(outputValue) - containerSize;
|
||||
if (addedCount > 0)
|
||||
{
|
||||
// Values were added which means the container is no longer in its default state of being empty.
|
||||
retVal.Combine(JSR::ResultCode(JSR::Tasks::ReadField, JSR::Outcomes::Success));
|
||||
}
|
||||
AZStd::string_view message =
|
||||
addedCount >= arraySize ? "Successfully read basic container.":
|
||||
addedCount == 0 ? "Unable to read data for basic container." :
|
||||
|
||||
@@ -82,12 +82,18 @@ namespace AZ
|
||||
|
||||
bool* valAsBool = reinterpret_cast<bool*>(outputValue);
|
||||
|
||||
if (IsExplicitDefault(inputValue))
|
||||
{
|
||||
*valAsBool = {};
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::DefaultsUsed, "Boolean value set to default of 'false'.");
|
||||
}
|
||||
|
||||
switch (inputValue.GetType())
|
||||
{
|
||||
case rapidjson::kArrayType:
|
||||
// fallthrough
|
||||
[[fallthrough]];
|
||||
case rapidjson::kObjectType:
|
||||
// fallthrough
|
||||
[[fallthrough]];
|
||||
case rapidjson::kNullType:
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Unsupported,
|
||||
"Unsupported type. Booleans can't be read from arrays, objects or null.");
|
||||
@@ -96,7 +102,7 @@ namespace AZ
|
||||
return SerializerInternal::TextToValue(valAsBool, inputValue.GetString(), inputValue.GetStringLength(), context);
|
||||
|
||||
case rapidjson::kFalseType:
|
||||
// fallthrough
|
||||
[[fallthrough]];
|
||||
case rapidjson::kTrueType:
|
||||
*valAsBool = inputValue.GetBool();
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Success, "Successfully read boolean.");
|
||||
@@ -145,4 +151,9 @@ namespace AZ
|
||||
|
||||
return context.Report(JSR::Tasks::WriteValue, JSR::Outcomes::DefaultsUsed, "Default boolean used.");
|
||||
}
|
||||
|
||||
auto JsonBoolSerializer::GetOperationsFlags() const -> OperationFlags
|
||||
{
|
||||
return OperationFlags::InitializeNewInstance;
|
||||
}
|
||||
} // namespace AZ
|
||||
|
||||
@@ -27,5 +27,6 @@ namespace AZ
|
||||
JsonDeserializerContext& context) override;
|
||||
JsonSerializationResult::Result Store(rapidjson::Value& outputValue, const void* inputValue, const void* defaultValue,
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
OperationFlags GetOperationsFlags() const override;
|
||||
};
|
||||
} // namespace AZ
|
||||
|
||||
@@ -62,19 +62,26 @@ namespace AZ
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static JsonSerializationResult::Result Load(T* outputValue, const rapidjson::Value& inputValue, JsonDeserializerContext& context)
|
||||
static JsonSerializationResult::Result Load(
|
||||
T* outputValue, const rapidjson::Value& inputValue, JsonDeserializerContext& context, bool isExplicitDefault)
|
||||
{
|
||||
namespace JSR = JsonSerializationResult; // Used remove name conflicts in AzCore in uber builds.
|
||||
|
||||
static_assert(AZStd::is_floating_point<T>::value, "Expected T to be a floating point type");
|
||||
AZ_Assert(outputValue, "Expected a valid pointer to load from json value.");
|
||||
|
||||
if (isExplicitDefault)
|
||||
{
|
||||
*outputValue = {};
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::DefaultsUsed, "Floating point value set to default of 0.0.");
|
||||
}
|
||||
|
||||
switch (inputValue.GetType())
|
||||
{
|
||||
case rapidjson::kArrayType:
|
||||
// fallthrough
|
||||
[[fallthrough]];
|
||||
case rapidjson::kObjectType:
|
||||
// fallthrough
|
||||
[[fallthrough]];
|
||||
case rapidjson::kNullType:
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Unsupported,
|
||||
"Unsupported type. Floating point values can't be read from arrays, objects or null.");
|
||||
@@ -83,7 +90,7 @@ namespace AZ
|
||||
return TextToValue(outputValue, inputValue.GetString(), context);
|
||||
|
||||
case rapidjson::kFalseType:
|
||||
// fallthrough
|
||||
[[fallthrough]];
|
||||
case rapidjson::kTrueType:
|
||||
*outputValue = inputValue.GetBool() ? 1.0f : 0.0f;
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Success,
|
||||
@@ -144,7 +151,8 @@ namespace AZ
|
||||
"Unable to deserialize double to json because the provided type is %s",
|
||||
outputValueTypeId.ToString<AZStd::string>().c_str());
|
||||
AZ_UNUSED(outputValueTypeId);
|
||||
return SerializerFloatingPointInternal::Load(reinterpret_cast<double*>(outputValue), inputValue, context);
|
||||
return SerializerFloatingPointInternal::Load(
|
||||
reinterpret_cast<double*>(outputValue), inputValue, context, IsExplicitDefault(inputValue));
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonDoubleSerializer::Store(rapidjson::Value& outputValue, const void* inputValue,
|
||||
@@ -156,6 +164,11 @@ namespace AZ
|
||||
return SerializerFloatingPointInternal::Store<double>(outputValue, inputValue, defaultValue, context);
|
||||
}
|
||||
|
||||
auto JsonDoubleSerializer::GetOperationsFlags() const -> OperationFlags
|
||||
{
|
||||
return OperationFlags::InitializeNewInstance;
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonFloatSerializer::Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context)
|
||||
{
|
||||
@@ -163,7 +176,8 @@ namespace AZ
|
||||
"Unable to deserialize float to json because the provided type is %s",
|
||||
outputValueTypeId.ToString<AZStd::string>().c_str());
|
||||
AZ_UNUSED(outputValueTypeId);
|
||||
return SerializerFloatingPointInternal::Load(reinterpret_cast<float*>(outputValue), inputValue, context);
|
||||
return SerializerFloatingPointInternal::Load(
|
||||
reinterpret_cast<float*>(outputValue), inputValue, context, IsExplicitDefault(inputValue));
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonFloatSerializer::Store(rapidjson::Value& outputValue, const void* inputValue,
|
||||
@@ -174,4 +188,9 @@ namespace AZ
|
||||
AZ_UNUSED(valueTypeId);
|
||||
return SerializerFloatingPointInternal::Store<float>(outputValue, inputValue, defaultValue, context);
|
||||
}
|
||||
|
||||
auto JsonFloatSerializer::GetOperationsFlags() const -> OperationFlags
|
||||
{
|
||||
return OperationFlags::InitializeNewInstance;
|
||||
}
|
||||
} // namespace AZ
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace AZ
|
||||
JsonDeserializerContext& context) override;
|
||||
JsonSerializationResult::Result Store(rapidjson::Value& outputValue, const void* inputValue, const void* defaultValue,
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
OperationFlags GetOperationsFlags() const override;
|
||||
};
|
||||
|
||||
class JsonFloatSerializer
|
||||
@@ -40,5 +41,6 @@ namespace AZ
|
||||
JsonDeserializerContext& context) override;
|
||||
JsonSerializationResult::Result Store(rapidjson::Value& outputValue, const void* inputValue, const void* defaultValue,
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
OperationFlags GetOperationsFlags() const override;
|
||||
};
|
||||
} // namespace AZ
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
AZ_CLASS_ALLOCATOR_IMPL(BaseJsonIntegerSerializer, SystemAllocator, 0);
|
||||
|
||||
AZ_CLASS_ALLOCATOR_IMPL(JsonCharSerializer, SystemAllocator, 0);
|
||||
AZ_CLASS_ALLOCATOR_IMPL(JsonShortSerializer, SystemAllocator, 0);
|
||||
AZ_CLASS_ALLOCATOR_IMPL(JsonIntSerializer, SystemAllocator, 0);
|
||||
@@ -56,19 +58,25 @@ namespace AZ
|
||||
|
||||
template <typename T>
|
||||
static JsonSerializationResult::Result LoadInt(T* outputValue, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context)
|
||||
JsonDeserializerContext& context, bool isDefaultValue)
|
||||
{
|
||||
namespace JSR = JsonSerializationResult; // Used remove name conflicts in AzCore in uber builds.
|
||||
|
||||
static_assert(AZStd::is_integral<T>(), "Expected T to be a signed or unsigned type");
|
||||
AZ_Assert(outputValue, "Expected a valid pointer to load from json value.");
|
||||
|
||||
if (isDefaultValue)
|
||||
{
|
||||
*outputValue = {};
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::DefaultsUsed, "Integer value set to default of zero.");
|
||||
}
|
||||
|
||||
switch (inputValue.GetType())
|
||||
{
|
||||
case rapidjson::kArrayType:
|
||||
// fallthrough
|
||||
[[fallthrough]];
|
||||
case rapidjson::kObjectType:
|
||||
// fallthrough
|
||||
[[fallthrough]];
|
||||
case rapidjson::kNullType:
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Unsupported,
|
||||
"Unsupported type. Integers can't be read from arrays, objects or null.");
|
||||
@@ -77,7 +85,7 @@ namespace AZ
|
||||
return TextToValue(outputValue, inputValue.GetString(), context);
|
||||
|
||||
case rapidjson::kFalseType:
|
||||
// fallthrough
|
||||
[[fallthrough]];
|
||||
case rapidjson::kTrueType:
|
||||
*outputValue = inputValue.GetBool() ? 1 : 0;
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Success,
|
||||
@@ -125,6 +133,11 @@ namespace AZ
|
||||
}
|
||||
} // namespace SerializerInternal
|
||||
|
||||
auto BaseJsonIntegerSerializer::GetOperationsFlags() const -> OperationFlags
|
||||
{
|
||||
return OperationFlags::InitializeNewInstance;
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonCharSerializer::Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context)
|
||||
{
|
||||
@@ -132,7 +145,7 @@ namespace AZ
|
||||
"Unable to deserialize char to json because the provided type is %s",
|
||||
outputValueTypeId.ToString<AZStd::string>().c_str());
|
||||
AZ_UNUSED(outputValueTypeId);
|
||||
return SerializerInternal::LoadInt(reinterpret_cast<char*>(outputValue), inputValue, context);
|
||||
return SerializerInternal::LoadInt(reinterpret_cast<char*>(outputValue), inputValue, context, IsExplicitDefault(inputValue));
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonCharSerializer::Store(rapidjson::Value& outputValue, const void* inputValue, const void* defaultValue,
|
||||
@@ -151,7 +164,7 @@ namespace AZ
|
||||
"Unable to deserialize short to json because the provided type is %s",
|
||||
outputValueTypeId.ToString<AZStd::string>().c_str());
|
||||
AZ_UNUSED(outputValueTypeId);
|
||||
return SerializerInternal::LoadInt(reinterpret_cast<short*>(outputValue), inputValue, context);
|
||||
return SerializerInternal::LoadInt(reinterpret_cast<short*>(outputValue), inputValue, context, IsExplicitDefault(inputValue));
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonShortSerializer::Store(rapidjson::Value& outputValue, const void* inputValue, const void* defaultValue,
|
||||
@@ -170,7 +183,7 @@ namespace AZ
|
||||
"Unable to deserialize int to json because the provided type is %s",
|
||||
outputValueTypeId.ToString<AZStd::string>().c_str());
|
||||
AZ_UNUSED(outputValueTypeId);
|
||||
return SerializerInternal::LoadInt(reinterpret_cast<int*>(outputValue), inputValue, context);
|
||||
return SerializerInternal::LoadInt(reinterpret_cast<int*>(outputValue), inputValue, context, IsExplicitDefault(inputValue));
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonIntSerializer::Store(rapidjson::Value& outputValue, const void* inputValue, const void* defaultValue,
|
||||
@@ -189,7 +202,7 @@ namespace AZ
|
||||
"Unable to deserialize long to json because the provided type is %s",
|
||||
outputValueTypeId.ToString<AZStd::string>().c_str());
|
||||
AZ_UNUSED(outputValueTypeId);
|
||||
return SerializerInternal::LoadInt(reinterpret_cast<long*>(outputValue), inputValue, context);
|
||||
return SerializerInternal::LoadInt(reinterpret_cast<long*>(outputValue), inputValue, context, IsExplicitDefault(inputValue));
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonLongSerializer::Store(rapidjson::Value& outputValue, const void* inputValue, const void* defaultValue,
|
||||
@@ -208,7 +221,7 @@ namespace AZ
|
||||
"Unable to deserialize long long to json because the provided type is %s",
|
||||
outputValueTypeId.ToString<AZStd::string>().c_str());
|
||||
AZ_UNUSED(outputValueTypeId);
|
||||
return SerializerInternal::LoadInt(reinterpret_cast<long long*>(outputValue), inputValue, context);
|
||||
return SerializerInternal::LoadInt(reinterpret_cast<long long*>(outputValue), inputValue, context, IsExplicitDefault(inputValue));
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonLongLongSerializer::Store(rapidjson::Value& outputValue, const void* inputValue, const void* defaultValue,
|
||||
@@ -227,7 +240,8 @@ namespace AZ
|
||||
"Unable to deserialize unsigned char to json because the provided type is %s",
|
||||
outputValueTypeId.ToString<AZStd::string>().c_str());
|
||||
AZ_UNUSED(outputValueTypeId);
|
||||
return SerializerInternal::LoadInt(reinterpret_cast<unsigned char*>(outputValue), inputValue, context);
|
||||
return SerializerInternal::LoadInt(
|
||||
reinterpret_cast<unsigned char*>(outputValue), inputValue, context, IsExplicitDefault(inputValue));
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonUnsignedCharSerializer::Store(rapidjson::Value& outputValue, const void* inputValue,
|
||||
@@ -246,7 +260,8 @@ namespace AZ
|
||||
"Unable to deserialize unsigned short to json because the provided type is %s",
|
||||
outputValueTypeId.ToString<AZStd::string>().c_str());
|
||||
AZ_UNUSED(outputValueTypeId);
|
||||
return SerializerInternal::LoadInt(reinterpret_cast<unsigned short*>(outputValue), inputValue, context);
|
||||
return SerializerInternal::LoadInt(
|
||||
reinterpret_cast<unsigned short*>(outputValue), inputValue, context, IsExplicitDefault(inputValue));
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonUnsignedShortSerializer::Store(rapidjson::Value& outputValue, const void* inputValue,
|
||||
@@ -265,7 +280,8 @@ namespace AZ
|
||||
"Unable to deserialize unsigned int to json because the provided type is %s",
|
||||
outputValueTypeId.ToString<AZStd::string>().c_str());
|
||||
AZ_UNUSED(outputValueTypeId);
|
||||
return SerializerInternal::LoadInt(reinterpret_cast<unsigned int*>(outputValue), inputValue, context);
|
||||
return SerializerInternal::LoadInt(
|
||||
reinterpret_cast<unsigned int*>(outputValue), inputValue, context, IsExplicitDefault(inputValue));
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonUnsignedIntSerializer::Store(rapidjson::Value& outputValue, const void* inputValue,
|
||||
@@ -284,7 +300,8 @@ namespace AZ
|
||||
"Unable to deserialize unsigned long to json because the provided type is %s",
|
||||
outputValueTypeId.ToString<AZStd::string>().c_str());
|
||||
AZ_UNUSED(outputValueTypeId);
|
||||
return SerializerInternal::LoadInt(reinterpret_cast<unsigned long*>(outputValue), inputValue, context);
|
||||
return SerializerInternal::LoadInt(
|
||||
reinterpret_cast<unsigned long*>(outputValue), inputValue, context, IsExplicitDefault(inputValue));
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonUnsignedLongSerializer::Store(rapidjson::Value& outputValue, const void* inputValue,
|
||||
@@ -303,7 +320,8 @@ namespace AZ
|
||||
"Unable to deserialize unsigned long long to json because the provided type is %s",
|
||||
outputValueTypeId.ToString<AZStd::string>().c_str());
|
||||
AZ_UNUSED(outputValueTypeId);
|
||||
return SerializerInternal::LoadInt(reinterpret_cast<unsigned long long*>(outputValue), inputValue, context);
|
||||
return SerializerInternal::LoadInt(
|
||||
reinterpret_cast<unsigned long long*>(outputValue), inputValue, context, IsExplicitDefault(inputValue));
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonUnsignedLongLongSerializer::Store(rapidjson::Value& outputValue, const void* inputValue,
|
||||
|
||||
@@ -18,11 +18,18 @@
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class JsonCharSerializer
|
||||
: public BaseJsonSerializer
|
||||
class BaseJsonIntegerSerializer : public BaseJsonSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonCharSerializer, "{CA2A4AAC-3068-40B2-94F8-A537FBA8236E}", BaseJsonSerializer);
|
||||
AZ_RTTI(BaseJsonIntegerSerializer, "{FD060F54-D3B5-4D5B-B64A-AFE371CD6F20}", BaseJsonSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
OperationFlags GetOperationsFlags() const override;
|
||||
};
|
||||
|
||||
class JsonCharSerializer : public BaseJsonIntegerSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonCharSerializer, "{CA2A4AAC-3068-40B2-94F8-A537FBA8236E}", BaseJsonIntegerSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
@@ -30,11 +37,10 @@ namespace AZ
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
};
|
||||
|
||||
class JsonShortSerializer
|
||||
: public BaseJsonSerializer
|
||||
class JsonShortSerializer : public BaseJsonIntegerSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonShortSerializer, "{3D6789BD-231B-4E5D-B81D-609E71A2BCB5}", BaseJsonSerializer);
|
||||
AZ_RTTI(JsonShortSerializer, "{3D6789BD-231B-4E5D-B81D-609E71A2BCB5}", BaseJsonIntegerSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
@@ -42,11 +48,10 @@ namespace AZ
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
};
|
||||
|
||||
class JsonIntSerializer
|
||||
: public BaseJsonSerializer
|
||||
class JsonIntSerializer : public BaseJsonIntegerSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonIntSerializer, "{29E26946-0F1F-44B0-A098-1171B7B0C8FA}", BaseJsonSerializer);
|
||||
AZ_RTTI(JsonIntSerializer, "{29E26946-0F1F-44B0-A098-1171B7B0C8FA}", BaseJsonIntegerSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
@@ -54,11 +59,10 @@ namespace AZ
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
};
|
||||
|
||||
class JsonLongSerializer
|
||||
: public BaseJsonSerializer
|
||||
class JsonLongSerializer : public BaseJsonIntegerSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonLongSerializer, "{0EB432D0-A0C8-43B2-9D65-A73A4D6DFE3E}", BaseJsonSerializer);
|
||||
AZ_RTTI(JsonLongSerializer, "{0EB432D0-A0C8-43B2-9D65-A73A4D6DFE3E}", BaseJsonIntegerSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
@@ -66,11 +70,10 @@ namespace AZ
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
};
|
||||
|
||||
class JsonLongLongSerializer
|
||||
: public BaseJsonSerializer
|
||||
class JsonLongLongSerializer : public BaseJsonIntegerSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonLongLongSerializer, "{5E7967DE-A4DC-40E1-81A1-2896A054BB8A}", BaseJsonSerializer);
|
||||
AZ_RTTI(JsonLongLongSerializer, "{5E7967DE-A4DC-40E1-81A1-2896A054BB8A}", BaseJsonIntegerSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
@@ -78,11 +81,10 @@ namespace AZ
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
};
|
||||
|
||||
class JsonUnsignedCharSerializer
|
||||
: public BaseJsonSerializer
|
||||
class JsonUnsignedCharSerializer : public BaseJsonIntegerSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonUnsignedCharSerializer, "{1E6D606F-8490-4736-AAFF-91046FDEA2BB}", BaseJsonSerializer);
|
||||
AZ_RTTI(JsonUnsignedCharSerializer, "{1E6D606F-8490-4736-AAFF-91046FDEA2BB}", BaseJsonIntegerSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
@@ -90,11 +92,10 @@ namespace AZ
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
};
|
||||
|
||||
class JsonUnsignedShortSerializer
|
||||
: public BaseJsonSerializer
|
||||
class JsonUnsignedShortSerializer : public BaseJsonIntegerSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonUnsignedShortSerializer, "{3C92D2CC-CB13-4A40-B779-47562EE36451}", BaseJsonSerializer);
|
||||
AZ_RTTI(JsonUnsignedShortSerializer, "{3C92D2CC-CB13-4A40-B779-47562EE36451}", BaseJsonIntegerSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
@@ -102,11 +103,10 @@ namespace AZ
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
};
|
||||
|
||||
class JsonUnsignedIntSerializer
|
||||
: public BaseJsonSerializer
|
||||
class JsonUnsignedIntSerializer : public BaseJsonIntegerSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonUnsignedIntSerializer, "{70C0714A-690D-4F30-8986-ABC9DEFE9D62}", BaseJsonSerializer);
|
||||
AZ_RTTI(JsonUnsignedIntSerializer, "{70C0714A-690D-4F30-8986-ABC9DEFE9D62}", BaseJsonIntegerSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
@@ -114,11 +114,10 @@ namespace AZ
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
};
|
||||
|
||||
class JsonUnsignedLongSerializer
|
||||
: public BaseJsonSerializer
|
||||
class JsonUnsignedLongSerializer : public BaseJsonIntegerSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonUnsignedLongSerializer, "{28E5499F-6AF4-4778-AE14-66BA40B56247}", BaseJsonSerializer);
|
||||
AZ_RTTI(JsonUnsignedLongSerializer, "{28E5499F-6AF4-4778-AE14-66BA40B56247}", BaseJsonIntegerSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
@@ -126,11 +125,10 @@ namespace AZ
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
};
|
||||
|
||||
class JsonUnsignedLongLongSerializer
|
||||
: public BaseJsonSerializer
|
||||
class JsonUnsignedLongLongSerializer : public BaseJsonIntegerSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonUnsignedLongLongSerializer, "{AB048BB3-C280-4166-9E2E-54CE2C3413CA}", BaseJsonSerializer);
|
||||
AZ_RTTI(JsonUnsignedLongLongSerializer, "{AB048BB3-C280-4166-9E2E-54CE2C3413CA}", BaseJsonIntegerSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
|
||||
@@ -19,25 +19,30 @@
|
||||
#include <AzCore/Serialization/Json/RegistrationContext.h>
|
||||
#include <AzCore/Serialization/Json/StackedString.h>
|
||||
#include <AzCore/std/string/conversions.h>
|
||||
#include <AzCore/std/string/fixed_string.h>
|
||||
#include <AzCore/std/string/string.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
JsonSerializationResult::ResultCode JsonDeserializer::DeserializerDefaultCheck(BaseJsonSerializer* serializer, void* object,
|
||||
const Uuid& typeId, const rapidjson::Value& value, JsonDeserializerContext& context)
|
||||
const Uuid& typeId,const rapidjson::Value& value, bool isNewInstance, JsonDeserializerContext& context)
|
||||
{
|
||||
using namespace AZ::JsonSerializationResult;
|
||||
|
||||
bool isExplicitDefault = IsExplicitDefault(value);
|
||||
bool manuallyDefaults = (serializer->GetOperationsFlags() & BaseJsonSerializer::OperationFlags::ManualDefault) ==
|
||||
BaseJsonSerializer::OperationFlags::ManualDefault;
|
||||
return !isExplicitDefault || (isExplicitDefault && manuallyDefaults)
|
||||
bool initializeNewInstance = (serializer->GetOperationsFlags() & BaseJsonSerializer::OperationFlags::InitializeNewInstance) ==
|
||||
BaseJsonSerializer::OperationFlags::InitializeNewInstance;
|
||||
|
||||
return
|
||||
!isExplicitDefault || (isExplicitDefault && manuallyDefaults) || (isExplicitDefault && isNewInstance && initializeNewInstance)
|
||||
? serializer->Load(object, typeId, value, context)
|
||||
: context.Report(Tasks::ReadField, Outcomes::DefaultsUsed, "Value has an explicit default.");
|
||||
}
|
||||
|
||||
JsonSerializationResult::ResultCode JsonDeserializer::Load(void* object, const Uuid& typeId, const rapidjson::Value& value,
|
||||
JsonDeserializerContext& context)
|
||||
JsonSerializationResult::ResultCode JsonDeserializer::Load(
|
||||
void* object, const Uuid& typeId, const rapidjson::Value& value, bool isNewInstance, JsonDeserializerContext& context)
|
||||
{
|
||||
using namespace AZ::JsonSerializationResult;
|
||||
|
||||
@@ -50,7 +55,7 @@ namespace AZ
|
||||
BaseJsonSerializer* serializer = context.GetRegistrationContext()->GetSerializerForType(typeId);
|
||||
if (serializer)
|
||||
{
|
||||
return DeserializerDefaultCheck(serializer, object, typeId, value, context);
|
||||
return DeserializerDefaultCheck(serializer, object, typeId, value, isNewInstance, context);
|
||||
}
|
||||
|
||||
const SerializeContext::ClassData* classData = context.GetSerializeContext()->FindClassData(typeId);
|
||||
@@ -72,7 +77,7 @@ namespace AZ
|
||||
serializer = context.GetRegistrationContext()->GetSerializerForType(classData->m_azRtti->GetGenericTypeId());
|
||||
if (serializer)
|
||||
{
|
||||
return DeserializerDefaultCheck(serializer, object, typeId, value, context);
|
||||
return DeserializerDefaultCheck(serializer, object, typeId, value, isNewInstance, context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +138,7 @@ namespace AZ
|
||||
const SerializeContext::ClassData* resolvedClassData = context.GetSerializeContext()->FindClassData(resolvedTypeId);
|
||||
if (resolvedClassData)
|
||||
{
|
||||
status = JsonDeserializer::Load(*objectPtr, resolvedTypeId, value, context);
|
||||
status = JsonDeserializer::Load(*objectPtr, resolvedTypeId, value, true, context);
|
||||
|
||||
*objectPtr = resolvedClassData->m_azRtti->Cast(*objectPtr, typeId);
|
||||
|
||||
@@ -174,7 +179,7 @@ namespace AZ
|
||||
}
|
||||
else
|
||||
{
|
||||
return Load(object, classElement.m_typeId, value, context);
|
||||
return Load(object, classElement.m_typeId, value, false, context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -591,7 +596,9 @@ namespace AZ
|
||||
}
|
||||
else
|
||||
{
|
||||
status = context.Report(Tasks::RetrieveInfo, Outcomes::Unknown, "Serialization information for target type not found.");
|
||||
using ReporterString = AZStd::fixed_string<1024>;
|
||||
status = context.Report(Tasks::RetrieveInfo, Outcomes::Unknown,
|
||||
ReporterString::format("Serialization information for target type %s not found.", loadedTypeId.m_typeId.ToString<ReporterString>().c_str()));
|
||||
return ResolvePointerResult::FullyProcessed;
|
||||
}
|
||||
objectType = loadedTypeId.m_typeId;
|
||||
|
||||
@@ -58,8 +58,8 @@ namespace AZ
|
||||
JsonDeserializer(const JsonDeserializer& rhs) = delete;
|
||||
JsonDeserializer(JsonDeserializer&& rhs) = delete;
|
||||
|
||||
static JsonSerializationResult::ResultCode Load(void* object, const Uuid& typeId, const rapidjson::Value& value,
|
||||
JsonDeserializerContext& context);
|
||||
static JsonSerializationResult::ResultCode Load(
|
||||
void* object, const Uuid& typeId, const rapidjson::Value& value, bool isNewInstance, JsonDeserializerContext& context);
|
||||
|
||||
static JsonSerializationResult::ResultCode LoadToPointer(void* object, const Uuid& typeId, const rapidjson::Value& value,
|
||||
JsonDeserializerContext& context);
|
||||
@@ -120,6 +120,7 @@ namespace AZ
|
||||
void* object,
|
||||
const Uuid& typeId,
|
||||
const rapidjson::Value& value,
|
||||
bool isNewInstance,
|
||||
JsonDeserializerContext& context);
|
||||
};
|
||||
} // namespace AZ
|
||||
|
||||
@@ -607,10 +607,12 @@ namespace AZ
|
||||
}
|
||||
else if (source.Size() > target.Size())
|
||||
{
|
||||
rapidjson::SizeType sourceCount = source.Size();
|
||||
for (rapidjson::SizeType i = count; i < sourceCount; ++i)
|
||||
// Loop backwards through the removals so that each removal has a valid index when processing in order.
|
||||
for (rapidjson::SizeType i = source.Size(); i > count; --i)
|
||||
{
|
||||
ScopedStackedString entryName(element, i);
|
||||
// (We use "i - 1" here instead of in the loop to ensure we don't wrap around our unsigned numbers in the case
|
||||
// where count is 0.)
|
||||
ScopedStackedString entryName(element, i - 1);
|
||||
patch.PushBack(CreatePatchInternal_Remove(allocator, element), allocator);
|
||||
resultCode.Combine(settings.m_reporting("Removed member from array in JSON Patch.",
|
||||
ResultCode(Tasks::CreatePatch, Outcomes::Success), element));
|
||||
|
||||
@@ -249,7 +249,7 @@ namespace AZ
|
||||
{
|
||||
StackedString path(StackedString::Format::JsonPointer);
|
||||
JsonDeserializerContext context(settings);
|
||||
result = JsonDeserializer::Load(object, objectType, root, context);
|
||||
result = JsonDeserializer::Load(object, objectType, root, false, context);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -190,6 +190,12 @@ namespace AZ
|
||||
}
|
||||
|
||||
size_t addedCount = container->Size(outputValue) - containerSize;
|
||||
if (addedCount > 0)
|
||||
{
|
||||
// If at least one entry was added then the map is no longer in it's default state so
|
||||
// mark is with success so the result can at best be partial defaults.
|
||||
retVal.Combine(JSR::ResultCode(JSR::Tasks::ReadField, JSR::Outcomes::Success));
|
||||
}
|
||||
AZStd::string_view message =
|
||||
addedCount >= maximumSize ? "Successfully read associative container." :
|
||||
addedCount == 0 ? "Unable to read data for the associative container." :
|
||||
@@ -215,10 +221,10 @@ namespace AZ
|
||||
// Load key
|
||||
void* keyAddress = pairContainer->GetElementByIndex(address, pairElement, 0);
|
||||
AZ_Assert(keyAddress, "Element reserved for associative container, but unable to retrieve address of the key.");
|
||||
ContinuationFlags keyLoadFlags = ContinuationFlags::None;
|
||||
ContinuationFlags keyLoadFlags = ContinuationFlags::LoadAsNewInstance;
|
||||
if (keyElement->m_flags & SerializeContext::ClassElement::Flags::FLG_POINTER)
|
||||
{
|
||||
keyLoadFlags = ContinuationFlags::ResolvePointer;
|
||||
keyLoadFlags |= ContinuationFlags::ResolvePointer;
|
||||
*reinterpret_cast<void**>(keyAddress) = nullptr;
|
||||
}
|
||||
JSR::ResultCode keyResult = ContinueLoading(keyAddress, keyElement->m_typeId, key, context, keyLoadFlags);
|
||||
@@ -231,10 +237,10 @@ namespace AZ
|
||||
// Load value
|
||||
void* valueAddress = pairContainer->GetElementByIndex(address, pairElement, 1);
|
||||
AZ_Assert(valueAddress, "Element reserved for associative container, but unable to retrieve address of the value.");
|
||||
ContinuationFlags valueLoadFlags = ContinuationFlags::None;
|
||||
ContinuationFlags valueLoadFlags = ContinuationFlags::LoadAsNewInstance;
|
||||
if (valueElement->m_flags & SerializeContext::ClassElement::Flags::FLG_POINTER)
|
||||
{
|
||||
valueLoadFlags = ContinuationFlags::ResolvePointer;
|
||||
valueLoadFlags |= ContinuationFlags::ResolvePointer;
|
||||
*reinterpret_cast<void**>(valueAddress) = nullptr;
|
||||
}
|
||||
JSR::ResultCode valueResult = ContinueLoading(valueAddress, valueElement->m_typeId, value, context, valueLoadFlags);
|
||||
|
||||
@@ -34,13 +34,24 @@ namespace AZ
|
||||
switch (inputValue.GetType())
|
||||
{
|
||||
case rapidjson::kArrayType:
|
||||
return LoadContainer(outputValue, outputValueTypeId, inputValue, context);
|
||||
return LoadContainer(outputValue, outputValueTypeId, inputValue, false, context);
|
||||
|
||||
case rapidjson::kObjectType: // fall through
|
||||
case rapidjson::kNullType: // fall through
|
||||
case rapidjson::kStringType: // fall through
|
||||
case rapidjson::kFalseType: // fall through
|
||||
case rapidjson::kTrueType: // fall through
|
||||
case rapidjson::kObjectType:
|
||||
if (IsExplicitDefault(inputValue))
|
||||
{
|
||||
// Because this serializer has only the operation flag "InitializeNewInstance" set, the only time this will be called with
|
||||
// an explicit default is when a new instance has been created.
|
||||
return LoadContainer(outputValue, outputValueTypeId, inputValue, true, context);
|
||||
}
|
||||
[[fallthrough]];
|
||||
case rapidjson::kNullType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kStringType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kFalseType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kTrueType:
|
||||
[[fallthrough]];
|
||||
case rapidjson::kNumberType:
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Unsupported,
|
||||
"Unsupported type. AZStd::pair or AZStd::tuple can only be read from an array.");
|
||||
@@ -127,8 +138,13 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
auto JsonTupleSerializer::GetOperationsFlags() const -> OperationFlags
|
||||
{
|
||||
return OperationFlags::InitializeNewInstance;
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result JsonTupleSerializer::LoadContainer(void* outputValue, const Uuid& outputValueTypeId,
|
||||
const rapidjson::Value& inputValue, JsonDeserializerContext& context)
|
||||
const rapidjson::Value& inputValue, bool isNewInstance, JsonDeserializerContext& context)
|
||||
{
|
||||
namespace JSR = JsonSerializationResult; // Used to remove name conflicts in AzCore in uber builds.
|
||||
|
||||
@@ -154,13 +170,6 @@ namespace AZ
|
||||
};
|
||||
container->EnumTypes(typeCountCallback);
|
||||
|
||||
rapidjson::SizeType arraySize = inputValue.Size();
|
||||
if (arraySize < typeCount)
|
||||
{
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Unsupported,
|
||||
"Not enough entries in array to load an AZStd::pair or AZStd::tuple from.");
|
||||
}
|
||||
|
||||
AZStd::vector<const SerializeContext::ClassElement*> classElements;
|
||||
classElements.reserve(typeCount);
|
||||
auto typeEnumCallback = [&classElements](const Uuid&, const SerializeContext::ClassElement* genericClassElement)
|
||||
@@ -171,46 +180,80 @@ namespace AZ
|
||||
container->EnumTypes(typeEnumCallback);
|
||||
|
||||
JSR::ResultCode retVal(JSR::Tasks::ReadField);
|
||||
rapidjson::SizeType arrayIndex = 0;
|
||||
size_t numElementsWritten = 0;
|
||||
for (size_t i = 0; i < typeCount; ++i)
|
||||
if (isNewInstance)
|
||||
{
|
||||
ScopedContextPath subPath(context, i);
|
||||
|
||||
void* elementAddress = container->GetElementByIndex(outputValue, nullptr, i);
|
||||
AZ_Assert(elementAddress, "Address of AZStd::pair or AZStd::tuple element %zu could not be retrieved.", i);
|
||||
rapidjson::Value explicitDefaultValue = GetExplicitDefault();
|
||||
|
||||
ContinuationFlags flags = classElements[i]->m_flags & SerializeContext::ClassElement::Flags::FLG_POINTER
|
||||
? ContinuationFlags::ResolvePointer
|
||||
: ContinuationFlags::None;
|
||||
|
||||
while (arrayIndex < inputValue.Size())
|
||||
for (size_t i = 0; i < typeCount; ++i)
|
||||
{
|
||||
JSR::ResultCode result = ContinueLoading(elementAddress, classElements[i]->m_typeId, inputValue[arrayIndex], context, flags);
|
||||
ScopedContextPath subPath(context, i);
|
||||
|
||||
void* elementAddress = container->GetElementByIndex(outputValue, nullptr, i);
|
||||
AZ_Assert(elementAddress, "Address of AZStd::pair or AZStd::tuple element %zu could not be retrieved.", i);
|
||||
|
||||
ContinuationFlags flags = ContinuationFlags::LoadAsNewInstance;
|
||||
flags |=
|
||||
(classElements[i]->m_flags & SerializeContext::ClassElement::Flags::FLG_POINTER ? ContinuationFlags::ResolvePointer
|
||||
: ContinuationFlags::None);
|
||||
JSR::ResultCode result = ContinueLoading(elementAddress, classElements[i]->m_typeId, explicitDefaultValue, context, flags);
|
||||
retVal.Combine(result);
|
||||
arrayIndex++;
|
||||
if (result.GetProcessing() == JSR::Processing::Halted)
|
||||
{
|
||||
return context.Report(retVal, "Failed to read element for AZStd::pair or AZStd::tuple.");
|
||||
}
|
||||
else if (result.GetProcessing() != JSR::Processing::Altered)
|
||||
{
|
||||
numElementsWritten++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (numElementsWritten < typeCount)
|
||||
{
|
||||
AZStd::string_view message = numElementsWritten == 0 ?
|
||||
"Unable to read data for AZStd::pair or AZStd::tuple." :
|
||||
"Partially read data for AZStd::pair or AZStd::tuple.";
|
||||
return context.Report(retVal, message);
|
||||
return context.Report(retVal, "Initialized AZStd::pair or AZStd::tuple to defaults.");
|
||||
}
|
||||
else
|
||||
{
|
||||
return context.Report(retVal, "Successfully read AZStd::pair or AZStd::tuple.");
|
||||
if (inputValue.Size() < typeCount)
|
||||
{
|
||||
return context.Report(
|
||||
JSR::Tasks::ReadField, JSR::Outcomes::Unsupported,
|
||||
"Not enough entries in array to load an AZStd::pair or AZStd::tuple from.");
|
||||
}
|
||||
|
||||
rapidjson::SizeType arrayIndex = 0;
|
||||
size_t numElementsWritten = 0;
|
||||
for (size_t i = 0; i < typeCount; ++i)
|
||||
{
|
||||
ScopedContextPath subPath(context, i);
|
||||
|
||||
void* elementAddress = container->GetElementByIndex(outputValue, nullptr, i);
|
||||
AZ_Assert(elementAddress, "Address of AZStd::pair or AZStd::tuple element %zu could not be retrieved.", i);
|
||||
|
||||
ContinuationFlags flags =
|
||||
(classElements[i]->m_flags & SerializeContext::ClassElement::Flags::FLG_POINTER ? ContinuationFlags::ResolvePointer
|
||||
: ContinuationFlags::None);
|
||||
while (arrayIndex < inputValue.Size())
|
||||
{
|
||||
JSR::ResultCode result =
|
||||
ContinueLoading(elementAddress, classElements[i]->m_typeId, inputValue[arrayIndex], context, flags);
|
||||
retVal.Combine(result);
|
||||
arrayIndex++;
|
||||
if (result.GetProcessing() == JSR::Processing::Halted)
|
||||
{
|
||||
return context.Report(retVal, "Failed to read element for AZStd::pair or AZStd::tuple.");
|
||||
}
|
||||
else if (result.GetProcessing() != JSR::Processing::Altered)
|
||||
{
|
||||
numElementsWritten++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (numElementsWritten < typeCount)
|
||||
{
|
||||
AZStd::string_view message = numElementsWritten == 0 ? "Unable to read data for AZStd::pair or AZStd::tuple."
|
||||
: "Partially read data for AZStd::pair or AZStd::tuple.";
|
||||
return context.Report(retVal, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
return context.Report(retVal, "Successfully read AZStd::pair or AZStd::tuple.");
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace AZ
|
||||
|
||||
@@ -23,13 +23,20 @@ namespace AZ
|
||||
public:
|
||||
AZ_RTTI(JsonTupleSerializer, "{1AA0ADC1-395A-4223-8A73-304ACDEE7793}", BaseJsonSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
JsonSerializationResult::Result Store(rapidjson::Value& outputValue, const void* inputValue, const void* defaultValue,
|
||||
const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||
|
||||
OperationFlags GetOperationsFlags() const override;
|
||||
|
||||
private:
|
||||
JsonSerializationResult::Result LoadContainer(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonSerializationResult::Result LoadContainer(
|
||||
void* outputValue,
|
||||
const Uuid& outputValueTypeId,
|
||||
const rapidjson::Value& inputValue,
|
||||
bool isNewInstance,
|
||||
JsonDeserializerContext& context);
|
||||
};
|
||||
} // namespace AZ
|
||||
|
||||
@@ -816,7 +816,11 @@ namespace AZ::SettingsRegistryMergeUtils
|
||||
}
|
||||
}
|
||||
|
||||
void MergeSettingsToRegistry_CommandLine(SettingsRegistryInterface& registry, const AZ::CommandLine& commandLine, bool executeCommands)
|
||||
// This function intentionally copies `commandLine`. It looks like it only uses it as a const reference, but the
|
||||
// code in the loop makes calls that mutates the `commandLine` instance, invalidating the iterators. Making a copy
|
||||
// ensures that the iterators remain valid.
|
||||
// NOLINTNEXTLINE(performance-unnecessary-value-param)
|
||||
void MergeSettingsToRegistry_CommandLine(SettingsRegistryInterface& registry, AZ::CommandLine commandLine, bool executeCommands)
|
||||
{
|
||||
// Iterate over all the command line options in order to parse the --regset and --regremove
|
||||
// arguments in the order they were supplied
|
||||
@@ -831,7 +835,7 @@ namespace AZ::SettingsRegistryMergeUtils
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (commandArgument.m_option == "regremove")
|
||||
else if (commandArgument.m_option == "regremove")
|
||||
{
|
||||
if (!registry.Remove(commandArgument.m_value))
|
||||
{
|
||||
|
||||
@@ -15,11 +15,7 @@
|
||||
#include <AzCore/IO/Path/Path_fwd.h>
|
||||
#include <AzCore/Memory/OSAllocator.h>
|
||||
#include <AzCore/Settings/SettingsRegistry.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class CommandLine;
|
||||
}
|
||||
#include <AzCore/Settings/CommandLine.h>
|
||||
|
||||
namespace AZ::IO
|
||||
{
|
||||
@@ -217,7 +213,7 @@ namespace AZ::SettingsRegistryMergeUtils
|
||||
//! example: --regdump /My/Array/With/Objects
|
||||
//! --regdumpall Dumps the entire settings registry to output.
|
||||
//! Note that this function is only called in development builds and is compiled out in release builds.
|
||||
void MergeSettingsToRegistry_CommandLine(SettingsRegistryInterface& registry, const AZ::CommandLine& commandLine, bool executeCommands);
|
||||
void MergeSettingsToRegistry_CommandLine(SettingsRegistryInterface& registry, AZ::CommandLine commandLine, bool executeCommands);
|
||||
|
||||
//! Stores the command line settings into the Setting Registry
|
||||
//! The arguments can be used later anywhere the command line is needed
|
||||
|
||||
Reference in New Issue
Block a user