// FindOffsetPosition attempts to find the provided offset position in the
// Segment.
167359
func (s *Segment) FindOffsetPosition(offset uint64) (int64, error) {
	if _, err := s.log.Seek(0, 0); err != nil {
		return 0, err
	}

	var position int64
	for {
		b := new(bytes.Buffer)
		// get offset and size
		_, err := io.CopyN(b, s.log, 8)
		if err != nil {
			return position, ErrOffsetNotFound
		}
		o := encoding.Uint64(b.Bytes()[offsetPos:8])

		_, err = io.CopyN(b, s.log, 4)
		if err != nil {
			return position, ErrOffsetNotFound
		}
		size := int64(encoding.Uint32(b.Bytes()[sizePos:12]))

		if offset == o {
			log.With("position", position).With("offset", o).Infoln("found offset position")
			return position, nil
		}
		position += size + logEntryHeaderLen

		// add 9 to size to include the timestamp and attribute
		_, err = s.log.Seek(size+9, 1)
		if err != nil {
			return 0, err
		}
	}
}
1041332
func (b *BootSectorCommon) DataOffset() uint32 {
	offset := uint32(b.RootDirOffset())
	offset += uint32(b.RootEntryCount * DirectoryEntrySize)
	return offset
}
106377
func (l Log) PutOffset(offset int64) {
	encoding.PutUint64(l[offsetPos:sizePos], uint64(offset))
}
658084
func (pc *KafkaPartitionConsumer) SetOffset(offset int64) {
	atomic.StoreInt64(&pc.offset, offset)
}
262304
func randomOffset(n int) int {
	if n == 0 {
		return 0
	}

	val, err := rand.Int(rand.Reader, big.NewInt(int64(n)))
	if err != nil {
		logrus.Errorf("Failed to get a random offset: %v", err)
		return 0
	}

	return int(val.Int64())
}
1187829
func parseTimeOffset(buff []byte, cursor *int, l int) (*time.Location, error) {

	if buff[*cursor] == 'Z' {
		*cursor++
		return time.UTC, nil
	}

	return parseNumericalTimeOffset(buff, cursor, l)
}
416121
func (a *ReadArgs) SetOffset(offset int) *ReadArgs {
	a.Offset = &offset
	return a
}
109890
func (p *PullRequestComment) GetPosition() int {
	if p == nil || p.Position == nil {
		return 0
	}
	return *p.Position
}
985080
func (query Query) Offset(offset int) Query {
	query.OffsetResult = offset
	return query
}
356361
func (stmt SelectStmt) Offset(offset int) SelectStmt {
	stmt.offset = offset
	return stmt
}
704171
func ResultOffset(offset uint32) func(Call) error {
	return func(hc Call) error {
		if c, ok := hc.(hasQueryOptions); ok {
			if offset > math.MaxInt32 {
				return errors.New("'ResultOffset' exceeds supported offset value")
			}
			c.setResultOffset(offset)
			return nil
		}
		return errors.New("'ResultOffset' option can only be used with Get or Scan request")
	}
}
249116
func (bldr *aeDataQueryBuilder) Offset(offset int) *aeDataQueryBuilder {
	bldr.q = bldr.q.Offset(offset)
	if bldr.plugin != nil {
		bldr.plugin.Offset(offset)
	}
	return bldr
}
1328678
func (b *BootSectorCommon) FATOffset(n int) int {
	offset := uint32(b.ReservedSectorCount * b.BytesPerSector)
	offset += b.SectorsPerFat * uint32(b.BytesPerSector) * uint32(n)
	return int(offset)
}
623101
func (c *CommitLog) OldestOffset() int64 {
	c.mu.RLock()
	defer c.mu.RUnlock()
	return c.segments[0].BaseOffset
}
263479
func (bldr *aeBackupInformationKindFilesQueryBuilder) Offset(offset int) *aeBackupInformationKindFilesQueryBuilder {
	bldr.q = bldr.q.Offset(offset)
	if bldr.plugin != nil {
		bldr.plugin.Offset(offset)
	}
	return bldr
}
434703
func (r *Reader) Offset() int64 {
	if b, ok := r.rdr.(*segmentBufReader); ok {
		return int64(b.off)
	}
	return r.total
}
153711
func pageOffset(pos, pageSize int64) int64 {
	rem := pos % pageSize
	if rem != 0 {
		return pos - rem
	}
	return pos
}