MCPcopy
hub / github.com/dgraph-io/dgraph / ToHex

Function ToHex

x/x.go:1369–1391  ·  view source on GitHub ↗

ToHex converts a uint64 to a hex byte array. If rdf is true it will use < > brackets to delimit the value. Otherwise it will use quotes like JSON requires.

(i uint64, rdf bool)

Source from the content-addressed store, hash-verified

1367// use < > brackets to delimit the value. Otherwise it will use quotes
1368// like JSON requires.
1369func ToHex(i uint64, rdf bool) []byte {
1370 var b [16]byte
1371 tmp := strconv.AppendUint(b[:0], i, 16)
1372
1373 out := make([]byte, len(tmp)+3+1)
1374 if rdf {
1375 out[0] = '<'
1376 } else {
1377 out[0] = '"'
1378 }
1379
1380 out[1] = '0'
1381 out[2] = 'x'
1382 n := copy(out[3:], tmp)
1383
1384 if rdf {
1385 out[3+n] = '>'
1386 } else {
1387 out[3+n] = '"'
1388 }
1389
1390 return out
1391}
1392
1393func MarshalToSizedBuffer(buf []byte, m proto.Message) ([]byte, error) {
1394 buf = buf[:0]

Callers 4

getScalarValMethod · 0.92
writeRDFMethod · 0.92
rdfForUIDListMethod · 0.92
TestToHexFunction · 0.85

Calls 1

copyFunction · 0.85

Tested by 1

TestToHexFunction · 0.68