PrettyPrintValueEncoded returns a string representation of the first decodable value in the provided byte slice, along with the remaining byte slice after decoding.
(b []byte)
| 3331 | // decodable value in the provided byte slice, along with the remaining byte |
| 3332 | // slice after decoding. |
| 3333 | func PrettyPrintValueEncoded(b []byte) ([]byte, string, error) { |
| 3334 | _, dataOffset, _, typ, err := DecodeValueTag(b) |
| 3335 | if err != nil { |
| 3336 | return b, "", err |
| 3337 | } |
| 3338 | switch typ { |
| 3339 | case Null: |
| 3340 | b = b[dataOffset:] |
| 3341 | return b, "NULL", nil |
| 3342 | case True: |
| 3343 | b = b[dataOffset:] |
| 3344 | return b, "true", nil |
| 3345 | case False: |
| 3346 | b = b[dataOffset:] |
| 3347 | return b, "false", nil |
| 3348 | case Int: |
| 3349 | var i int64 |
| 3350 | b, i, err = DecodeIntValue(b) |
| 3351 | if err != nil { |
| 3352 | return b, "", err |
| 3353 | } |
| 3354 | return b, strconv.FormatInt(i, 10), nil |
| 3355 | case Float: |
| 3356 | var f float64 |
| 3357 | b, f, err = DecodeFloatValue(b) |
| 3358 | if err != nil { |
| 3359 | return b, "", err |
| 3360 | } |
| 3361 | return b, strconv.FormatFloat(f, 'g', -1, 64), nil |
| 3362 | case Decimal: |
| 3363 | var d apd.Decimal |
| 3364 | b, d, err = DecodeDecimalValue(b) |
| 3365 | if err != nil { |
| 3366 | return b, "", err |
| 3367 | } |
| 3368 | return b, d.String(), nil |
| 3369 | case Bytes: |
| 3370 | var data []byte |
| 3371 | b, data, err = DecodeBytesValue(b) |
| 3372 | if err != nil { |
| 3373 | return b, "", err |
| 3374 | } |
| 3375 | if PrintableBytes(data) { |
| 3376 | return b, string(data), nil |
| 3377 | } |
| 3378 | // The following code extends hex.EncodeToString(). |
| 3379 | dst := make([]byte, 2+hex.EncodedLen(len(data))) |
| 3380 | dst[0], dst[1] = '0', 'x' |
| 3381 | hex.Encode(dst[2:], data) |
| 3382 | return b, string(dst), nil |
| 3383 | case Time: |
| 3384 | var t time.Time |
| 3385 | b, t, err = DecodeTimeValue(b) |
| 3386 | if err != nil { |
| 3387 | return b, "", err |
| 3388 | } |
| 3389 | return b, t.UTC().Format(time.RFC3339Nano), nil |
| 3390 | case TimeTZ: |
nothing calls this directly
no test coverage detected
searching dependent graphs…