in memstore/common/data_value.go [258:347]
func (v1 DataValue) ConvertToHumanReadable(dataType DataType) interface{} {
if !v1.Valid {
return nil
}
if v1.IsBool {
return v1.BoolVal
}
switch dataType {
case Int8:
return *(*int8)(v1.OtherVal)
case Uint8, SmallEnum:
return *(*uint8)(v1.OtherVal)
case Int16:
return *(*int16)(v1.OtherVal)
case Uint16, BigEnum:
return *(*uint16)(v1.OtherVal)
case Int32:
return *(*int32)(v1.OtherVal)
case Uint32:
return *(*uint32)(v1.OtherVal)
case Int64:
return *(*int64)(v1.OtherVal)
case Float32:
return *(*float32)(v1.OtherVal)
case UUID:
bys := *(*[16]byte)(v1.OtherVal)
uuidStr := hex.EncodeToString(bys[:])
if len(uuidStr) == 32 {
return fmt.Sprintf("%s-%s-%s-%s-%s",
uuidStr[:8],
uuidStr[8:12],
uuidStr[12:16],
uuidStr[16:20],
uuidStr[20:])
}
case GeoPoint:
latLngs := *(*[2]float32)(v1.OtherVal)
// in string format, lng goes first and lat second
return fmt.Sprintf("Point(%.4f,%.4f)", latLngs[1], latLngs[0])
case GeoShape:
shape, ok := (v1.GoVal).(*GeoShapeGo)
if ok {
polygons := make([]string, len(shape.Polygons))
for i, points := range shape.Polygons {
pointsStrs := make([]string, len(points))
for j, point := range points {
// in string format, lng goes first and lat second
// https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry
pointsStrs[j] = fmt.Sprintf("%.4f+%.4f", point[1], point[0])
}
polygons[i] = fmt.Sprintf("(%s)", strings.Join(pointsStrs, ","))
}
return fmt.Sprintf("Polygon(%s)", strings.Join(polygons, ","))
}
default:
if IsArrayType(dataType) {
reader := NewArrayValueReader(dataType, v1.OtherVal)
num := reader.GetLength()
arrVal := make([]interface{}, num)
for i := 0; i < int(num); i++ {
if reader.IsItemValid(i) {
var dataValue DataValue
if reader.itemType == Bool {
dataValue = DataValue{
DataType: reader.itemType,
Valid: true,
IsBool: true,
BoolVal: reader.GetBool(i),
}
} else {
dataValue = DataValue{
DataType: reader.itemType,
Valid: true,
OtherVal: reader.Get(i),
}
}
arrVal[i] = dataValue.ConvertToHumanReadable(reader.itemType)
} else {
arrVal[i] = nil
}
}
bytes, _ := json.Marshal(arrVal)
return string(bytes)
}
}
return nil
}