MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / PrettyPrintValueEncoded

Function PrettyPrintValueEncoded

pkg/util/encoding/encoding.go:2421–2516  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

2419// decodable value in the provided byte slice, along with the remaining byte
2420// slice after decoding.
2421func 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:

Callers

nothing calls this directly

Calls 15

StringMethod · 0.95
StringMethod · 0.95
StringMethod · 0.95
StringMethod · 0.95
DecodeValueTagFunction · 0.85
DecodeIntValueFunction · 0.85
DecodeFloatValueFunction · 0.85
DecodeDecimalValueFunction · 0.85
DecodeBytesValueFunction · 0.85
PrintableBytesFunction · 0.85
DecodeTimeValueFunction · 0.85
DecodeTimeTZValueFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…