MCPcopy Create free account
hub / github.com/PostHog/duckgres / encodeUUID

Function encodeUUID

server/types.go:529–553  ·  view source on GitHub ↗

encodeUUID encodes a UUID value as 16 raw bytes (PostgreSQL binary UUID format). DuckDB Go driver returns UUID as []byte (16 bytes).

(v interface{})

Source from the content-addressed store, hash-verified

527// encodeUUID encodes a UUID value as 16 raw bytes (PostgreSQL binary UUID format).
528// DuckDB Go driver returns UUID as []byte (16 bytes).
529func encodeUUID(v interface{}) []byte {
530 switch val := v.(type) {
531 case []byte:
532 if len(val) == 16 {
533 return val
534 }
535 return nil
536 case string:
537 s := strings.ReplaceAll(val, "-", "")
538 if len(s) != 32 {
539 return nil
540 }
541 data, err := hex.DecodeString(s)
542 if err != nil {
543 return nil
544 }
545 return data
546 default:
547 // Try Stringer interface (e.g., duckdb.UUID)
548 if stringer, ok := v.(fmt.Stringer); ok {
549 return encodeUUID(stringer.String())
550 }
551 return nil
552 }
553}
554
555// decodeUUID decodes 16 raw bytes into a UUID string "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".
556func decodeUUID(data []byte) (string, error) {

Callers 2

TestEncodeDecodeUUIDFunction · 0.85
encodeBinaryFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by 1

TestEncodeDecodeUUIDFunction · 0.68