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)
| 2419 | // decodable value in the provided byte slice, along with the remaining byte |
| 2420 | // slice after decoding. |
| 2421 | func PrettyPrintValueEncoded(b []byte) ([]byte, string, error) { |
| 2422 | _, dataOffset, _, typ, err := DecodeValueTag(b) |
| 2423 | if err != nil { |
| 2424 | return b, "", err |
| 2425 | } |
| 2426 | switch typ { |
| 2427 | case Null: |
| 2428 | b = b[dataOffset:] |
| 2429 | return b, "NULL", nil |
| 2430 | case True: |
| 2431 | b = b[dataOffset:] |
| 2432 | return b, "true", nil |
| 2433 | case False: |
| 2434 | b = b[dataOffset:] |
| 2435 | return b, "false", nil |
| 2436 | case Int: |
| 2437 | var i int64 |
| 2438 | b, i, err = DecodeIntValue(b) |
| 2439 | if err != nil { |
| 2440 | return b, "", err |
| 2441 | } |
| 2442 | return b, strconv.FormatInt(i, 10), nil |
| 2443 | case Float: |
| 2444 | var f float64 |
| 2445 | b, f, err = DecodeFloatValue(b) |
| 2446 | if err != nil { |
| 2447 | return b, "", err |
| 2448 | } |
| 2449 | return b, strconv.FormatFloat(f, 'g', -1, 64), nil |
| 2450 | case Decimal: |
| 2451 | var d apd.Decimal |
| 2452 | b, d, err = DecodeDecimalValue(b) |
| 2453 | if err != nil { |
| 2454 | return b, "", err |
| 2455 | } |
| 2456 | return b, d.String(), nil |
| 2457 | case Bytes: |
| 2458 | var data []byte |
| 2459 | b, data, err = DecodeBytesValue(b) |
| 2460 | if err != nil { |
| 2461 | return b, "", err |
| 2462 | } |
| 2463 | if PrintableBytes(data) { |
| 2464 | return b, string(data), nil |
| 2465 | } |
| 2466 | // The following code extends hex.EncodeToString(). |
| 2467 | dst := make([]byte, 2+hex.EncodedLen(len(data))) |
| 2468 | dst[0], dst[1] = '0', 'x' |
| 2469 | hex.Encode(dst[2:], data) |
| 2470 | return b, string(dst), nil |
| 2471 | case Time: |
| 2472 | var t time.Time |
| 2473 | b, t, err = DecodeTimeValue(b) |
| 2474 | if err != nil { |
| 2475 | return b, "", err |
| 2476 | } |
| 2477 | return b, t.UTC().Format(time.RFC3339Nano), nil |
| 2478 | case TimeTZ: |
nothing calls this directly
no test coverage detected
searching dependent graphs…