// NextPackageVariable moves the reader to the next debug entry that describes a package variable.
// Any TagVariable entry that is not inside a sub prgram entry and is marked external is considered a package variable.
170554
func (reader *Reader) NextPackageVariable() (*dwarf.Entry, error) {
	for entry, err := reader.Next(); entry != nil; entry, err = reader.Next() {
		if err != nil {
			return nil, err
		}

		if entry.Tag == dwarf.TagVariable {
			ext, ok := entry.Val(dwarf.AttrExternal).(bool)
			if ok && ext {
				return entry, nil
			}
		}

		// Ignore everything inside sub programs
		if entry.Tag == dwarf.TagSubprogram {
			reader.SkipChildren()
		}
	}

	// No more items
	return nil, nil
}
770331
func TabletTypeVar(p *topodatapb.TabletType, name string, defaultValue topodatapb.TabletType, usage string) {
	*p = defaultValue
	flag.Var((*TabletTypeFlag)(p), name, usage)
}
701539
func (s *Service) UpdateVariable(ctx context.Context, id platform.ID, update *platform.VariableUpdate) (*platform.Variable, error) {
	op := OpPrefix + platform.OpUpdateVariable
	variable, err := s.FindVariableByID(ctx, id)
	if err != nil {
		return nil, &platform.Error{
			Op:  op,
			Err: err,
		}
	}

	if err := update.Apply(variable); err != nil {
		return nil, &platform.Error{
			Op:  op,
			Err: err,
		}
	}

	if err := s.ReplaceVariable(ctx, variable); err != nil {
		return nil, &platform.Error{
			Op:  op,
			Err: err,
		}
	}

	return variable, nil
}
1366483
func (p *PUBCOMP) setVariableHeader() {
	// Append the Packet Identifier to the variable header.
	p.variableHeader = append(p.variableHeader, encodeUint16(p.PacketID)...)
}
326156
func (s *VariableService) UpdateVariable(ctx context.Context, id platform.ID, update *platform.VariableUpdate) (*platform.Variable, error) {
	u, err := newURL(s.Addr, variableIDPath(id))
	if err != nil {
		return nil, err
	}

	octets, err := json.Marshal(update)
	if err != nil {
		return nil, err
	}

	req, err := http.NewRequest("PATCH", u.String(), bytes.NewReader(octets))
	if err != nil {
		return nil, err
	}

	req.Header.Set("Content-Type", "application/json")
	SetToken(s.Token, req)

	hc := newClient(u.Scheme, s.InsecureSkipVerify)

	resp, err := hc.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	if err := CheckError(resp); err != nil {
		return nil, err
	}

	var m platform.Variable
	if err := json.NewDecoder(resp.Body).Decode(&m); err != nil {
		return nil, err
	}

	return &m, nil
}
1133396
func (d *Debugger) SetVariableInScope(scope api.EvalScope, symbol, value string) error {
	d.processMutex.Lock()
	defer d.processMutex.Unlock()

	s, err := proc.ConvertEvalScope(d.target, scope.GoroutineID, scope.Frame, scope.DeferredCall)
	if err != nil {
		return err
	}
	return s.SetVariable(symbol, value)
}
301632
func (scope *EvalScope) LocalVariables(cfg LoadConfig) ([]*Variable, error) {
	vars, err := scope.Locals()
	if err != nil {
		return nil, err
	}
	vars = filterVariables(vars, func(v *Variable) bool {
		return (v.Flags & (VariableArgument | VariableReturnArgument)) == 0
	})
	cfg.MaxMapBuckets = maxMapBucketsFactor * cfg.MaxArrayValues
	loadValues(vars, cfg)
	return vars, nil
}
770439
func NewVariableHandler(b *VariableBackend) *VariableHandler {
	h := &VariableHandler{
		Router: NewRouter(),
		Logger: b.Logger,

		VariableService: b.VariableService,
		LabelService:    b.LabelService,
	}

	entityPath := fmt.Sprintf("%s/:id", variablePath)
	entityLabelsPath := fmt.Sprintf("%s/labels", entityPath)
	entityLabelsIDPath := fmt.Sprintf("%s/:lid", entityLabelsPath)

	h.HandlerFunc("GET", variablePath, h.handleGetVariables)
	h.HandlerFunc("POST", variablePath, h.handlePostVariable)
	h.HandlerFunc("GET", entityPath, h.handleGetVariable)
	h.HandlerFunc("PATCH", entityPath, h.handlePatchVariable)
	h.HandlerFunc("PUT", entityPath, h.handlePutVariable)
	h.HandlerFunc("DELETE", entityPath, h.handleDeleteVariable)

	labelBackend := &LabelBackend{
		Logger:       b.Logger.With(zap.String("handler", "label")),
		LabelService: b.LabelService,
		ResourceType: platform.DashboardsResourceType,
	}
	h.HandlerFunc("GET", entityLabelsPath, newGetLabelsHandler(labelBackend))
	h.HandlerFunc("POST", entityLabelsPath, newPostLabelHandler(labelBackend))
	h.HandlerFunc("DELETE", entityLabelsIDPath, newDeleteLabelHandler(labelBackend))

	return h
}
1095763
func (m ModuleInstance) InputVariable(name string) AbsInputVariableInstance {
	return AbsInputVariableInstance{
		Module: m,
		Variable: InputVariable{
			Name: name,
		},
	}
}
1089905
func (rule *Rule) AddVariable(variable *Variable) {
	for key, existingVariable := range rule.Variables {
		if existingVariable.Name == variable.Name {
			rule.Variables[key] = variable

			return
		}
	}

	rule.Variables = append(rule.Variables, variable)
}
400605
func readVariableValueLengthFromReader(r io.Reader, reverse bool) (ValueLength, []byte, error) {
	if reverse {
		return 0, nil, WithStack(fmt.Errorf("reverse is not supported"))
	}
	length := ValueLength(0)
	p := uint(0)
	buf := make([]byte, 1)
	bytes := make([]byte, 0, 8)
	for {
		if n, err := r.Read(buf); n != 1 {
			if err != nil {
				return 0, nil, WithStack(err)
			} else {
				return 0, nil, WithStack(fmt.Errorf("failed to read 1 byte"))
			}
		}
		bytes = append(bytes, buf[0])
		v := ValueLength(buf[0])
		length += (v & 0x7f) << p
		p += 7
		if v&0x80 == 0 {
			break
		}
	}
	return length, bytes, nil
}
665547
func (p *parserMixin) BytesVar(target *units.Base2Bytes) {
	p.SetValue(newBytesValue(target))
}
1231849
func (reader *Reader) NextMemberVariable() (*dwarf.Entry, error) {
	for entry, err := reader.Next(); entry != nil; entry, err = reader.Next() {
		if err != nil {
			return nil, err
		}

		// All member variables will be at the same depth
		reader.SkipChildren()

		// End of the current depth
		if entry.Tag == 0 {
			break
		}

		if entry.Tag == dwarf.TagMember {
			return entry, nil
		}
	}

	// No more items
	return nil, nil
}
323860
func getVariable(image *api.Image, name string) string {
	envName := name + "="
	for _, v := range image.Config.Env {
		if strings.HasPrefix(v, envName) {
			return strings.TrimSpace(v[len(envName):])
		}
	}

	return ""
}
1359812
func ReadVariable(id string) (StaySetVariable, error) {
	monitor.RLock()
	defer monitor.RUnlock()
	return monitor.backend().ReadVariable(id)
}
845373
func (d *Debugger) LocalVariables(scope api.EvalScope, cfg proc.LoadConfig) ([]api.Variable, error) {
	d.processMutex.Lock()
	defer d.processMutex.Unlock()

	s, err := proc.ConvertEvalScope(d.target, scope.GoroutineID, scope.Frame, scope.DeferredCall)
	if err != nil {
		return nil, err
	}
	pv, err := s.LocalVariables(cfg)
	if err != nil {
		return nil, err
	}
	return convertVars(pv), err
}
686351
func (c *Client) DeleteVariable(ctx context.Context, id platform.ID) error {
	op := getOp(platform.OpDeleteVariable)
	return c.db.Update(func(tx *bolt.Tx) error {
		m, pe := c.findVariableByID(ctx, tx, id)
		if pe != nil {
			return &platform.Error{
				Op:  op,
				Err: pe,
			}
		}

		encID, err := id.Encode()
		if err != nil {
			return &platform.Error{
				Op:  op,
				Err: err,
			}
		}

		if err := c.removeVariableOrgsIndex(ctx, tx, m); err != nil {
			return &platform.Error{
				Op:  op,
				Err: err,
			}
		}

		if err := tx.Bucket(variableBucket).Delete(encID); err != nil {
			return &platform.Error{
				Op:  op,
				Err: err,
			}
		}

		return nil
	})
}