diff --git a/LibreMetaverse.Types/Color4.cs b/LibreMetaverse.Types/Color4.cs index 0b7dd8e0..0fd21fc0 100644 --- a/LibreMetaverse.Types/Color4.cs +++ b/LibreMetaverse.Types/Color4.cs @@ -1,5 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co + * Copyright (c) 2021, Sjofn LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -26,6 +27,7 @@ using System; using System.Runtime.InteropServices; +using ProtoBuf; namespace OpenMetaverse { @@ -34,15 +36,20 @@ namespace OpenMetaverse /// [Serializable] [StructLayout(LayoutKind.Sequential)] + [ProtoContract] public struct Color4 : IComparable, IEquatable { /// Red + [ProtoMember(1)] public float R; /// Green + [ProtoMember(2)] public float G; /// Blue + [ProtoMember(3)] public float B; /// Alpha + [ProtoMember(4)] public float A; #region Constructors diff --git a/LibreMetaverse.Types/LibreMetaverse.Types.csproj b/LibreMetaverse.Types/LibreMetaverse.Types.csproj index f34673ff..247cd4af 100644 --- a/LibreMetaverse.Types/LibreMetaverse.Types.csproj +++ b/LibreMetaverse.Types/LibreMetaverse.Types.csproj @@ -130,6 +130,9 @@ + + + diff --git a/LibreMetaverse.Types/Quaternion.cs b/LibreMetaverse.Types/Quaternion.cs index 34ff2b4f..f5e92eff 100644 --- a/LibreMetaverse.Types/Quaternion.cs +++ b/LibreMetaverse.Types/Quaternion.cs @@ -1,5 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co + * Copyright (c) 2021, Sjofn LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -27,23 +28,29 @@ using System; using System.Runtime.InteropServices; using System.Globalization; +using ProtoBuf; namespace OpenMetaverse { [Serializable] + [ProtoContract] [StructLayout(LayoutKind.Sequential)] public struct Quaternion : IEquatable { /// X value + [ProtoMember(1)] public float X; /// Y value + [ProtoMember(2)] public float Y; /// Z value + [ProtoMember(3)] public float Z; /// W value + [ProtoMember(4)] public float W; #region Constructors diff --git a/LibreMetaverse.Types/UUID.cs b/LibreMetaverse.Types/UUID.cs index 98e516d5..eaf13353 100644 --- a/LibreMetaverse.Types/UUID.cs +++ b/LibreMetaverse.Types/UUID.cs @@ -1,5 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co + * Copyright (c) 2021, Sjofn LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -26,6 +27,7 @@ using System; using System.Security.Cryptography; +using ProtoBuf; namespace OpenMetaverse { @@ -34,9 +36,11 @@ namespace OpenMetaverse /// Life networking protocol /// [Serializable] + [ProtoContract] public struct UUID : IComparable, IEquatable { /// The System.Guid object this struct wraps around + [ProtoMember(1)] public Guid Guid { get; set; } #region Constructors diff --git a/LibreMetaverse.Types/Vector2.cs b/LibreMetaverse.Types/Vector2.cs index e3138516..f01fc2a2 100644 --- a/LibreMetaverse.Types/Vector2.cs +++ b/LibreMetaverse.Types/Vector2.cs @@ -1,5 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co + * Copyright (c) 2021, Sjofn LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -27,6 +28,7 @@ using System; using System.Runtime.InteropServices; using System.Globalization; +using ProtoBuf; namespace OpenMetaverse { @@ -35,11 +37,14 @@ namespace OpenMetaverse /// [Serializable] [StructLayout(LayoutKind.Sequential)] + [ProtoContract] public struct Vector2 : IComparable, IEquatable { /// X value + [ProtoMember(1)] public float X; /// Y value + [ProtoMember(2)] public float Y; #region Constructors diff --git a/LibreMetaverse.Types/Vector3.cs b/LibreMetaverse.Types/Vector3.cs index b4655170..b0e89ac5 100644 --- a/LibreMetaverse.Types/Vector3.cs +++ b/LibreMetaverse.Types/Vector3.cs @@ -1,5 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co + * Copyright (c) 2021, Sjofn LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -27,6 +28,7 @@ using System; using System.Runtime.InteropServices; using System.Globalization; +using ProtoBuf; namespace OpenMetaverse { @@ -35,15 +37,19 @@ namespace OpenMetaverse /// [Serializable] [StructLayout(LayoutKind.Sequential)] + [ProtoContract] public struct Vector3 : IComparable, IEquatable { /// X value + [ProtoMember(1)] public float X; /// Y value + [ProtoMember(2)] public float Y; /// Z value + [ProtoMember(3)] public float Z; #region Constructors diff --git a/LibreMetaverse.Types/Vector3d.cs b/LibreMetaverse.Types/Vector3d.cs index 0f71dabe..383c8ed1 100644 --- a/LibreMetaverse.Types/Vector3d.cs +++ b/LibreMetaverse.Types/Vector3d.cs @@ -1,5 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co + * Copyright (c) 2021, Sjofn LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -27,6 +28,7 @@ using System; using System.Runtime.InteropServices; using System.Globalization; +using ProtoBuf; namespace OpenMetaverse { @@ -35,13 +37,17 @@ namespace OpenMetaverse /// [Serializable] [StructLayout(LayoutKind.Sequential)] + [ProtoContract] public struct Vector3d : IComparable, IEquatable { /// X value + [ProtoMember(1)] public double X; /// Y value + [ProtoMember(2)] public double Y; /// Z value + [ProtoMember(3)] public double Z; #region Constructors diff --git a/LibreMetaverse.Types/Vector4.cs b/LibreMetaverse.Types/Vector4.cs index 3ed77218..91f9b38a 100644 --- a/LibreMetaverse.Types/Vector4.cs +++ b/LibreMetaverse.Types/Vector4.cs @@ -1,5 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co + * Copyright (c) 2021, Sjofn LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -27,20 +28,26 @@ using System; using System.Runtime.InteropServices; using System.Globalization; +using ProtoBuf; namespace OpenMetaverse { [Serializable] [StructLayout(LayoutKind.Sequential)] + [ProtoContract] public struct Vector4 : IComparable, IEquatable { /// X value + [ProtoMember(1)] public float X; /// Y value + [ProtoMember(2)] public float Y; /// Z value + [ProtoMember(3)] public float Z; /// W value + [ProtoMember(4)] public float W; #region Constructors diff --git a/LibreMetaverse/Inventory.cs b/LibreMetaverse/Inventory.cs index 6a2cb8b1..e9800962 100644 --- a/LibreMetaverse/Inventory.cs +++ b/LibreMetaverse/Inventory.cs @@ -28,6 +28,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Runtime.Serialization.Formatters.Binary; +using ProtoBuf; namespace OpenMetaverse { @@ -351,7 +352,7 @@ namespace OpenMetaverse Logger.Log("Caching " + Items.Count.ToString() + " inventory items to " + filename, Helpers.LogLevel.Info); foreach (KeyValuePair kvp in Items) { - ZeroFormatter.ZeroFormatterSerializer.Serialize(stream, kvp.Value); + Serializer.Serialize(stream, kvp.Value); } } } @@ -381,7 +382,7 @@ namespace OpenMetaverse { while (stream.Position < stream.Length) { - var node = ZeroFormatter.ZeroFormatterSerializer.Deserialize(stream); + var node = Serializer.Deserialize(stream); nodes.Add(node); item_count++; } diff --git a/LibreMetaverse/InventoryBase.cs b/LibreMetaverse/InventoryBase.cs index a7c8c529..e1ed982a 100644 --- a/LibreMetaverse/InventoryBase.cs +++ b/LibreMetaverse/InventoryBase.cs @@ -1,24 +1,57 @@ -using System; -using System.Collections.Generic; +/* + * Copyright (c) 2006-2016, openmetaverse.co + * Copyright (c) 2021, Sjofn LLC. + * All rights reserved. + * + * - Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Neither the name of the openmetaverse.co nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +using System; using System.Runtime.Serialization; -using System.Text; using OpenMetaverse.StructuredData; +using ProtoBuf; namespace OpenMetaverse { /// /// Base Class for Inventory Items /// - [Serializable()] + [Serializable] + [ProtoContract] + [ProtoInclude(5, typeof(InventoryItem))] + [ProtoInclude(6, typeof(InventoryFolder))] public abstract class InventoryBase : ISerializable { /// of item/folder + [ProtoMember(1)] public UUID UUID; /// of parent folder + [ProtoMember(2)] public UUID ParentUUID; /// Name of item/folder + [ProtoMember(3)] public string Name; /// Item/Folder Owners + [ProtoMember(4)] public UUID OwnerID; /// @@ -102,6 +135,20 @@ namespace OpenMetaverse /// An Item in Inventory /// [Serializable] + [ProtoContract(SkipConstructor=true)] + [ProtoInclude(15, typeof(InventoryTexture))] + [ProtoInclude(16, typeof(InventorySound))] + [ProtoInclude(17, typeof(InventoryCallingCard))] + [ProtoInclude(18, typeof(InventoryLandmark))] + [ProtoInclude(19, typeof(InventoryObject))] + [ProtoInclude(20, typeof(InventoryNotecard))] + [ProtoInclude(21, typeof(InventoryCategory))] + [ProtoInclude(22, typeof(InventoryLSL))] + [ProtoInclude(23, typeof(InventorySnapshot))] + [ProtoInclude(24, typeof(InventoryAttachment))] + [ProtoInclude(25, typeof(InventoryWearable))] + [ProtoInclude(26, typeof(InventoryAnimation))] + [ProtoInclude(27, typeof(InventoryGesture))] public class InventoryItem : InventoryBase { public override string ToString() @@ -110,33 +157,47 @@ namespace OpenMetaverse Description + "' " + Permissions; } /// The of this item + [ProtoMember(1)] public UUID AssetUUID; /// The combined of this item + [ProtoMember(2)] public Permissions Permissions; /// The type of item from + [ProtoMember(3)] public AssetType AssetType; /// The type of item from the enum + [ProtoMember(4)] public InventoryType InventoryType; /// The of the creator of this item + [ProtoMember(5)] public UUID CreatorID; /// A Description of this item + [ProtoMember(6)] public string Description; /// The s this item is set to or owned by + [ProtoMember(7)] public UUID GroupID; /// If true, item is owned by a group + [ProtoMember(8)] public bool GroupOwned; /// The price this item can be purchased for + [ProtoMember(9)] public int SalePrice; /// The type of sale from the enum + [ProtoMember(10)] public SaleType SaleType; /// Combined flags from + [ProtoMember(11)] public uint Flags; /// Time and date this inventory item was created, stored as /// UTC (Coordinated Universal Time) + [ProtoMember(12)] public DateTime CreationDate; /// Used to update the AssetID in requests sent to the server + [ProtoMember(13)] public UUID TransactionID; /// The of the previous owner of the item + [ProtoMember(14)] public UUID LastOwnerID; /// @@ -348,7 +409,8 @@ namespace OpenMetaverse /// InventoryTexture Class representing a graphical image /// /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryTexture : InventoryItem { /// @@ -376,7 +438,8 @@ namespace OpenMetaverse /// /// InventorySound Class representing a playable sound /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventorySound : InventoryItem { /// @@ -404,7 +467,8 @@ namespace OpenMetaverse /// /// InventoryCallingCard Class, contains information on another avatar /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryCallingCard : InventoryItem { /// @@ -432,7 +496,8 @@ namespace OpenMetaverse /// /// InventoryLandmark Class, contains details on a specific location /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryLandmark : InventoryItem { /// @@ -474,7 +539,8 @@ namespace OpenMetaverse /// /// InventoryObject Class contains details on a primitive or coalesced set of primitives /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryObject : InventoryItem { /// @@ -520,7 +586,8 @@ namespace OpenMetaverse /// /// InventoryNotecard Class, contains details on an encoded text document /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryNotecard : InventoryItem { /// @@ -549,7 +616,8 @@ namespace OpenMetaverse /// InventoryCategory Class /// /// TODO: Is this even used for anything? - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryCategory : InventoryItem { /// @@ -577,7 +645,8 @@ namespace OpenMetaverse /// /// InventoryLSL Class, represents a Linden Scripting Language object /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryLSL : InventoryItem { /// @@ -605,7 +674,8 @@ namespace OpenMetaverse /// /// InventorySnapshot Class, an image taken with the viewer /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventorySnapshot : InventoryItem { /// @@ -633,7 +703,8 @@ namespace OpenMetaverse /// /// InventoryAttachment Class, contains details on an attachable object /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryAttachment : InventoryItem { /// @@ -670,7 +741,8 @@ namespace OpenMetaverse /// /// InventoryWearable Class, details on a clothing item or body part /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryWearable : InventoryItem { /// @@ -703,7 +775,8 @@ namespace OpenMetaverse /// /// InventoryAnimation Class, A bvh encoded object which animates an avatar /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryAnimation : InventoryItem { /// @@ -731,7 +804,8 @@ namespace OpenMetaverse /// /// InventoryGesture Class, details on a series of animations, sounds, and actions /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryGesture : InventoryItem { /// @@ -760,7 +834,9 @@ namespace OpenMetaverse /// A folder contains s and has certain attributes specific /// to itself /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] + public class InventoryFolder : InventoryBase { /// The Preferred for a folder. diff --git a/LibreMetaverse/InventoryNode.cs b/LibreMetaverse/InventoryNode.cs index 3298974e..0e3de723 100644 --- a/LibreMetaverse/InventoryNode.cs +++ b/LibreMetaverse/InventoryNode.cs @@ -27,58 +27,34 @@ using System; using System.Runtime.Serialization; -using ZeroFormatter; +using ProtoBuf; namespace OpenMetaverse { - [ZeroFormattable] - public class InventoryNode + [Serializable] + [ProtoContract(SkipConstructor=true)] + public class InventoryNode : ISerializable { - [Index(0)] - private InventoryBase data; - [Index(1)] - private InventoryNode parent; - [Index(3)] - private UUID parentID; //used for de-seralization - [Index(4)] private InventoryNodeDictionary nodes; - [Index(5)] - private bool needsUpdate = true; - [IgnoreFormat] - private object tag; - /// - public InventoryBase Data - { - get => data; - set => data = value; - } + [ProtoMember(1)] + public InventoryBase Data { get; set; } - /// User data - public object Tag - { - get => tag; - set => tag = value; - } + [ProtoMember(2)] + public InventoryNode Parent { get; set; } - /// - public InventoryNode Parent - { - get => parent; - set => parent = value; - } + [ProtoMember(3)] + public UUID ParentID { get; } - /// - public UUID ParentID => parentID; - - /// + [ProtoMember(4)] public InventoryNodeDictionary Nodes { - get { return nodes ?? (nodes = new InventoryNodeDictionary(this)); } + get => nodes ?? (nodes = new InventoryNodeDictionary(this)); set => nodes = value; } - public System.DateTime ModifyTime + [ProtoMember(5)] + public DateTime ModifyTime { get { @@ -86,7 +62,7 @@ namespace OpenMetaverse { return item.CreationDate; } - DateTime newest = default(DateTime); //.MinValue; + DateTime newest = default; //.MinValue; if (Data is InventoryFolder) { foreach (var node in Nodes.Values) @@ -99,29 +75,17 @@ namespace OpenMetaverse } } - public void Sort() - { - Nodes.Sort(); - } - /// /// For inventory folder nodes specifies weather the folder needs to be /// refreshed from the server /// - public bool NeedsUpdate - { - get { return needsUpdate; } - set { needsUpdate = value; } - } - - public InventoryNode() - { - } + [ProtoMember(6)] + public bool NeedsUpdate { get; set; } /// public InventoryNode(InventoryBase data) { - this.data = data; + this.Data = data; } /// @@ -129,8 +93,8 @@ namespace OpenMetaverse /// public InventoryNode(InventoryBase data, InventoryNode parent) { - this.data = data; - this.parent = parent; + this.Data = data; + this.Parent = parent; if (parent != null) { @@ -138,15 +102,20 @@ namespace OpenMetaverse lock (parent.Nodes.SyncRoot) parent.Nodes.Add(data.UUID, this); } } + + public void Sort() + { + Nodes.Sort(); + } /// /// Serialization handler for the InventoryNode Class /// public void GetObjectData(SerializationInfo info, StreamingContext ctxt) { - info.AddValue("Parent", parent?.Data.UUID ?? UUID.Zero, typeof(UUID)); - info.AddValue("Type", data.GetType(), typeof(Type)); - data.GetObjectData(info, ctxt); + info.AddValue("Parent", Parent?.Data.UUID ?? UUID.Zero, typeof(UUID)); + info.AddValue("Type", Data.GetType(), typeof(Type)); + Data.GetObjectData(info, ctxt); } /// @@ -154,12 +123,12 @@ namespace OpenMetaverse /// public InventoryNode(SerializationInfo info, StreamingContext ctxt) { - parentID = (UUID)info.GetValue("Parent", typeof(UUID)); + ParentID = (UUID)info.GetValue("Parent", typeof(UUID)); Type type = (Type)info.GetValue("Type", typeof(Type)); // Construct a new inventory object based on the Type stored in Type - System.Reflection.ConstructorInfo ctr = type.GetConstructor(new Type[] {typeof(SerializationInfo),typeof(StreamingContext)}); - data = (InventoryBase) ctr.Invoke(new Object[] { info, ctxt }); + System.Reflection.ConstructorInfo ctr = type.GetConstructor(new[] {typeof(SerializationInfo),typeof(StreamingContext)}); + Data = (InventoryBase) ctr?.Invoke(new object[] { info, ctxt }); } public override string ToString() diff --git a/LibreMetaverse/LibreMetaverse.csproj b/LibreMetaverse/LibreMetaverse.csproj index 5cef4f8c..c87ade29 100644 --- a/LibreMetaverse/LibreMetaverse.csproj +++ b/LibreMetaverse/LibreMetaverse.csproj @@ -126,12 +126,12 @@ + -