Update read and write streaming api to use the newest format
This commit is contained in:
@@ -167,14 +167,14 @@ void ReadStream::Read(CommonValue& data)
|
||||
case CommonType::String:
|
||||
{
|
||||
String v;
|
||||
ReadString(&v, 953);
|
||||
Read(v, 953);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
case CommonType::Box:
|
||||
{
|
||||
BoundingBox v;
|
||||
ReadBoundingBox(&v);
|
||||
Read(v);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
@@ -188,14 +188,14 @@ void ReadStream::Read(CommonValue& data)
|
||||
case CommonType::Transform:
|
||||
{
|
||||
Transform v;
|
||||
ReadTransform(&v);
|
||||
Read(v);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
case CommonType::Sphere:
|
||||
{
|
||||
BoundingSphere v;
|
||||
ReadBoundingSphere(&v);
|
||||
Read(v);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
@@ -208,7 +208,7 @@ void ReadStream::Read(CommonValue& data)
|
||||
case CommonType::Ray:
|
||||
{
|
||||
Ray v;
|
||||
ReadRay(&v);
|
||||
Read(v);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
@@ -277,7 +277,7 @@ void ReadStream::Read(VariantType& data)
|
||||
void ReadStream::Read(Variant& data)
|
||||
{
|
||||
VariantType type;
|
||||
ReadVariantType(&type);
|
||||
Read(type);
|
||||
data.SetType(MoveTemp(type));
|
||||
switch (data.Type.Type)
|
||||
{
|
||||
@@ -360,7 +360,7 @@ void ReadStream::Read(Variant& data)
|
||||
{
|
||||
// Json
|
||||
StringAnsi json;
|
||||
ReadStringAnsi(&json, -71);
|
||||
Read(json, -71);
|
||||
#if USE_CSHARP
|
||||
MCore::Thread::Attach();
|
||||
MClass* klass = MUtils::GetClass(data.Type);
|
||||
@@ -430,22 +430,22 @@ void ReadStream::Read(Variant& data)
|
||||
ReadBytes(&data.AsData, sizeof(Guid));
|
||||
break;
|
||||
case VariantType::BoundingBox:
|
||||
ReadBoundingBox(&data.AsBoundingBox());
|
||||
Read(data.AsBoundingBox());
|
||||
break;
|
||||
case VariantType::BoundingSphere:
|
||||
ReadBoundingSphere(&data.AsBoundingSphere());
|
||||
Read(data.AsBoundingSphere());
|
||||
break;
|
||||
case VariantType::Quaternion:
|
||||
ReadBytes(&data.AsData, sizeof(Quaternion));
|
||||
break;
|
||||
case VariantType::Transform:
|
||||
ReadTransform(&data.AsTransform());
|
||||
Read(data.AsTransform());
|
||||
break;
|
||||
case VariantType::Rectangle:
|
||||
ReadBytes(&data.AsData, sizeof(Rectangle));
|
||||
break;
|
||||
case VariantType::Ray:
|
||||
ReadRay(&data.AsRay());
|
||||
Read(data.AsRay());
|
||||
break;
|
||||
case VariantType::Matrix:
|
||||
ReadBytes(data.AsBlob.Data, sizeof(Matrix));
|
||||
@@ -453,25 +453,25 @@ void ReadStream::Read(Variant& data)
|
||||
case VariantType::Array:
|
||||
{
|
||||
int32 count;
|
||||
ReadInt32(&count);
|
||||
Read(count);
|
||||
auto& array = *(Array<Variant>*)data.AsData;
|
||||
array.Resize(count);
|
||||
for (int32 i = 0; i < count; i++)
|
||||
ReadVariant(&array[i]);
|
||||
Read(array[i]);
|
||||
break;
|
||||
}
|
||||
case VariantType::Dictionary:
|
||||
{
|
||||
int32 count;
|
||||
ReadInt32(&count);
|
||||
Read(count);
|
||||
auto& dictionary = *data.AsDictionary;
|
||||
dictionary.Clear();
|
||||
dictionary.EnsureCapacity(count);
|
||||
for (int32 i = 0; i < count; i++)
|
||||
{
|
||||
Variant key;
|
||||
ReadVariant(&key);
|
||||
ReadVariant(&dictionary[MoveTemp(key)]);
|
||||
Read(key);
|
||||
Read(dictionary[MoveTemp(key)]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -562,18 +562,18 @@ void ReadStream::ReadVariant(Variant* data)
|
||||
Read(*data);
|
||||
}
|
||||
|
||||
void ReadStream::ReadBoundingBox(BoundingBox* box, bool useDouble)
|
||||
void ReadStream::Read(BoundingBox& box, bool useDouble)
|
||||
{
|
||||
#if USE_LARGE_WORLDS
|
||||
if (useDouble)
|
||||
Read(box);
|
||||
ReadBytes(&box, sizeof(BoundingBox));
|
||||
else
|
||||
{
|
||||
Float3 min, max;
|
||||
Read(min);
|
||||
Read(max);
|
||||
box->Minimum = min;
|
||||
box->Maximum = max;
|
||||
box.Minimum = min;
|
||||
box.Maximum = max;
|
||||
}
|
||||
#else
|
||||
if (useDouble)
|
||||
@@ -581,27 +581,27 @@ void ReadStream::ReadBoundingBox(BoundingBox* box, bool useDouble)
|
||||
Double3 min, max;
|
||||
Read(min);
|
||||
Read(max);
|
||||
box->Minimum = min;
|
||||
box->Maximum = max;
|
||||
box.Minimum = min;
|
||||
box.Maximum = max;
|
||||
}
|
||||
else
|
||||
Read(*box);
|
||||
ReadBytes(&box, sizeof(BoundingBox));
|
||||
#endif
|
||||
}
|
||||
|
||||
void ReadStream::ReadBoundingSphere(BoundingSphere* sphere, bool useDouble)
|
||||
void ReadStream::Read(BoundingSphere& sphere, bool useDouble)
|
||||
{
|
||||
#if USE_LARGE_WORLDS
|
||||
if (useDouble)
|
||||
Read(*sphere);
|
||||
ReadBytes(&sphere, sizeof(BoundingSphere));
|
||||
else
|
||||
{
|
||||
Float3 center;
|
||||
float radius;
|
||||
Read(center);
|
||||
Read(radius);
|
||||
sphere->Center = center;
|
||||
sphere->Radius = radius;
|
||||
sphere.Center = center;
|
||||
sphere.Radius = radius;
|
||||
}
|
||||
#else
|
||||
if (useDouble)
|
||||
@@ -610,53 +610,53 @@ void ReadStream::ReadBoundingSphere(BoundingSphere* sphere, bool useDouble)
|
||||
double radius;
|
||||
Read(center);
|
||||
Read(radius);
|
||||
sphere->Center = center;
|
||||
sphere->Radius = (float)radius;
|
||||
sphere.Center = center;
|
||||
sphere.Radius = (float)radius;
|
||||
}
|
||||
else
|
||||
Read(*sphere);
|
||||
ReadBytes(&sphere, sizeof(BoundingSphere));
|
||||
#endif
|
||||
}
|
||||
|
||||
void ReadStream::ReadTransform(Transform* transform, bool useDouble)
|
||||
void ReadStream::Read(Transform& transform, bool useDouble)
|
||||
{
|
||||
#if USE_LARGE_WORLDS
|
||||
if (useDouble)
|
||||
Read(*transform);
|
||||
ReadBytes(&transform, sizeof(Transform));
|
||||
else
|
||||
{
|
||||
Float3 translation;
|
||||
Read(translation);
|
||||
Read(transform->Orientation);
|
||||
Read(transform->Scale);
|
||||
transform->Translation = translation;
|
||||
Read(transform.Orientation);
|
||||
Read(transform.Scale);
|
||||
transform.Translation = translation;
|
||||
}
|
||||
#else
|
||||
if (useDouble)
|
||||
{
|
||||
Double3 translation;
|
||||
Read(translation);
|
||||
Read(transform->Orientation);
|
||||
Read(transform->Scale);
|
||||
transform->Translation = translation;
|
||||
Read(transform.Orientation);
|
||||
Read(transform.Scale);
|
||||
transform.Translation = translation;
|
||||
}
|
||||
else
|
||||
Read(*transform);
|
||||
ReadBytes(&transform, sizeof(Transform));
|
||||
#endif
|
||||
}
|
||||
|
||||
void ReadStream::ReadRay(Ray* ray, bool useDouble)
|
||||
void ReadStream::Read(Ray& ray, bool useDouble)
|
||||
{
|
||||
#if USE_LARGE_WORLDS
|
||||
if (useDouble)
|
||||
Read(*ray);
|
||||
ReadBytes(&ray, sizeof(Ray));
|
||||
else
|
||||
{
|
||||
Float3 position, direction;
|
||||
Read(position);
|
||||
Read(direction);
|
||||
ray->Position = position;
|
||||
ray->Direction = direction;
|
||||
ray.Position = position;
|
||||
ray.Direction = direction;
|
||||
}
|
||||
#else
|
||||
if (useDouble)
|
||||
@@ -664,14 +664,34 @@ void ReadStream::ReadRay(Ray* ray, bool useDouble)
|
||||
Double3 position, direction;
|
||||
Read(position);
|
||||
Read(direction);
|
||||
ray->Position = position;
|
||||
ray->Direction = direction;
|
||||
ray.Position = position;
|
||||
ray.Direction = direction;
|
||||
}
|
||||
else
|
||||
Read(*ray);
|
||||
ReadBytes(&ray, sizeof(Ray));
|
||||
#endif
|
||||
}
|
||||
|
||||
void ReadStream::ReadBoundingBox(BoundingBox* box, bool useDouble)
|
||||
{
|
||||
Read(*box);
|
||||
}
|
||||
|
||||
void ReadStream::ReadBoundingSphere(BoundingSphere* sphere, bool useDouble)
|
||||
{
|
||||
Read(*sphere);
|
||||
}
|
||||
|
||||
void ReadStream::ReadTransform(Transform* transform, bool useDouble)
|
||||
{
|
||||
Read(*transform);
|
||||
}
|
||||
|
||||
void ReadStream::ReadRay(Ray* ray, bool useDouble)
|
||||
{
|
||||
Read(*ray);
|
||||
}
|
||||
|
||||
void WriteStream::WriteText(const StringView& text)
|
||||
{
|
||||
WriteBytes(text.Get(), sizeof(Char) * text.Length());
|
||||
@@ -722,13 +742,13 @@ void WriteStream::Write(const CommonValue& data)
|
||||
switch (data.Type)
|
||||
{
|
||||
case CommonType::Bool:
|
||||
WriteBool(data.AsBool);
|
||||
Write(data.AsBool);
|
||||
break;
|
||||
case CommonType::Integer:
|
||||
WriteInt32(data.AsInteger);
|
||||
Write(data.AsInteger);
|
||||
break;
|
||||
case CommonType::Float:
|
||||
WriteFloat(data.AsFloat);
|
||||
Write(data.AsFloat);
|
||||
break;
|
||||
case CommonType::Vector2:
|
||||
Write(data.AsVector2);
|
||||
@@ -746,25 +766,25 @@ void WriteStream::Write(const CommonValue& data)
|
||||
Write(data.AsGuid);
|
||||
break;
|
||||
case CommonType::String:
|
||||
WriteString(data.AsString, 953);
|
||||
Write(data.AsString, 953);
|
||||
break;
|
||||
case CommonType::Box:
|
||||
WriteBoundingBox(data.AsBox);
|
||||
Write(data.AsBox);
|
||||
break;
|
||||
case CommonType::Rotation:
|
||||
Write(data.AsRotation);
|
||||
break;
|
||||
case CommonType::Transform:
|
||||
WriteTransform(data.AsTransform);
|
||||
Write(data.AsTransform);
|
||||
break;
|
||||
case CommonType::Sphere:
|
||||
WriteBoundingSphere(data.AsSphere);
|
||||
Write(data.AsSphere);
|
||||
break;
|
||||
case CommonType::Rectangle:
|
||||
Write(data.AsRectangle);
|
||||
break;
|
||||
case CommonType::Ray:
|
||||
WriteRay(data.AsRay);
|
||||
Write(data.AsRay);
|
||||
break;
|
||||
case CommonType::Matrix:
|
||||
Write(data.AsMatrix);
|
||||
@@ -782,12 +802,12 @@ void WriteStream::Write(const VariantType& data)
|
||||
{
|
||||
WriteByte((byte)data.Type);
|
||||
WriteInt32(MAX_int32);
|
||||
WriteStringAnsi(StringAnsiView(data.TypeName), 77);
|
||||
Write(StringAnsiView(data.TypeName), 77);
|
||||
}
|
||||
|
||||
void WriteStream::Write(const Variant& data)
|
||||
{
|
||||
WriteVariantType(data.Type);
|
||||
Write(data.Type);
|
||||
Guid id;
|
||||
switch (data.Type.Type)
|
||||
{
|
||||
@@ -826,7 +846,7 @@ void WriteStream::Write(const Variant& data)
|
||||
WriteUint64((uint64)(uintptr)data.AsPointer);
|
||||
break;
|
||||
case VariantType::String:
|
||||
WriteString((StringView)data, -14);
|
||||
Write((StringView)data, -14);
|
||||
break;
|
||||
case VariantType::Object:
|
||||
id = data.AsObject ? data.AsObject->GetID() : Guid::Empty;
|
||||
@@ -837,13 +857,13 @@ void WriteStream::Write(const Variant& data)
|
||||
WriteBytes(data.AsBlob.Data, data.AsBlob.Length);
|
||||
break;
|
||||
case VariantType::BoundingBox:
|
||||
WriteBoundingBox(data.AsBoundingBox());
|
||||
Write(data.AsBoundingBox());
|
||||
break;
|
||||
case VariantType::Transform:
|
||||
WriteTransform(data.AsTransform());
|
||||
Write(data.AsTransform());
|
||||
break;
|
||||
case VariantType::Ray:
|
||||
WriteRay(data.AsRay());
|
||||
Write(data.AsRay());
|
||||
break;
|
||||
case VariantType::Matrix:
|
||||
WriteBytes(data.AsBlob.Data, sizeof(Matrix));
|
||||
@@ -883,24 +903,24 @@ void WriteStream::Write(const Variant& data)
|
||||
WriteBytes(data.AsData, sizeof(Rectangle));
|
||||
break;
|
||||
case VariantType::BoundingSphere:
|
||||
WriteBoundingSphere(data.AsBoundingSphere());
|
||||
Write(data.AsBoundingSphere());
|
||||
break;
|
||||
case VariantType::Array:
|
||||
id.A = ((Array<Variant>*)data.AsData)->Count();
|
||||
WriteInt32(id.A);
|
||||
for (uint32 i = 0; i < id.A; i++)
|
||||
WriteVariant(((Array<Variant>*)data.AsData)->At(i));
|
||||
Write(((Array<Variant>*)data.AsData)->At(i));
|
||||
break;
|
||||
case VariantType::Dictionary:
|
||||
WriteInt32(data.AsDictionary->Count());
|
||||
for (auto i = data.AsDictionary->Begin(); i.IsNotEnd(); ++i)
|
||||
{
|
||||
WriteVariant(i->Key);
|
||||
WriteVariant(i->Value);
|
||||
Write(i->Key);
|
||||
Write(i->Value);
|
||||
}
|
||||
break;
|
||||
case VariantType::Typename:
|
||||
WriteStringAnsi((StringAnsiView)data, -14);
|
||||
Write((StringAnsiView)data, -14);
|
||||
break;
|
||||
case VariantType::ManagedObject:
|
||||
case VariantType::Structure:
|
||||
@@ -918,7 +938,7 @@ void WriteStream::Write(const Variant& data)
|
||||
CompactJsonWriter writerObj(json);
|
||||
MCore::Thread::Attach();
|
||||
ManagedSerialization::Serialize(writerObj, obj);
|
||||
WriteStringAnsi(StringAnsiView(json.GetString(), (int32)json.GetSize()), -71);
|
||||
Write(StringAnsiView(json.GetString(), (int32)json.GetSize()), -71);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@@ -992,11 +1012,11 @@ void WriteStream::WriteVariant(const Variant& data)
|
||||
Write(data);
|
||||
}
|
||||
|
||||
void WriteStream::WriteBoundingBox(const BoundingBox& box, bool useDouble)
|
||||
void WriteStream::Write(const BoundingBox& box, bool useDouble)
|
||||
{
|
||||
#if USE_LARGE_WORLDS
|
||||
if (useDouble)
|
||||
Write(box);
|
||||
WriteBytes(&box, sizeof(BoundingBox));
|
||||
else
|
||||
{
|
||||
Float3 min = box.Minimum, max = box.Maximum;
|
||||
@@ -1011,15 +1031,15 @@ void WriteStream::WriteBoundingBox(const BoundingBox& box, bool useDouble)
|
||||
Write(max);
|
||||
}
|
||||
else
|
||||
Write(box);
|
||||
WriteBytes(&box, sizeof(BoundingBox));
|
||||
#endif
|
||||
}
|
||||
|
||||
void WriteStream::WriteBoundingSphere(const BoundingSphere& sphere, bool useDouble)
|
||||
void WriteStream::Write(const BoundingSphere& sphere, bool useDouble)
|
||||
{
|
||||
#if USE_LARGE_WORLDS
|
||||
if (useDouble)
|
||||
Write(sphere);
|
||||
WriteBytes(&sphere, sizeof(BoundingSphere));
|
||||
else
|
||||
{
|
||||
Float3 center = sphere.Center;
|
||||
@@ -1036,15 +1056,15 @@ void WriteStream::WriteBoundingSphere(const BoundingSphere& sphere, bool useDoub
|
||||
Write(radius);
|
||||
}
|
||||
else
|
||||
Write(sphere);
|
||||
WriteBytes(&sphere, sizeof(BoundingSphere));
|
||||
#endif
|
||||
}
|
||||
|
||||
void WriteStream::WriteTransform(const Transform& transform, bool useDouble)
|
||||
void WriteStream::Write(const Transform& transform, bool useDouble)
|
||||
{
|
||||
#if USE_LARGE_WORLDS
|
||||
if (useDouble)
|
||||
Write(transform);
|
||||
WriteBytes(&transform, sizeof(Transform));
|
||||
else
|
||||
{
|
||||
Float3 translation = transform.Translation;
|
||||
@@ -1061,15 +1081,15 @@ void WriteStream::WriteTransform(const Transform& transform, bool useDouble)
|
||||
Write(transform.Scale);
|
||||
}
|
||||
else
|
||||
Write(transform);
|
||||
WriteBytes(&transform, sizeof(Transform));
|
||||
#endif
|
||||
}
|
||||
|
||||
void WriteStream::WriteRay(const Ray& ray, bool useDouble)
|
||||
void WriteStream::Write(const Ray& ray, bool useDouble)
|
||||
{
|
||||
#if USE_LARGE_WORLDS
|
||||
if (useDouble)
|
||||
Write(ray);
|
||||
WriteBytes(&ray, sizeof(Ray));
|
||||
else
|
||||
{
|
||||
Float3 position = ray.Position, direction = ray.Direction;
|
||||
@@ -1084,10 +1104,30 @@ void WriteStream::WriteRay(const Ray& ray, bool useDouble)
|
||||
Write(direction);
|
||||
}
|
||||
else
|
||||
Write(ray);
|
||||
WriteBytes(&ray, sizeof(Ray));
|
||||
#endif
|
||||
}
|
||||
|
||||
void WriteStream::WriteBoundingBox(const BoundingBox& box, bool useDouble)
|
||||
{
|
||||
Write(box, useDouble);
|
||||
}
|
||||
|
||||
void WriteStream::WriteBoundingSphere(const BoundingSphere& sphere, bool useDouble)
|
||||
{
|
||||
Write(sphere, useDouble);
|
||||
}
|
||||
|
||||
void WriteStream::WriteTransform(const Transform& transform, bool useDouble)
|
||||
{
|
||||
Write(transform, useDouble);
|
||||
}
|
||||
|
||||
void WriteStream::WriteRay(const Ray& ray, bool useDouble)
|
||||
{
|
||||
Write(ray, useDouble);
|
||||
}
|
||||
|
||||
Array<byte> JsonSerializer::SaveToBytes(ISerializable* obj)
|
||||
{
|
||||
Array<byte> result;
|
||||
|
||||
Reference in New Issue
Block a user