MCPcopy Create free account
hub / github.com/cli/cli / EncodeNodeID

Function EncodeNodeID

api/node_id.go:20–38  ·  view source on GitHub ↗

EncodeNodeID encodes templateIndex and ids as a base64 MessagePack array of compact integers, the payload of a GraphQL node ID such as "PR_ ". templateIndex is an internal GitHub node ID detail. Clients should treat node IDs as opaque rather than construct them. This helper was introduced t

(templateIndex int64, ids ...int64)

Source from the content-addressed store, hash-verified

18// templateIndex and all IDs must be non-negative. Callers must supply fewer
19// than 15 IDs.
20func EncodeNodeID(templateIndex int64, ids ...int64) string {
21 parts := append([]int64{templateIndex}, ids...)
22 b := []byte{0x90 | byte(len(parts))}
23 for _, id := range parts {
24 switch {
25 case id < 0x80:
26 b = append(b, byte(id))
27 case id <= math.MaxUint8:
28 b = append(b, 0xcc, byte(id))
29 case id <= math.MaxUint16:
30 b = binary.BigEndian.AppendUint16(append(b, 0xcd), uint16(id))
31 case id <= math.MaxUint32:
32 b = binary.BigEndian.AppendUint32(append(b, 0xce), uint32(id))
33 default:
34 b = binary.BigEndian.AppendUint64(append(b, 0xcf), uint64(id))
35 }
36 }
37 return base64.RawURLEncoding.EncodeToString(b)
38}

Callers 4

ResolveCommentNodeIDMethod · 0.92
generateUserNodeIDFunction · 0.92
TestEncodeNodeIDFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestEncodeNodeIDFunction · 0.68