id.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package modelse
  2. import "strconv"
  3. const (
  4. HASH_SIZE_8 = 8
  5. HASH_SIZE_16 = 16
  6. )
  7. // apm_span_context
  8. type ApmSpanContextT struct {
  9. type_from [1]byte
  10. sample [1]byte
  11. host_id [8]byte
  12. app_id [8]byte
  13. instance_id [8]byte
  14. trace_id [16]byte
  15. assumed_app_id [8]byte
  16. span_id [8]byte
  17. }
  18. type HashByte [HASH_SIZE_8]byte
  19. type HashByte16 [HASH_SIZE_16]byte
  20. type INT_HASH_ID struct {
  21. IntVal int64
  22. HashtVal HashByte
  23. }
  24. type ID_STRING string
  25. func (id ID_STRING) ToString() string {
  26. return string(id)
  27. }
  28. func (id ID_STRING) ToInt64() (int64, error) {
  29. intID, err := strconv.ParseInt(id.ToString(), 10, 64)
  30. if err != nil {
  31. return 0, err
  32. }
  33. return intID, nil
  34. }
  35. func (id ID_STRING) ToHashByte() HashByte {
  36. var charArray HashByte
  37. hexStringToBPFBytes(id.ToString(), &charArray)
  38. return charArray
  39. }
  40. func hexStringToBPFBytes(str string, out *HashByte) {
  41. for i := 0; i < len(str)/2; i++ {
  42. ch0 := str[2*i]
  43. ch1 := str[2*i+1]
  44. nib0 := (ch0 & 0x0F) + (ch0 >> 6) | ((ch0 >> 3) & 0x08)
  45. nib1 := (ch1 & 0x0F) + (ch1 >> 6) | ((ch1 >> 3) & 0x08)
  46. (*out)[i] = (nib0 << 4) | nib1
  47. }
  48. }