IndexBlock.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using TEAMModelOS.SDK.IP2Region;
  2. namespace TEAMModelOS.SDK
  3. {
  4. internal class IndexBlock
  5. {
  6. public const int LENGTH = 12;
  7. public long StartIP
  8. {
  9. get;
  10. private set;
  11. }
  12. public long EndIp
  13. {
  14. get;
  15. private set;
  16. }
  17. public uint DataPtr
  18. {
  19. get;
  20. private set;
  21. }
  22. public int DataLen
  23. {
  24. get;
  25. private set;
  26. }
  27. public IndexBlock(long startIp, long endIp, uint dataPtr, int dataLen)
  28. {
  29. StartIP = startIp;
  30. EndIp = endIp;
  31. DataPtr = dataPtr;
  32. DataLen = dataLen;
  33. }
  34. public byte[] GetBytes()
  35. {
  36. /*
  37. * +------------+-----------+-----------+
  38. * | 4bytes | 4bytes | 4bytes |
  39. * +------------+-----------+-----------+
  40. * start ip end ip data ptr + len
  41. */
  42. byte[] b = new byte[12];
  43. Utils.WriteIntLong(b, 0, StartIP); //start ip
  44. Utils.WriteIntLong(b, 4, EndIp); //end ip
  45. //write the data ptr and the length
  46. long mix = DataPtr | ((DataLen << 24) & 0xFF000000L);
  47. Utils.WriteIntLong(b, 8, mix);
  48. return b;
  49. }
  50. }
  51. }