Mercurial > jhg
diff src/org/tmatesoft/hg/internal/Patch.java @ 534:243202f1bda5
Commit: refactor revision creation code from clone command to work separately, fit into existing library structure
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 04 Feb 2013 18:00:55 +0100 |
parents | e6f72c9829a6 |
children | 47dfa0ec7e35 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/Patch.java Wed Jan 30 15:48:36 2013 +0100 +++ b/src/org/tmatesoft/hg/internal/Patch.java Mon Feb 04 18:00:55 2013 +0100 @@ -154,7 +154,29 @@ ends.add(e); data.add(src); } - + + /** + * @return how many bytes the patch would take if written down using BundleFormat structure (start, end, length, data) + */ + public int serializedLength() { + int totalDataLen = 0; + for (byte[] d : data) { + totalDataLen += d.length; + } + int prefix = 3 * 4 * count(); // 3 integer fields per entry * sizeof(int) * number of entries + return prefix + totalDataLen; + } + + /*package-local*/ void serialize(DataSerializer out) throws IOException { + for (int i = 0, x = data.size(); i < x; i++) { + final int start = starts.get(i); + final int end = ends.get(i); + byte[] d = data.get(i); + out.writeInt(start, end, d.length); + out.write(d, 0, d.length); + } + } + private void add(Patch p, int i) { add(p.starts.get(i), p.ends.get(i), p.data.get(i)); } @@ -363,4 +385,15 @@ }; return r; } + + public class PatchDataSource implements DataSerializer.DataSource { + + public void serialize(DataSerializer out) throws IOException { + Patch.this.serialize(out); + } + + public int serializeLength() { + return Patch.this.serializedLength(); + } + } } \ No newline at end of file