Beispiel #1
0
func TestMerge(t *testing.T) {
	for _, m := range mergeTests {
		got := proto.Clone(m.dst)
		proto.Merge(got, m.src)
		if !proto.Equal(got, m.want) {
			t.Errorf("Merge(%v, %v)\n got %v\nwant %v\n", m.dst, m.src, got, m.want)
		}
	}
}
Beispiel #2
0
//Put File information into Packet, reusing existing file hash if possible
func (p *Packet) MergeFile(f *File) {
	files := p.GetFiles()
	haveFile := false
	for _, v := range files {
		if f.GetId().Equal(*(v.GetId())) {
			proto.Merge(v, f) // todo: a better merge
			haveFile = true
			break
		}
	}
	if !haveFile {
		files = append(files, f)
		p.Files = files
	}
}