public static SocketFileInfo FromBytes(byte[] bytes, ref int idx) { SocketFileInfo info = new SocketFileInfo(); info.Name = BytesConverter.ParseString(bytes, ref idx); info.Length = BytesConverter.ParseLong(bytes, ref idx); info.IsDirectory = BytesConverter.ParseBool(bytes, ref idx); return(info); }
public static byte[] ToBytes(SocketFileInfo info) { byte[] bytes = new byte[info.Name.Length + 4 + 8 + 1]; int idx = 0; bytes = BytesConverter.WriteString(bytes, info.Name, ref idx); bytes = BytesConverter.WriteLong(bytes, info.Length, ref idx); bytes = BytesConverter.WriteBool(bytes, info.IsDirectory, ref idx); return(bytes); }
public static int Compare(SocketFileInfo f1, SocketFileInfo f2) { if (f1.IsDirectory == f2.IsDirectory) { return(f1.Name.CompareTo(f2.Name)); } else { return(f1.IsDirectory ? -1 : 1); } }