Exemplo n.º 1
0
func EncodingEntry(e pb.Entry) ([]byte, error) {
	data, err := e.Marshal()
	if err != nil {
		return nil, err
	}
	size := len(data)
	ret := make([]byte, 4)
	binary.BigEndian.PutUint32(ret, uint32(size))
	ret = append(ret, data...)
	return ret, nil
}
Exemplo n.º 2
0
func (fs *FragmentStorage) Entry(i uint64) (pb.Entry, error) {
	fs.fents.Seek(int64(i*SegmentSize), 0)
	lengthByte := make([]byte, 4)
	entry := pb.Entry{}
	n, err := fs.fents.Read(lengthByte)
	if err != nil || n != 4 {
		if err != nil {
			return entry, err
		}
		return entry, ErrEntryLength
	}
	len := binary.BigEndian.Uint32(lengthByte)
	payload := make([]byte, int(len))
	n, err = fs.fents.Read(payload)
	if err != nil || n != int(len) {
		if err != nil {
			return entry, err
		}
		return entry, ErrEntryContentShort
	}
	return entry, entry.Unmarshal(payload)
}