当前位置: 首页>>代码示例>>Golang>>正文


Golang Value.GetInteger方法代码示例

本文整理汇总了Golang中github.com/cockroachdb/cockroach/proto.Value.GetInteger方法的典型用法代码示例。如果您正苦于以下问题:Golang Value.GetInteger方法的具体用法?Golang Value.GetInteger怎么用?Golang Value.GetInteger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cockroachdb/cockroach/proto.Value的用法示例。


在下文中一共展示了Value.GetInteger方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: mustGetInteger

// mustGetInteger decodes an int64 value from the bytes field of the receiver
// and panics if the bytes field is not 0 or 8 bytes in length.
func mustGetInteger(v *proto.Value) int64 {
	i, err := v.GetInteger()
	if err != nil {
		panic(err)
	}
	return i
}
开发者ID:mingpengxiao,项目名称:cockroach,代码行数:9,代码来源:client_raft_test.go

示例2: ConditionalPut

// ConditionalPut sets the value for a specified key only if
// the expected value matches. If not, the return value contains
// the actual value.
func (mvcc *MVCC) ConditionalPut(key Key, timestamp proto.Timestamp, value proto.Value, expValue *proto.Value, txn *proto.Transaction) (*proto.Value, error) {
	// Handle check for non-existence of key. In order to detect
	// the potential write intent by another concurrent transaction
	// with a newer timestamp, we need to use the max timestamp
	// while reading.
	existVal, err := mvcc.Get(key, proto.MaxTimestamp, txn)
	if err != nil {
		return nil, err
	}

	if expValue == nil && existVal != nil {
		return existVal, util.Errorf("key %q already exists", key)
	} else if expValue != nil {
		// Handle check for existence when there is no key.
		if existVal == nil {
			return nil, util.Errorf("key %q does not exist", key)
		} else if expValue.Bytes != nil && !bytes.Equal(expValue.Bytes, existVal.Bytes) {
			return existVal, util.Errorf("key %q does not match existing", key)
		} else if expValue.Integer != nil && (existVal.Integer == nil || expValue.GetInteger() != existVal.GetInteger()) {
			return existVal, util.Errorf("key %q does not match existing", key)
		}
	}

	return nil, mvcc.Put(key, timestamp, value, txn)
}
开发者ID:embark,项目名称:cockroach,代码行数:28,代码来源:mvcc.go

示例3: unmarshalValue

// unmarshalValue sets the destination reflect.Value contents from the source
// proto.Value, returning an error if the types are not compatible.
func unmarshalValue(src *proto.Value, dest reflect.Value) error {
	if src == nil {
		dest.Set(reflect.Zero(dest.Type()))
		return nil
	}

	switch d := dest.Addr().Interface().(type) {
	case *string:
		if src.Bytes != nil {
			*d = string(src.Bytes)
		} else {
			*d = ""
		}
		return nil

	case *[]byte:
		if src.Bytes != nil {
			*d = src.Bytes
		} else {
			*d = nil
		}
		return nil

	case *gogoproto.Message:
		panic("TODO(pmattis): unimplemented")

	case *encoding.BinaryUnmarshaler:
		return (*d).UnmarshalBinary(src.Bytes)
	}

	switch dest.Kind() {
	case reflect.Bool:
		i, err := src.GetInteger()
		if err != nil {
			return err
		}
		dest.SetBool(i != 0)
		return nil

	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		i, err := src.GetInteger()
		if err != nil {
			return err
		}
		dest.SetInt(i)
		return nil

	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
		i, err := src.GetInteger()
		if err != nil {
			return err
		}
		dest.SetUint(uint64(i))
		return nil

	case reflect.Float32, reflect.Float64:
		i, err := src.GetInteger()
		if err != nil {
			return err
		}
		dest.SetFloat(math.Float64frombits(uint64(i)))
		return nil

	case reflect.String:
		if src == nil || src.Bytes == nil {
			dest.SetString("")
			return nil
		}
		dest.SetString(string(src.Bytes))
		return nil
	}

	return fmt.Errorf("unable to unmarshal value: %s", dest.Type())
}
开发者ID:husttom,项目名称:cockroach,代码行数:76,代码来源:util.go


注:本文中的github.com/cockroachdb/cockroach/proto.Value.GetInteger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。