IndexBlock.cs 1.4 KB

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