Hi Guys,
I was getting my head around this issue the last couple days. Please find my implementation below.
To be considered:
- The c# binary formatter only works in the same appDomain (assambly), still need to get my head around that. This means the deserialization can only be done in the same program.
- The "InteractionBox" struc needs to be made serializable as well.
My serialization code is:
public byte[] Serialize
{
get
{
BinaryFormatter bf = new BinaryFormatter();
using (var ms = new MemoryStream())
{
bf.Serialize(ms, this);
return ms.ToArray();
}
}
}
My code for deserialization:
public void Deserialize(byte[] arg)
{
using (var ms = new MemoryStream())
{
BinaryFormatter bf = new BinaryFormatter();
ms.Write(arg, 0, arg.Length);
ms.Seek(0, SeekOrigin.Begin);
Frame objArray = (Frame)bf.Deserialize(ms);
this.Id = objArray.Id;
this.Timestamp = objArray.Timestamp;
this.CurrentFramesPerSecond = objArray.CurrentFramesPerSecond;
this.InteractionBox = objArray.InteractionBox;
this.Hands = objArray.Hands;
}
}
My code to get the Lenght:
public int SerializeLength
{
get
{
BinaryFormatter bf = new BinaryFormatter();
using (var ms = new MemoryStream())
{
bf.Serialize(ms, this);
return ms.ToArray().Length;
}
}
}
Part of the "InteractionBox.cs":
[System.Serializable]
public struct InteractionBox{...}
Also to create your own *.dll (Leap.dll in my case instead of the csharp.dll) in order to use the frame object serialization across several applications.
csc /t:library /out:Leap.dll LeapC.cs Arm.cs Bone.cs CircularObjectBuffer.cs ClockCorrelator.cs Config.cs Connection.cs Controller.cs CopyFromLeapCExtensions.cs CopyFromOtherExtensions.cs CSharpExtensions.cs Device.cs DeviceList.cs DistortionData.cs DistortionDictionary.cs Events.cs FailedDevice.cs FailedDeviceList.cs Finger.cs Frame.cs Hand.cs IController.cs Image.cs ImageData.cs ImageFuture.cs InteractionBox.cs LeapQuaternion.cs LeapTransform.cs Logger.cs Matrix.cs MessageSeverity.cs ObjectPool.cs PendingImages.cs PooledObject.cs StructMarshal.cs TimeBracket.cs TransformExtensions.cs Vector.cs
You still need to make the copy reference in your postbuild to the LeapC.dll from the x86/x64 SDK folder
Hope that helps,
Cheers Sedowan