id.go 1.2 KB

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