public static byte[] Serialize(SkeletonDataAlternative data)
 {
     byte[] bytes = null;
     using (BinaryStreamWriter w = new BinaryStreamWriter(new MemoryStream()))
     {
         w.Write(data.TrackingID);
         w.Write(data.UserIndex);
         w.Write(data.TrackingState);
         w.Write(data.Quality);
         switch (data.TrackingState)
         {
             case SkeletonTrackingState.Tracked:
                 w.Write(data.Position);
                 w.Write(data.Joints.Count);
                 foreach (Joint joint in data.Joints)
                 {
                     w.Write(joint);
                 }
                 break;
             case SkeletonTrackingState.NotTracked:
                 break;
             case SkeletonTrackingState.PositionOnly:
                 w.Write(data.Position);
                 break;
             default:
                 throw new UnknownSkeletonTrackingStateException(data.TrackingState);
         }
         bytes = ((MemoryStream)w.Stream).ToArray();
         w.Close();
     }
     return bytes;
 }
 public static byte[] Serialize(SkeletonFrameAlternative frame)
 {
     byte[] bytes = null;
     using (BinaryStreamWriter w = new BinaryStreamWriter(new MemoryStream()))
     {
         w.Write(frame.FrameNumber);
         w.Write(frame.Skeletons.Length);
         foreach (SkeletonDataAlternative data in frame.Skeletons)
         {
             w.Write(SkeletonDataSerializer.Serialize(data));
         }
         bytes = ((MemoryStream)w.Stream).ToArray();
         w.Close();
     }
     return bytes;
 }
 public byte[] CreateHeader()
 {
     byte[] bytes = null;
     using(BinaryStreamWriter w = new BinaryStreamWriter(new MemoryStream())){
         w.Write((int)CommandType);
         w.Write(BodyLength);
         bytes = ((MemoryStream)w.Stream).ToArray();
         w.Close();
     }
     return bytes;
 }