+ len = (tr->comment) ? strlen(tr->comment)+1 : 0;
+ g_byte_array_append(b, (guint8 *)&len, sizeof(len));
+ if (tr->comment) g_byte_array_append(b, (guint8 *)tr->comment, len);
+
+ *data = b->data;
+ *datalen = b->len;
+ g_byte_array_free(b, FALSE);
+}
+
+VikTrack *vik_track_unmarshall (guint8 *data, guint datalen)
+{
+ guint len;
+ VikTrack *new_tr = vik_track_new();
+ VikTrackpoint *new_tp;
+ guint ntp;
+ gint i;
+
+ /* only the visibility is needed */
+ new_tr->visible = ((VikTrack *)data)->visible;
+ data += sizeof(*new_tr);
+
+ ntp = *(guint *)data;
+ data += sizeof(ntp);
+
+ for (i=0; i<ntp; i++) {
+ new_tp = vik_trackpoint_new();
+ memcpy(new_tp, data, sizeof(*new_tp));
+ data += sizeof(*new_tp);
+ new_tr->trackpoints = g_list_append(new_tr->trackpoints, new_tp);