+#define WRITE_N(_buffer, _offset, _len, _dataptr) do { \
+ if(_buffer) memcpy((char*)_buffer + _offset, _dataptr, _len);\
+ _offset += _len; \
+} while(0)
+
+#define WRITE_8(_buffer, _offset, _val) do {\
+ uint8_t v = (_val);\
+ WRITE_N(_buffer, _offset, 1, &v);\
+} while(0)
+#define WRITE_16(_buffer, _offset, _val) do {\
+ uint16_t v = (_val);\
+ WRITE_N(_buffer, _offset, 2, &v);\
+} while(0)
+#define WRITE_32(_buffer, _offset, _val) do {\
+ uint32_t v = (_val);\
+ WRITE_N(_buffer, _offset, 4, &v);\
+} while(0)
+#define WRITE_64(_buffer, _offset, _val) do {\
+ uint64_t v = (_val);\
+ WRITE_N(_buffer, _offset, 8, &v);\
+} while(0)
+#define WRITE_REAL(_buffer, _offset, _val) do {\
+ double v = (_val);\
+ WRITE_N(_buffer, _offset, sizeof(double), &v);\
+} while(0)
+
+#define WRITE_STR(_buffer, _offset, _string) do {\
+ int len = strlen(_string);\
+ WRITE_16(_buffer, _offset, len);\
+ WRITE_N(_buffer, _offset, len, _string);\
+ if((_offset & 1) == 1)WRITE_8(_buffer, _offset, 0); \
+ if((_offset & 3) == 2)WRITE_16(_buffer, _offset, 0); \
+} while(0)
+#define WRITE_NODELIST(_buffer, _offset, _listHead) do {\
+ tAST_Node *node; \
+ size_t ptr = -1;\
+ for(node=(_listHead); node; node = node->NextSibling) {\
+ ptr = _offset;\
+ _offset += AST_WriteNode(_buffer, _offset, node); \
+ WRITE_32(_buffer, ptr, ptr); \
+ } \
+ if(ptr != -1){ptr -= 4; WRITE_32(_buffer, ptr, 0);} \
+} while(0)
+