Source File
value_union.go
Belonging Package
google.golang.org/protobuf/reflect/protoreflect
package protoreflect
import (
)
func ( interface{}) Value {
switch v := .(type) {
case nil:
return Value{}
case bool:
return ValueOfBool()
case int32:
return ValueOfInt32()
case int64:
return ValueOfInt64()
case uint32:
return ValueOfUint32()
case uint64:
return ValueOfUint64()
case float32:
return ValueOfFloat32()
case float64:
return ValueOfFloat64()
case string:
return ValueOfString()
case []byte:
return ValueOfBytes()
case EnumNumber:
return ValueOfEnum()
case Message, List, Map:
return valueOfIface()
case ProtoMessage:
panic(fmt.Sprintf("invalid proto.Message(%T) type, expected a protoreflect.Message type", ))
default:
panic(fmt.Sprintf("invalid type: %T", ))
}
}
func ( float32) Value {
return Value{typ: float32Type, num: uint64(math.Float64bits(float64()))}
}
func ( float64) Value {
return Value{typ: float64Type, num: uint64(math.Float64bits(float64()))}
}
func ( string) Value {
return valueOfString()
}
func ( []byte) Value {
return valueOfBytes([:len():len()])
}
func ( Message) Value {
return valueOfIface()
}
func ( List) Value {
return valueOfIface()
}
func ( Map) Value {
return valueOfIface()
}
func ( Value) () interface{} {
switch .typ {
case nilType:
return nil
case boolType:
return .Bool()
case int32Type:
return int32(.Int())
case int64Type:
return int64(.Int())
case uint32Type:
return uint32(.Uint())
case uint64Type:
return uint64(.Uint())
case float32Type:
return float32(.Float())
case float64Type:
return float64(.Float())
case stringType:
return .String()
case bytesType:
return .Bytes()
case enumType:
return .Enum()
default:
return .getIface()
}
}
func ( Value) () string {
switch .typ {
case nilType:
return "nil"
case boolType:
return "bool"
case int32Type:
return "int32"
case int64Type:
return "int64"
case uint32Type:
return "uint32"
case uint64Type:
return "uint64"
case float32Type:
return "float32"
case float64Type:
return "float64"
case stringType:
return "string"
case bytesType:
return "bytes"
case enumType:
return "enum"
default:
switch v := .getIface().(type) {
case Message:
return "message"
case List:
return "list"
case Map:
return "map"
default:
return fmt.Sprintf("<unknown: %T>", )
}
}
}
func ( Value) ( string) string {
return fmt.Sprintf("type mismatch: cannot convert %v to %s", .typeName(), )
}
func ( Value) () uint64 {
switch .typ {
case uint32Type, uint64Type:
return uint64(.num)
default:
panic(.panicMessage("uint"))
}
}
func ( Value) () float64 {
switch .typ {
case float32Type, float64Type:
return math.Float64frombits(uint64(.num))
default:
panic(.panicMessage("float"))
}
}
func ( Value) () EnumNumber {
switch .typ {
case enumType:
return EnumNumber(.num)
default:
panic(.panicMessage("enum"))
}
}
func ( Value) () MapKey {
switch .typ {
case boolType, int32Type, int64Type, uint32Type, uint64Type, stringType:
return MapKey()
default:
panic(.panicMessage("map key"))
}
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |