C#C
C#3y ago
Kiel

More efficient or performant way of serializing permission nodes?

As a personal project, I'm designing a chat platform similar to Discord. Discord's permission system uses a simple bitfield, which is great as it's a small size and simply expressed, but terrible as I'm limited to n-1 possible permission values where n is the bit size of the field (I believe Discord internally uses a 64-bit integer, so 63 total possible permissions). I consider this bad for futureproofing and I would like to make sure I'm not painted into a corner and can have any arbitrary number of permission nodes/values. Anyone have any great ideas for alternative ways to format arbitrary permissions in a JSON-serializable-friendly way?

Right now my only genius idea is still using an enum, but making it essentially an array instead of a bitfield. This would greatly increase the size of the generated JSON most likely, but now I have a massively increased number of permission values. even using just a humble uint, I'd now have billions, which is more than enough for me.
IE:
"permissions": [
  "CreateX", // or 0
  "ModifyX", // 1
  "DeleteX", // 2
  "CreateY", // 3
  "ModifyY", // 4
  "DeleteY", // 5
  // etc
]

strings are probably slower, and obviously take up precious bandwidth at the scale of potentially hundreds or thousands of permissions arrays, so I may opt for the less-readable but identical int value format...but I'd like to know if anyone with more experience or knowledge has a brighter idea. Maybe something silly like multiple bitfields across multiple field names?
Was this page helpful?