MCPcopy Index your code
hub / github.com/coder/coder / EncodeAgentIDChunks

Function EncodeAgentIDChunks

coderd/agentapi/metadatabatcher/agentid_chunks.go:35–59  ·  view source on GitHub ↗

EncodeAgentIDChunks encodes agent IDs into chunks that fit within the PostgreSQL NOTIFY 8KB payload size limit. Each UUID is base64-encoded (without padding) and concatenated into a single byte slice per chunk.

(agentIDs []uuid.UUID)

Source from the content-addressed store, hash-verified

33// PostgreSQL NOTIFY 8KB payload size limit. Each UUID is base64-encoded
34// (without padding) and concatenated into a single byte slice per chunk.
35func EncodeAgentIDChunks(agentIDs []uuid.UUID) ([][]byte, error) {
36 chunks := make([][]byte, 0, (len(agentIDs)+maxAgentIDsPerChunk-1)/maxAgentIDsPerChunk)
37
38 for i := 0; i < len(agentIDs); i += maxAgentIDsPerChunk {
39 end := i + maxAgentIDsPerChunk
40 if end > len(agentIDs) {
41 end = len(agentIDs)
42 }
43
44 chunk := agentIDs[i:end]
45
46 // Build payload by base64-encoding each UUID (without padding) and
47 // concatenating them. This is UTF-8 safe for PostgreSQL NOTIFY.
48 payload := make([]byte, len(chunk)*UUIDBase64Size)
49 for i, agentID := range chunk {
50 err := EncodeAgentID(agentID, payload[i*UUIDBase64Size:(i+1)*UUIDBase64Size])
51 if err != nil {
52 return nil, err
53 }
54 }
55 chunks = append(chunks, payload)
56 }
57
58 return chunks, nil
59}

Callers 3

flushMethod · 0.85

Calls 1

EncodeAgentIDFunction · 0.85

Tested by 2