Example #1
0
// uintValue returns the unsigned integer value of a schema value or
// zero if the value is invalid (the null pointer). Panics if the value
// is not an unsigned integer.
func uintValue(v schema.Value) uint64 {
	if !v.IsValid() {
		return 0
	}
	switch v.Which() {
	case schema.Value_Which_uint8:
		return uint64(v.Uint8())
	case schema.Value_Which_uint16:
		return uint64(v.Uint16())
	case schema.Value_Which_uint32:
		return uint64(v.Uint32())
	case schema.Value_Which_uint64:
		return v.Uint64()
	}
	panic("unreachable")
}
Example #2
0
func isEmptyValue(v schema.Value) bool {
	if !v.IsValid() {
		return false
	}
	switch v.Which() {
	case schema.Value_Which_text:
		b, _ := v.TextBytes()
		return len(b) == 0
	case schema.Value_Which_data:
		b, _ := v.Data()
		return len(b) == 0
	case schema.Value_Which_list:
		p, _ := v.ListPtr()
		return p.List().Len() == 0
	default:
		return false
	}
}
Example #3
0
func isValueOfType(v schema.Value, t schema.Type) bool {
	// Ensure that the value is for the given type.  The schema ensures the union ordinals match.
	return !v.IsValid() || int(v.Which()) == int(t.Which())
}