// NewFrame popoulates a stack frame object from the program counter.
320561
func NewFrame(pc uintptr) Frame {
	frame := Frame{ProgramCounter: pc}
	if frame.Func() == nil {
		return frame
	}
	frame.Package, frame.Name = packageAndName(frame.Func())

	// pc -1 because the program counters we use are usually return addresses,
	// and we want to show the line that corresponds to the function call
	frame.File, frame.LineNumber = frame.Func().FileLine(pc - 1)
	frame.IsSystemPackage = isSystemPackage(frame.File, frame.Package)

	return frame
}
429049
func (f *Conn) ReadFrame() (frame []byte, err error) {
	size, err := f.readSize()
	if err != nil {
		return nil, err
	}

	buf := make([]byte, size)
	_, err = io.ReadFull(f.Conn, buf)
	if err != nil {
		return nil, err
	}

	return buf, nil
}
933504
func WriteFrame(w io.Writer, f Frame) error {
	err := WriteHeader(w, f.Header)
	if err != nil {
		return err
	}
	_, err = w.Write(f.Payload)
	return err
}
119077
func NewGetApplicationCacheForFrameArgs(frameID page.FrameID) *GetApplicationCacheForFrameArgs {
	args := new(GetApplicationCacheForFrameArgs)
	args.FrameID = frameID
	return args
}
1326183
func (buf *FloatBuffer) NumFrames() int {
	if buf == nil || buf.Format == nil {
		return 0
	}
	numChannels := buf.Format.NumChannels
	if numChannels == 0 {
		numChannels = 1
	}

	return len(buf.Data) / numChannels
}
208484
func (f *Frame) Drop() {
	if f.Len() == 0 {
		return
	}

	top := f.Len() - 1
	f.stack[top] = nil
	f.stack = f.stack[:top]
}
1300505
func (buf hybiFrameReaderFactory) NewFrameReader() (frame frameReader, err error) {
	hybiFrame := new(hybiFrameReader)
	frame = hybiFrame
	var header []byte
	var b byte
	// First byte. FIN/RSV1/RSV2/RSV3/OpCode(4bits)
	b, err = buf.ReadByte()
	if err != nil {
		return
	}
	header = append(header, b)
	hybiFrame.header.Fin = ((header[0] >> 7) & 1) != 0
	for i := 0; i < 3; i++ {
		j := uint(6 - i)
		hybiFrame.header.Rsv[i] = ((header[0] >> j) & 1) != 0
	}
	hybiFrame.header.OpCode = header[0] & 0x0f

	// Second byte. Mask/Payload len(7bits)
	b, err = buf.ReadByte()
	if err != nil {
		return
	}
	header = append(header, b)
	mask := (b & 0x80) != 0
	b &= 0x7f
	lengthFields := 0
	switch {
	case b <= 125: // Payload length 7bits.
		hybiFrame.header.Length = int64(b)
	case b == 126: // Payload length 7+16bits
		lengthFields = 2
	case b == 127: // Payload length 7+64bits
		lengthFields = 8
	}
	for i := 0; i < lengthFields; i++ {
		b, err = buf.ReadByte()
		if err != nil {
			return
		}
		header = append(header, b)
		hybiFrame.header.Length = hybiFrame.header.Length*256 + int64(b)
	}
	if mask {
		// Masking key. 4 bytes.
		for i := 0; i < 4; i++ {
			b, err = buf.ReadByte()
			if err != nil {
				return
			}
			header = append(header, b)
			hybiFrame.header.MaskingKey = append(hybiFrame.header.MaskingKey, b)
		}
	}
	hybiFrame.reader = io.LimitReader(buf.Reader, hybiFrame.header.Length)
	hybiFrame.header.data = bytes.NewBuffer(header)
	hybiFrame.length = len(header) + int(hybiFrame.header.Length)
	return
}
48242
func NewPropertiesFrame(frame [][]string) *Properties {
	p := Properties{}
	for i, line := range frame {
		if i == 0 {
			p.Header = line
		} else {
			p.AddRow(line)
		}
	}
	return &p
}
964961
func (err *Error) Stack() []byte {
	buf := bytes.Buffer{}

	for _, frame := range err.StackFrames() {
		buf.WriteString(frame.String())
	}

	return buf.Bytes()
}
291262
func NewWindow(options WindowOptions) *window.Window {
	return window.NewWindow(window.Options(options))
}
1213653
func (e *EvalError) Stack() []*Frame {
	var stack []*Frame
	for fr := e.Frame; fr != nil; fr = fr.parent {
		stack = append(stack, fr)
	}
	return stack
}
886017
func NewFrameItemFromRegionKey(key []byte) (frame *FrameItem, err error) {
	frame = &FrameItem{}
	frame.TableID, frame.IndexID, frame.IsRecord, err = tablecodec.DecodeKeyHead(key)
	if err == nil {
		if frame.IsRecord {
			_, frame.RecordID, err = tablecodec.DecodeRecordKey(key)
		} else {
			_, _, frame.IndexValues, err = tablecodec.DecodeIndexKey(key)
		}
		log.Warnf("decode region key %q fail: %v", key, err)
		// Ignore decode errors.
		err = nil
		return
	}
	if bytes.HasPrefix(key, tablecodec.TablePrefix()) {
		// If SplitTable is enabled, the key may be `t{id}`.
		if len(key) == tablecodec.TableSplitKeyLen {
			frame.TableID = tablecodec.DecodeTableID(key)
			return frame, nil
		}
		return nil, errors.Trace(err)
	}

	// key start with tablePrefix must be either record key or index key
	// That's means table's record key and index key are always together
	// in the continuous interval. And for key with prefix smaller than
	// tablePrefix, is smaller than all tables. While for key with prefix
	// bigger than tablePrefix, means is bigger than all tables.
	err = nil
	if bytes.Compare(key, tablecodec.TablePrefix()) < 0 {
		frame.TableID = math.MinInt64
		frame.IndexID = math.MinInt64
		frame.IsRecord = false
		return
	}
	// bigger than tablePrefix, means is bigger than all tables.
	frame.TableID = math.MaxInt64
	frame.TableID = math.MaxInt64
	frame.IsRecord = true
	return
}
1264543
func New(text string) error {
	if AddStack {
		text += "\n" + string(debug.Stack())
	}
	return &errorString{text}
}
288476
func NewReader(read io.Reader, opt ...Opt) framing.Reader {
	debug.Log("new frame reader")
	r := &reader{Scanner: bufio.NewScanner(read)}
	r.Split(func(data []byte, atEOF bool) (int, []byte, error) {
		// Scanner panics if we invoke Split after scanning has started,
		// use this proxy func as a work-around.
		return r.splitf(data, atEOF)
	})
	buf := make([]byte, 16*1024)
	r.Buffer(buf, 1<<22) // 1<<22 == max protobuf size
	r.splitf = r.splitSize
	// apply options
	for _, f := range opt {
		if f != nil {
			f(r)
		}
	}
	return r
}
614812
func (a *Ancestor) Stack(n int) ([]Stackframe, error) {
	if a.Unreadable != nil {
		return nil, a.Unreadable
	}
	pcsVar := a.pcsVar.clone()
	pcsVar.loadValue(LoadConfig{MaxArrayValues: n})
	if pcsVar.Unreadable != nil {
		return nil, pcsVar.Unreadable
	}
	r := make([]Stackframe, len(pcsVar.Children))
	for i := range pcsVar.Children {
		if pcsVar.Children[i].Unreadable != nil {
			r[i] = Stackframe{Err: pcsVar.Children[i].Unreadable}
			continue
		}
		if pcsVar.Children[i].Kind != reflect.Uint {
			return nil, fmt.Errorf("wrong type for pcs item %d: %v", i, pcsVar.Children[i].Kind)
		}
		pc, _ := constant.Int64Val(pcsVar.Children[i].Value)
		fn := a.pcsVar.bi.PCToFunc(uint64(pc))
		if fn == nil {
			loc := Location{PC: uint64(pc)}
			r[i] = Stackframe{Current: loc, Call: loc}
			continue
		}
		pc2 := uint64(pc)
		if pc2-1 >= fn.Entry {
			pc2--
		}
		f, ln := fn.cu.lineInfo.PCToLine(fn.Entry, pc2)
		loc := Location{PC: uint64(pc), File: f, Line: ln, Fn: fn}
		r[i] = Stackframe{Current: loc, Call: loc}
	}
	r[len(r)-1].Bottom = pcsVar.Len == int64(len(pcsVar.Children))
	return r, nil
}
1020074
func (it *stackIterator) Frame() Stackframe {
	it.frame.Bottom = it.atend
	return it.frame
}
1099936
func PopDownlinkFrame(p *redis.Pool, token uint32) (lorawan.EUI64, gw.DownlinkFrame, error) {
	var out gw.DownlinkFrame
	var devEUI lorawan.EUI64

	c := p.Get()
	defer c.Close()

	b, err := redis.Bytes(c.Do("LPOP", fmt.Sprintf(downlinkFramesKeyTempl, token)))
	if err != nil {
		if err == redis.ErrNil {
			return lorawan.EUI64{}, gw.DownlinkFrame{}, ErrDoesNotExist
		}
		return lorawan.EUI64{}, gw.DownlinkFrame{}, errors.Wrap(err, "lpop error")
	}
	err = proto.Unmarshal(b, &out)
	if err != nil {
		return lorawan.EUI64{}, gw.DownlinkFrame{}, errors.Wrap(err, "proto unmarshal error")
	}

	b, err = redis.Bytes(c.Do("GET", fmt.Sprintf(downlinkFramesDevEUIKeyTempl, token)))
	if err != nil {
		if err == redis.ErrNil {
			return lorawan.EUI64{}, gw.DownlinkFrame{}, ErrDoesNotExist
		}
		return lorawan.EUI64{}, gw.DownlinkFrame{}, errors.Wrap(err, "get error")
	}

	copy(devEUI[:], b)

	return devEUI, out, nil
}