Beispiel #1
0
// Read implements persistedIndex.
func (x *defQueryIndex) Read(r io.Reader) error {
	b, err := ioutil.ReadAll(r)
	if err != nil {
		return err
	}
	var mt mafsaTable
	err = binary.Unmarshal(b, &mt)
	x.mt = &mt
	if err == nil && len(x.mt.B) > 0 {
		x.mt.t, err = new(mafsa.Decoder).Decode(x.mt.B)
	}
	x.ready = (err == nil)
	return err
}
Beispiel #2
0
func TestUnitOffsets_BinaryEncoding(t *testing.T) {
	uofs := unitOffsets{Unit: 123, byteOffsets: []int64{1, 100, 1000, 200, 2}}
	b, err := binary.Marshal(&uofs)
	if err != nil {
		t.Fatal(err)
	}

	var uofs2 unitOffsets
	if err := binary.Unmarshal(b, &uofs2); err != nil {
		t.Fatal(err)
	}

	if !reflect.DeepEqual(uofs2, uofs) {
		t.Errorf("got %v, want %v", uofs2, uofs)
	}
}
Beispiel #3
0
// getByFile returns a list of source units that contain the file
// specified by the path. The path can also be a directory, in which
// case all source units that contain files underneath that directory
// are returned.
func (x *unitFilesIndex) getByPath(path string) ([]unit.ID2, bool, error) {
	vlog.Printf("unitFilesIndex.getByPath(%s)", path)
	c_unitFilesIndex_getByPath.increment()

	if x.phtable == nil {
		panic("phtable not built/read")
	}
	v := x.phtable.Get([]byte(path))
	if v == nil {
		return nil, false, nil
	}

	var us []unit.ID2
	if err := binary.Unmarshal(v, &us); err != nil {
		return nil, true, err
	}
	return us, true, nil
}
Beispiel #4
0
// getByFile returns a list of source units that contain the file
// specified by the path. The path can also be a directory, in which
// case all source units that contain files underneath that directory
// are returned.
func (x *defFilesIndex) getByPath(path string) (byteOffsets, bool, error) {
	vlog.Printf("defFilesIndex.getByPath(%s)", path)
	c_defFilesIndex_getByPath++

	if x.phtable == nil {
		panic("phtable not built/read")
	}
	v := x.phtable.Get([]byte(path))
	if v == nil {
		return nil, false, nil
	}

	var ofs byteOffsets
	if err := binary.Unmarshal(v, &ofs); err != nil {
		return nil, true, err
	}
	return ofs, true, nil
}
Beispiel #5
0
func (x *defRefsIndex) getByDef(def graph.RefDefKey) (byteOffsets, bool, error) {
	c_defRefsIndex_getByDef.increment()
	if x.phtable == nil {
		panic("phtable not built/read")
	}

	k, err := proto.Marshal(&def)
	if err != nil {
		return nil, false, err
	}

	v := x.phtable.Get(k)
	if v == nil {
		return nil, false, nil
	}

	var ofs byteOffsets
	if err := binary.Unmarshal(v, &ofs); err != nil {
		return nil, true, err
	}
	return ofs, true, nil
}
Beispiel #6
0
// getByFile returns a list of source units that contain refs to the
// specified def.
func (x *defRefUnitsIndex) getByDef(def graph.RefDefKey) ([]unit.ID2, bool, error) {
	vlog.Printf("defRefUnitsIndex.getByDef(%v)", def)
	c_defRefUnitsIndex_getByDef++

	k, err := proto.Marshal(&def)
	if err != nil {
		return nil, false, err
	}

	if x.phtable == nil {
		panic("phtable not built/read")
	}
	v := x.phtable.Get(k)
	if v == nil {
		return nil, false, nil
	}

	var us []unit.ID2
	if err := binary.Unmarshal(v, &us); err != nil {
		return nil, true, err
	}
	return us, true, nil
}
func (b BinarySerializer) Unmarshal(d []byte, o interface{}) error {
	return binary.Unmarshal(d, o)
}