Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.45 KB | None | 0 0
  1. private struct BytesReader
  2. {
  3.     ubyte[] arr;
  4.     size_t currIdx;
  5.  
  6.     this(ubyte[] a)
  7.     {
  8.         arr = a;
  9.     }
  10.  
  11.     T read(T)() const
  12.     {
  13.         const incremented = currIdx + sizeof(T);
  14.  
  15.         // Malformed array?
  16.         if(incremented > arr.length)
  17.             throw new AnswerException(ExceptionType.FATAL_ERROR, null);
  18.  
  19.         auto ret = cast(T*) &arr[currIdx];
  20.  
  21.         currIdx = incremented;
  22.  
  23.         return ret;
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement