Source File
default.go
Belonging Package
google.golang.org/protobuf/internal/encoding/defval
GoTag
)
func ( string, pref.Kind, pref.EnumValueDescriptors, Format) (pref.Value, pref.EnumValueDescriptor, error) {
switch {
case pref.BoolKind:
if == GoTag {
switch {
case "1":
return pref.ValueOfBool(true), nil, nil
case "0":
return pref.ValueOfBool(false), nil, nil
}
} else {
switch {
case "true":
return pref.ValueOfBool(true), nil, nil
case "false":
return pref.ValueOfBool(false), nil, nil
}
}
case pref.EnumKind:
:= .ByName(pref.Name())
if != nil {
return pref.ValueOfEnum(.Number()), , nil
}
}
case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind:
if , := strconv.ParseInt(, 10, 32); == nil {
return pref.ValueOfInt32(int32()), nil, nil
}
case pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind:
if , := strconv.ParseInt(, 10, 64); == nil {
return pref.ValueOfInt64(int64()), nil, nil
}
case pref.Uint32Kind, pref.Fixed32Kind:
if , := strconv.ParseUint(, 10, 32); == nil {
return pref.ValueOfUint32(uint32()), nil, nil
}
case pref.Uint64Kind, pref.Fixed64Kind:
if , := strconv.ParseUint(, 10, 64); == nil {
return pref.ValueOfUint64(uint64()), nil, nil
}
case pref.FloatKind, pref.DoubleKind:
var float64
var error
switch {
case "-inf":
= math.Inf(-1)
case "inf":
= math.Inf(+1)
case "nan":
= math.NaN()
default:
, = strconv.ParseFloat(, 64)
}
if == nil {
if == pref.FloatKind {
return pref.ValueOfFloat32(float32()), nil, nil
} else {
return pref.ValueOfFloat64(float64()), nil, nil
}
}
func ( pref.Value, pref.EnumValueDescriptor, pref.Kind, Format) (string, error) {
switch {
case pref.BoolKind:
if == GoTag {
if .Bool() {
return "1", nil
} else {
return "0", nil
}
} else {
if .Bool() {
return "true", nil
} else {
return "false", nil
}
}
case pref.EnumKind:
if == GoTag {
return strconv.FormatInt(int64(.Enum()), 10), nil
} else {
return string(.Name()), nil
}
case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind, pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind:
return strconv.FormatInt(.Int(), 10), nil
case pref.Uint32Kind, pref.Fixed32Kind, pref.Uint64Kind, pref.Fixed64Kind:
return strconv.FormatUint(.Uint(), 10), nil
case pref.FloatKind, pref.DoubleKind:
:= .Float()
switch {
case math.IsInf(, -1):
return "-inf", nil
case math.IsInf(, +1):
return "inf", nil
case math.IsNaN():
return "nan", nil
default:
if == pref.FloatKind {
return strconv.FormatFloat(, 'g', -1, 32), nil
} else {
return strconv.FormatFloat(, 'g', -1, 64), nil
}
}
func ( []byte) (string, bool) {
var []byte
for , := range {
switch {
case '\n':
= append(, `\n`...)
case '\r':
= append(, `\r`...)
case '\t':
= append(, `\t`...)
case '"':
= append(, `\"`...)
case '\'':
= append(, `\'`...)
case '\\':
= append(, `\\`...)
default:
if := >= 0x20 && <= 0x7e; {
= append(, )
} else {
= append(, fmt.Sprintf(`\%03o`, )...)
}
}
}
return string(), true
![]() |
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. |