MCPcopy Create free account
hub / github.com/PasarGuard/node / BuildUsersFromChunks

Function BuildUsersFromChunks

controller/users_chunk.go:10–29  ·  view source on GitHub ↗

BuildUsersFromChunks orders chunked user payloads by their index and returns a single slice.

(chunks map[uint64][]*common.User, lastIndex uint64, sawLast bool)

Source from the content-addressed store, hash-verified

8
9// BuildUsersFromChunks orders chunked user payloads by their index and returns a single slice.
10func BuildUsersFromChunks(chunks map[uint64][]*common.User, lastIndex uint64, sawLast bool) ([]*common.User, error) {
11 if !sawLast {
12 return nil, fmt.Errorf("missing final chunk indicator")
13 }
14
15 users := make([]*common.User, 0)
16 for i := uint64(0); i <= lastIndex; i++ {
17 chunkUsers, ok := chunks[i]
18 if !ok {
19 return nil, fmt.Errorf("missing chunk index %d", i)
20 }
21 users = append(users, chunkUsers...)
22 }
23
24 if len(users) == 0 {
25 return nil, fmt.Errorf("no users received")
26 }
27
28 return users, nil
29}

Calls

no outgoing calls