public static byte[] SerializeToBytes(TreeFile instance)
 {
     using (MemoryStream ms = new MemoryStream()) {
         Serialize(ms, instance);
         return(ms.ToArray());
     }
 }
Exemple #2
0
        public static ChunkHash GenerateChunk(string path, Repo repo)
        {
            string fullPath = Path.GetFullPath (path);
            TreeChunk tree = new TreeChunk ();

            //Subdirectories
            string[] dirs = Directory.GetDirectories (fullPath);
            foreach (string d in dirs) {
                TreeFile df = new TreeFile ();
                df.Name = Path.GetFileName (d);
                df.TreeChunkHash = TreeChunk.GenerateChunk (d, repo).bytes;
                tree.Directories.Add (df);
            }

            //Files
            string[] files = Directory.GetFiles (fullPath);
            foreach (string f in files) {
                TreeFile ff = new TreeFile ();
                ff.Name = Path.GetFileName (f);
                ff.TreeChunkHash = StreamChunk.GenerateChunk (f, repo).bytes;
                tree.Files.Add (ff);
            }

            Chunk treeChunk = new Chunk (TreeChunk.SerializeToBytes (tree));
            ChunkHash ch = repo.WriteChunk (treeChunk);

            return ch;
        }
        public static TreeFile Deserialize(Stream stream)
        {
            TreeFile instance = new TreeFile();

            Deserialize(stream, instance);
            return(instance);
        }
Exemple #4
0
        public static ChunkHash GenerateChunk(string path, Repo repo)
        {
            string    fullPath = Path.GetFullPath(path);
            TreeChunk tree     = new TreeChunk();

            //Subdirectories
            string[] dirs = Directory.GetDirectories(fullPath);
            foreach (string d in dirs)
            {
                TreeFile df = new TreeFile();
                df.Name          = Path.GetFileName(d);
                df.TreeChunkHash = TreeChunk.GenerateChunk(d, repo).bytes;
                tree.Directories.Add(df);
            }

            //Files
            string[] files = Directory.GetFiles(fullPath);
            foreach (string f in files)
            {
                TreeFile ff = new TreeFile();
                ff.Name          = Path.GetFileName(f);
                ff.TreeChunkHash = StreamChunk.GenerateChunk(f, repo).bytes;
                tree.Files.Add(ff);
            }

            Chunk     treeChunk = new Chunk(TreeChunk.SerializeToBytes(tree));
            ChunkHash ch        = repo.WriteChunk(treeChunk);

            return(ch);
        }
 public static void Serialize(Stream stream, TreeFile instance)
 {
     if (instance.Name == null)
     {
         throw new ArgumentNullException("Name", "Required by proto specification.");
     }
     ProtocolParser.WriteKey(stream, new ProtocolBuffers.Key(1, Wire.LengthDelimited));
     ProtocolParser.WriteString(stream, instance.Name);
     if (instance.TreeChunkHash == null)
     {
         throw new ArgumentNullException("TreeChunkHash", "Required by proto specification.");
     }
     ProtocolParser.WriteKey(stream, new ProtocolBuffers.Key(2, Wire.LengthDelimited));
     ProtocolParser.WriteBytes(stream, instance.TreeChunkHash);
 }