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)
| 1367 | // use < > brackets to delimit the value. Otherwise it will use quotes |
| 1368 | // like JSON requires. |
| 1369 | func 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 | |
| 1393 | func MarshalToSizedBuffer(buf []byte, m proto.Message) ([]byte, error) { |
| 1394 | buf = buf[:0] |