luat_rostr.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef LUAT_ROTSTR_H
  2. #define LUAT_ROTSTR_H
  3. #include "luat_base.h"
  4. #include "lstring.h"
  5. typedef struct luat_rostr
  6. {
  7. // 标准头部, 12字节
  8. char magic[4]; // 魔数,固定为"ROST"
  9. uint8_t version; // 版本信息,从version 1开始, 1字节
  10. uint8_t revert[3];// 预留空间
  11. // 以下是版本1的定义
  12. // 首先是短字符串的信息
  13. uint32_t short_str_count; // 短字符串的总数量
  14. uint32_t short_str_len; // 短字符串的总长度
  15. // 然后是长字符串的信息, 当前均为0, 后续再考虑
  16. uint32_t long_str_count; // 长字符串的总数量
  17. uint32_t long_str_len; // 长字符串的总长度
  18. // 每种长度的短字符串的字符串数量, 每个元素为uint16_t
  19. uint16_t short_str_len_count[40];
  20. // 后续是具体数据, 需要通过运算得到具体的区域,然后遍历里面的字符串
  21. }luat_rostr_t;
  22. typedef struct luat_rostr_short {
  23. TString str;
  24. char data[4]; // 注意, 实际长度为str.len + 1, 末尾必须是\0
  25. // 后面是字符串数据, 需要对其到4字节
  26. // 例如 存储 "abcd" 4个字符, 那么实际长度为 16字节(TString头部) + 4字节(实际数据) + 1字节(\0) = 24字节(21字节对齐到4字节)
  27. }luat_rostr_short_t;
  28. typedef struct luat_rostr_short8 {
  29. TString str;
  30. char data[8];
  31. }luat_rostr_short8_t;
  32. typedef struct luat_rostr_short12 {
  33. TString str;
  34. char data[12];
  35. }luat_rostr_short12_t;
  36. typedef struct luat_rostr_short16 {
  37. TString str;
  38. char data[16];
  39. }luat_rostr_short16_t;
  40. typedef struct luat_rostr_short20 {
  41. TString str;
  42. char data[20];
  43. }luat_rostr_short20_t;
  44. typedef struct luat_rostr_short24 {
  45. TString str;
  46. char data[24];
  47. }luat_rostr_short24_t;
  48. typedef struct luat_rostr_short44 {
  49. TString str;
  50. char data[44];
  51. }luat_rostr_short44_t;
  52. TString* luat_rostr_get(const char *val_str, size_t len);
  53. GCObject* luat_rostr_get_gc(const char *val_str, size_t len);
  54. #endif