23 #ifndef WINPR_UTILS_STREAM_H
24 #define WINPR_UTILS_STREAM_H
26 #include <winpr/winpr.h>
27 #include <winpr/wtypes.h>
28 #include <winpr/endian.h>
29 #include <winpr/synch.h>
30 #include <winpr/assert.h>
37 typedef struct s_wStreamPool wStreamPool;
48 BOOL isAllocatedStream;
52 static INLINE
size_t Stream_Capacity(
const wStream* _s);
53 WINPR_API
size_t Stream_GetRemainingCapacity(
const wStream* _s);
54 WINPR_API
size_t Stream_GetRemainingLength(
const wStream* _s);
56 WINPR_API BOOL Stream_EnsureCapacity(
wStream* s,
size_t size);
57 WINPR_API BOOL Stream_EnsureRemainingCapacity(
wStream* s,
size_t size);
60 #define WINPR_STREAM_CAST(t, val) static_cast<t>(val)
62 #define WINPR_STREAM_CAST(t, val) (t)(val)
65 #define Stream_CheckAndLogRequiredCapacityOfSize(tag, s, nmemb, size) \
66 Stream_CheckAndLogRequiredCapacityEx(tag, WLOG_WARN, s, nmemb, size, "%s(%s:%" PRIuz ")", \
67 __func__, __FILE__, (size_t)__LINE__)
68 #define Stream_CheckAndLogRequiredCapacity(tag, s, len) \
69 Stream_CheckAndLogRequiredCapacityOfSize((tag), (s), (len), 1)
71 WINPR_API BOOL Stream_CheckAndLogRequiredCapacityEx(
const char* tag, DWORD level,
wStream* s,
72 size_t nmemb,
size_t size,
const char* fmt,
74 WINPR_API BOOL Stream_CheckAndLogRequiredCapacityExVa(
const char* tag, DWORD level,
wStream* s,
75 size_t nmemb,
size_t size,
76 const char* fmt, va_list args);
78 #define Stream_CheckAndLogRequiredCapacityOfSizeWLog(log, s, nmemb, size) \
79 Stream_CheckAndLogRequiredCapacityWLogEx(log, WLOG_WARN, s, nmemb, size, "%s(%s:%" PRIuz ")", \
80 __func__, __FILE__, (size_t)__LINE__)
82 #define Stream_CheckAndLogRequiredCapacityWLog(log, s, len) \
83 Stream_CheckAndLogRequiredCapacityOfSizeWLog((log), (s), (len), 1)
85 WINPR_API BOOL Stream_CheckAndLogRequiredCapacityWLogEx(wLog* log, DWORD level,
wStream* s,
86 size_t nmemb,
size_t size,
87 const char* fmt, ...);
88 WINPR_API BOOL Stream_CheckAndLogRequiredCapacityWLogExVa(wLog* log, DWORD level,
wStream* s,
89 size_t nmemb,
size_t size,
90 const char* fmt, va_list args);
92 WINPR_API
void Stream_Free(
wStream* s, BOOL bFreeBuffer);
94 WINPR_ATTR_MALLOC(Stream_Free, 1)
95 WINPR_API
wStream* Stream_New(BYTE* buffer,
size_t size);
96 WINPR_API
wStream* Stream_StaticConstInit(
wStream* s, const BYTE* buffer,
size_t size);
97 WINPR_API
wStream* Stream_StaticInit(
wStream* s, BYTE* buffer,
size_t size);
99 #define Stream_CheckAndLogRequiredLengthOfSize(tag, s, nmemb, size) \
100 Stream_CheckAndLogRequiredLengthEx(tag, WLOG_WARN, s, nmemb, size, "%s(%s:%" PRIuz ")", \
101 __func__, __FILE__, (size_t)__LINE__)
102 #define Stream_CheckAndLogRequiredLength(tag, s, len) \
103 Stream_CheckAndLogRequiredLengthOfSize(tag, s, len, 1)
105 WINPR_API BOOL Stream_CheckAndLogRequiredLengthEx(
const char* tag, DWORD level,
wStream* s,
106 size_t nmemb,
size_t size,
const char* fmt,
108 WINPR_API BOOL Stream_CheckAndLogRequiredLengthExVa(
const char* tag, DWORD level,
wStream* s,
109 size_t nmemb,
size_t size,
const char* fmt,
112 #define Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, nmemb, size) \
113 Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, nmemb, size, "%s(%s:%" PRIuz ")", \
114 __func__, __FILE__, (size_t)__LINE__)
115 #define Stream_CheckAndLogRequiredLengthWLog(log, s, len) \
116 Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, len, 1)
118 WINPR_API BOOL Stream_CheckAndLogRequiredLengthWLogEx(wLog* log, DWORD level,
wStream* s,
119 size_t nmemb,
size_t size,
120 const char* fmt, ...);
121 WINPR_API BOOL Stream_CheckAndLogRequiredLengthWLogExVa(wLog* log, DWORD level,
wStream* s,
122 size_t nmemb,
size_t size,
123 const char* fmt, va_list args);
125 static INLINE
void Stream_Seek(
wStream* s,
size_t _offset)
128 WINPR_ASSERT(Stream_GetRemainingCapacity(s) >= _offset);
129 s->pointer += (_offset);
132 static INLINE
void Stream_Rewind(
wStream* s,
size_t _offset)
136 WINPR_ASSERT(s->buffer <= s->pointer);
137 cur = WINPR_STREAM_CAST(
size_t, s->pointer - s->buffer);
138 WINPR_ASSERT(cur >= _offset);
140 s->pointer -= (_offset);
142 s->pointer = s->buffer;
145 static INLINE UINT8 stream_read_u8(
wStream* _s, BOOL seek)
148 WINPR_ASSERT(Stream_GetRemainingLength(_s) >=
sizeof(UINT8));
150 const UINT8 v = *(_s)->pointer;
152 Stream_Seek(_s,
sizeof(UINT8));
156 static INLINE INT8 stream_read_i8(
wStream* _s, BOOL seek)
158 const UINT8 v = stream_read_u8(_s, seek);
159 return WINPR_STREAM_CAST(INT8, v);
162 static INLINE UINT16 stream_read_u16_le(
wStream* _s, BOOL seek)
164 const size_t typesize =
sizeof(UINT16);
166 WINPR_ASSERT(Stream_GetRemainingLength(_s) >= typesize);
169 for (
size_t x = 0; x < typesize; x++)
172 v |= (_s)->pointer[typesize - x - 1];
175 Stream_Seek(_s, typesize);
179 static INLINE UINT16 stream_read_u16_be(
wStream* _s, BOOL seek)
181 const size_t typesize =
sizeof(UINT16);
183 WINPR_ASSERT(Stream_GetRemainingLength(_s) >= typesize);
186 for (
size_t x = 0; x < typesize; x++)
189 v |= (_s)->pointer[x];
192 Stream_Seek(_s, typesize);
196 static INLINE INT16 stream_read_i16_le(
wStream* _s, BOOL seek)
198 const UINT16 v = stream_read_u16_le(_s, seek);
199 return WINPR_STREAM_CAST(INT16, v);
202 static INLINE INT16 stream_read_i16_be(
wStream* _s, BOOL seek)
204 const UINT16 v = stream_read_u16_be(_s, seek);
205 return WINPR_STREAM_CAST(INT16, v);
208 static INLINE UINT32 stream_read_u32_le(
wStream* _s, BOOL seek)
210 const size_t typesize =
sizeof(UINT32);
212 WINPR_ASSERT(Stream_GetRemainingLength(_s) >= typesize);
215 for (
size_t x = 0; x < typesize; x++)
218 v |= (_s)->pointer[typesize - x - 1];
221 Stream_Seek(_s, typesize);
225 static INLINE UINT32 stream_read_u32_be(
wStream* _s, BOOL seek)
227 const size_t typesize =
sizeof(UINT32);
229 WINPR_ASSERT(Stream_GetRemainingLength(_s) >= typesize);
232 for (
size_t x = 0; x < typesize; x++)
235 v |= (_s)->pointer[x];
238 Stream_Seek(_s, typesize);
242 static INLINE INT32 stream_read_i32_le(
wStream* _s, BOOL seek)
244 const UINT32 v = stream_read_u32_le(_s, seek);
245 return WINPR_STREAM_CAST(INT32, v);
248 static INLINE INT32 stream_read_i32_be(
wStream* _s, BOOL seek)
250 const UINT32 v = stream_read_u32_be(_s, seek);
251 return WINPR_STREAM_CAST(INT32, v);
254 static INLINE UINT64 stream_read_u64_le(
wStream* _s, BOOL seek)
256 const size_t typesize =
sizeof(UINT64);
258 WINPR_ASSERT(Stream_GetRemainingLength(_s) >= typesize);
261 for (
size_t x = 0; x < typesize; x++)
264 v |= (_s)->pointer[typesize - x - 1];
267 Stream_Seek(_s, typesize);
271 static INLINE UINT64 stream_read_u64_be(
wStream* _s, BOOL seek)
273 const size_t typesize =
sizeof(UINT64);
275 WINPR_ASSERT(Stream_GetRemainingLength(_s) >= typesize);
278 for (
size_t x = 0; x < typesize; x++)
281 v |= (_s)->pointer[x];
284 Stream_Seek(_s, typesize);
288 static INLINE INT64 stream_read_i64_le(
wStream* _s, BOOL seek)
290 const UINT64 v = stream_read_u64_le(_s, seek);
291 return WINPR_STREAM_CAST(INT64, v);
294 static INLINE INT64 stream_read_i64_be(
wStream* _s, BOOL seek)
296 const UINT64 v = stream_read_u64_be(_s, seek);
297 return WINPR_STREAM_CAST(INT64, v);
306 static INLINE UINT8 Stream_Get_UINT8(
wStream* _s)
308 return stream_read_u8(_s, TRUE);
317 static INLINE INT8 Stream_Get_INT8(
wStream* _s)
319 return stream_read_i8(_s, TRUE);
328 static INLINE UINT16 Stream_Get_UINT16(
wStream* _s)
330 return stream_read_u16_le(_s, TRUE);
339 static INLINE INT16 Stream_Get_INT16(
wStream* _s)
341 return stream_read_i16_le(_s, TRUE);
350 static INLINE UINT16 Stream_Get_UINT16_BE(
wStream* _s)
352 return stream_read_u16_be(_s, TRUE);
361 static INLINE INT16 Stream_Get_INT16_BE(
wStream* _s)
363 return stream_read_i16_be(_s, TRUE);
372 static INLINE UINT32 Stream_Get_UINT32(
wStream* _s)
374 return stream_read_u32_le(_s, TRUE);
383 static INLINE INT32 Stream_Get_INT32(
wStream* _s)
385 return stream_read_i32_le(_s, TRUE);
394 static INLINE UINT32 Stream_Get_UINT32_BE(
wStream* _s)
396 return stream_read_u32_be(_s, TRUE);
405 static INLINE INT32 Stream_Get_INT32_BE(
wStream* _s)
407 return stream_read_i32_be(_s, TRUE);
416 static INLINE UINT64 Stream_Get_UINT64(
wStream* _s)
418 return stream_read_u64_le(_s, TRUE);
427 static INLINE INT64 Stream_Get_INT64(
wStream* _s)
429 return stream_read_i64_le(_s, TRUE);
438 static INLINE UINT64 Stream_Get_UINT64_BE(
wStream* _s)
440 return stream_read_u64_be(_s, TRUE);
449 static INLINE INT64 Stream_Get_INT64_BE(
wStream* _s)
451 return stream_read_i64_be(_s, TRUE);
460 static INLINE UINT8 Stream_Peek_Get_UINT8(
wStream* _s)
462 return stream_read_u8(_s, FALSE);
471 static INLINE INT8 Stream_Peek_Get_INT8(
wStream* _s)
473 return stream_read_i8(_s, FALSE);
482 static INLINE UINT16 Stream_Peek_Get_UINT16(
wStream* _s)
484 return stream_read_u16_le(_s, FALSE);
493 static INLINE INT16 Stream_Peek_Get_INT16(
wStream* _s)
495 return stream_read_i16_le(_s, FALSE);
504 static INLINE UINT16 Stream_Peek_Get_UINT16_BE(
wStream* _s)
506 return stream_read_u16_be(_s, FALSE);
515 static INLINE INT16 Stream_Peek_Get_INT16_BE(
wStream* _s)
517 return stream_read_i16_be(_s, FALSE);
526 static INLINE UINT32 Stream_Peek_Get_UINT32(
wStream* _s)
528 return stream_read_u32_le(_s, FALSE);
537 static INLINE INT32 Stream_Peek_Get_INT32(
wStream* _s)
539 return stream_read_i32_le(_s, FALSE);
548 static INLINE UINT32 Stream_Peek_Get_UINT32_BE(
wStream* _s)
550 return stream_read_u32_be(_s, FALSE);
559 static INLINE INT32 Stream_Peek_Get_INT32_BE(
wStream* _s)
561 return stream_read_i32_be(_s, FALSE);
570 static INLINE UINT64 Stream_Peek_Get_UINT64(
wStream* _s)
572 return stream_read_u64_le(_s, FALSE);
581 static INLINE INT64 Stream_Peek_Get_INT64(
wStream* _s)
583 return stream_read_i64_le(_s, FALSE);
592 static INLINE UINT64 Stream_Peek_Get_UINT64_BE(
wStream* _s)
594 return stream_read_u64_be(_s, FALSE);
603 static INLINE INT64 Stream_Peek_Get_INT64_BE(
wStream* _s)
605 return stream_read_i64_be(_s, FALSE);
608 #define Stream_Read_UINT8(_s, _v) \
611 _v = stream_read_u8(_s, TRUE); \
614 #define Stream_Read_INT8(_s, _v) \
617 _v = stream_read_i8(_s, TRUE); \
620 #define Stream_Read_UINT16(_s, _v) \
623 _v = stream_read_u16_le(_s, TRUE); \
626 #define Stream_Read_INT16(_s, _v) \
629 _v = stream_read_i16_le(_s, TRUE); \
632 #define Stream_Read_UINT16_BE(_s, _v) \
635 _v = stream_read_u16_be(_s, TRUE); \
638 #define Stream_Read_INT16_BE(_s, _v) \
641 _v = stream_read_i16_be(_s, TRUE); \
644 #define Stream_Read_UINT32(_s, _v) \
647 _v = stream_read_u32_le(_s, TRUE); \
650 #define Stream_Read_INT32(_s, _v) \
653 _v = stream_read_i32_le(_s, TRUE); \
656 #define Stream_Read_UINT32_BE(_s, _v) \
659 _v = stream_read_u32_be(_s, TRUE); \
662 #define Stream_Read_INT32_BE(_s, _v) \
665 _v = stream_read_i32_be(_s, TRUE); \
668 #define Stream_Read_UINT64(_s, _v) \
671 _v = stream_read_u64_le(_s, TRUE); \
674 #define Stream_Read_INT64(_s, _v) \
677 _v = stream_read_i64_le(_s, TRUE); \
680 #define Stream_Read_UINT64_BE(_s, _v) \
683 _v = stream_read_u64_be(_s, TRUE); \
686 #define Stream_Read_INT64_BE(_s, _v) \
689 _v = stream_read_i64_be(_s, TRUE); \
692 static INLINE
void Stream_Read(
wStream* _s,
void* _b,
size_t _n)
695 WINPR_ASSERT(_b || (_n == 0));
696 WINPR_ASSERT(Stream_GetRemainingCapacity(_s) >= _n);
697 memcpy(_b, (_s->pointer), (_n));
701 #define Stream_Peek_UINT8(_s, _v) \
704 _v = stream_read_u8(_s, FALSE); \
707 #define Stream_Peek_INT8(_s, _v) \
710 _v = stream_read_i8(_s, FALSE); \
713 #define Stream_Peek_UINT16(_s, _v) \
716 _v = stream_read_u16_le(_s, FALSE); \
719 #define Stream_Peek_INT16(_s, _v) \
722 _v = stream_read_i16_le(_s, FALSE); \
725 #define Stream_Peek_UINT16_BE(_s, _v) \
728 _v = stream_read_u16_be(_s, FALSE); \
731 #define Stream_Peek_INT16_BE(_s, _v) \
734 _v = stream_read_i16_be(_s, FALSE); \
737 #define Stream_Peek_UINT32(_s, _v) \
740 _v = stream_read_u32_le(_s, FALSE); \
743 #define Stream_Peek_INT32(_s, _v) \
746 _v = stream_read_i32_le(_s, FALSE); \
749 #define Stream_Peek_UINT32_BE(_s, _v) \
752 _v = stream_read_u32_be(_s, FALSE); \
755 #define Stream_Peek_INT32_BE(_s, _v) \
758 _v = stream_read_i32_be(_s, FALSE); \
761 #define Stream_Peek_UINT64(_s, _v) \
764 _v = stream_read_u64_le(_s, FALSE); \
767 #define Stream_Peek_INT64(_s, _v) \
770 _v = stream_read_i64_le(_s, FALSE); \
773 #define Stream_Peek_UINT64_BE(_s, _v) \
776 _v = stream_read_u64_be(_s, FALSE); \
779 #define Stream_Peek_INT64_BE(_s, _v) \
782 _v = stream_read_i64_be(_s, FALSE); \
785 static INLINE
void Stream_Peek(
const wStream* _s,
void* _b,
size_t _n)
788 WINPR_ASSERT(_b || (_n == 0));
789 WINPR_ASSERT(Stream_GetRemainingCapacity(_s) >= _n);
790 memcpy(_b, (_s->pointer), (_n));
793 static INLINE
void Stream_Write_UINT8(
wStream* _s, UINT8 _v)
796 WINPR_ASSERT(_s->pointer);
797 WINPR_ASSERT(Stream_GetRemainingCapacity(_s) >= 1);
798 *_s->pointer++ = (_v);
801 static INLINE
void Stream_Write_INT16(
wStream* _s, INT16 _v)
804 WINPR_ASSERT(_s->pointer);
805 WINPR_ASSERT(Stream_GetRemainingCapacity(_s) >= 2);
806 *_s->pointer++ = (_v)&0xFF;
807 *_s->pointer++ = ((_v) >> 8) & 0xFF;
810 static INLINE
void Stream_Write_UINT16(
wStream* _s, UINT16 _v)
813 WINPR_ASSERT(_s->pointer);
814 WINPR_ASSERT(Stream_GetRemainingCapacity(_s) >= 2);
815 *_s->pointer++ = (_v)&0xFF;
816 *_s->pointer++ = ((_v) >> 8) & 0xFF;
819 static INLINE
void Stream_Write_UINT16_BE(
wStream* _s, UINT16 _v)
822 WINPR_ASSERT(_s->pointer);
823 WINPR_ASSERT(Stream_GetRemainingCapacity(_s) >= 2);
824 *_s->pointer++ = ((_v) >> 8) & 0xFF;
825 *_s->pointer++ = (_v)&0xFF;
828 static INLINE
void Stream_Write_UINT24_BE(
wStream* _s, UINT32 _v)
831 WINPR_ASSERT(_s->pointer);
832 WINPR_ASSERT(_v <= 0x00FFFFFF);
833 WINPR_ASSERT(Stream_GetRemainingCapacity(_s) >= 3);
834 *_s->pointer++ = ((_v) >> 16) & 0xFF;
835 *_s->pointer++ = ((_v) >> 8) & 0xFF;
836 *_s->pointer++ = (_v)&0xFF;
839 static INLINE
void Stream_Write_INT32(
wStream* _s, INT32 _v)
842 WINPR_ASSERT(_s->pointer);
843 WINPR_ASSERT(Stream_GetRemainingCapacity(_s) >= 4);
844 *_s->pointer++ = (_v)&0xFF;
845 *_s->pointer++ = ((_v) >> 8) & 0xFF;
846 *_s->pointer++ = ((_v) >> 16) & 0xFF;
847 *_s->pointer++ = ((_v) >> 24) & 0xFF;
850 static INLINE
void Stream_Write_UINT32(
wStream* _s, UINT32 _v)
853 WINPR_ASSERT(_s->pointer);
854 WINPR_ASSERT(Stream_GetRemainingCapacity(_s) >= 4);
855 *_s->pointer++ = (_v)&0xFF;
856 *_s->pointer++ = ((_v) >> 8) & 0xFF;
857 *_s->pointer++ = ((_v) >> 16) & 0xFF;
858 *_s->pointer++ = ((_v) >> 24) & 0xFF;
861 static INLINE
void Stream_Write_UINT32_BE(
wStream* _s, UINT32 _v)
863 WINPR_ASSERT(Stream_GetRemainingCapacity(_s) >= 4);
864 Stream_Write_UINT16_BE(_s, ((_v) >> 16 & 0xFFFF));
865 Stream_Write_UINT16_BE(_s, ((_v)&0xFFFF));
868 static INLINE
void Stream_Write_UINT64(
wStream* _s, UINT64 _v)
871 WINPR_ASSERT(_s->pointer);
872 WINPR_ASSERT(Stream_GetRemainingCapacity(_s) >= 8);
873 Stream_Write_UINT32(_s, ((_v)&0xFFFFFFFFUL));
874 Stream_Write_UINT32(_s, ((_v) >> 16 & 0xFFFFFFFFUL));
877 static INLINE
void Stream_Write_UINT64_BE(
wStream* _s, UINT64 _v)
880 WINPR_ASSERT(_s->pointer);
881 WINPR_ASSERT(Stream_GetRemainingCapacity(_s) >= 8);
882 Stream_Write_UINT32_BE(_s, ((_v) >> 16 & 0xFFFFFFFFUL));
883 Stream_Write_UINT32_BE(_s, ((_v)&0xFFFFFFFFUL));
886 static INLINE
void Stream_Write(
wStream* _s,
const void* _b,
size_t _n)
892 WINPR_ASSERT(Stream_GetRemainingCapacity(_s) >= _n);
893 memcpy(_s->pointer, (_b), (_n));
898 static INLINE
void Stream_Seek_UINT8(
wStream* _s)
900 Stream_Seek(_s,
sizeof(UINT8));
902 static INLINE
void Stream_Seek_UINT16(
wStream* _s)
904 Stream_Seek(_s,
sizeof(UINT16));
906 static INLINE
void Stream_Seek_UINT32(
wStream* _s)
908 Stream_Seek(_s,
sizeof(UINT32));
910 static INLINE
void Stream_Seek_UINT64(
wStream* _s)
912 Stream_Seek(_s,
sizeof(UINT64));
915 static INLINE
void Stream_Rewind_UINT8(
wStream* _s)
917 Stream_Rewind(_s,
sizeof(UINT8));
919 static INLINE
void Stream_Rewind_UINT16(
wStream* _s)
921 Stream_Rewind(_s,
sizeof(UINT16));
923 static INLINE
void Stream_Rewind_UINT32(
wStream* _s)
925 Stream_Rewind(_s,
sizeof(UINT32));
927 static INLINE
void Stream_Rewind_UINT64(
wStream* _s)
929 Stream_Rewind(_s,
sizeof(UINT64));
932 static INLINE
void Stream_Zero(
wStream* _s,
size_t _n)
935 WINPR_ASSERT(Stream_GetRemainingCapacity(_s) >= (_n));
936 memset(_s->pointer,
'\0', (_n));
940 static INLINE
void Stream_Fill(
wStream* _s,
int _v,
size_t _n)
943 WINPR_ASSERT(Stream_GetRemainingCapacity(_s) >= (_n));
944 memset(_s->pointer, _v, (_n));
948 static INLINE
void Stream_Copy(
wStream* _src,
wStream* _dst,
size_t _n)
952 WINPR_ASSERT(Stream_GetRemainingCapacity(_src) >= (_n));
953 WINPR_ASSERT(Stream_GetRemainingCapacity(_dst) >= (_n));
955 memcpy(_dst->pointer, _src->pointer, _n);
956 Stream_Seek(_dst, _n);
957 Stream_Seek(_src, _n);
964 #define Stream_BufferAs(s, type) WINPR_STREAM_CAST(type*, Stream_Buffer(s))
966 static INLINE BYTE* Stream_Buffer(
wStream* _s)
976 #define Stream_ConstBufferAs(s, type) WINPR_STREAM_CAST(type*, Stream_ConstBuffer(s))
977 static INLINE
const BYTE* Stream_ConstBuffer(
const wStream* _s)
983 #define Stream_GetBuffer(_s, _b) _b = Stream_Buffer(_s)
989 #define Stream_GetBufferAs(_s, _b) _b = Stream_BufferAs(_s, typeof(_b))
991 #define Stream_PointerAs(s, type) WINPR_STREAM_CAST(type*, Stream_Pointer(s))
993 static INLINE
void* Stream_Pointer(
wStream* _s)
999 static INLINE
const void* Stream_ConstPointer(
const wStream* _s)
1005 #define Stream_GetPointer(_s, _p) _p = Stream_Pointer(_s)
1011 #define Stream_GetPointerAs(_s, _p) _p = Stream_PointerAs(_s, typeof(_p))
1013 #if defined(WITH_WINPR_DEPRECATED)
1014 WINPR_API WINPR_DEPRECATED_VAR(
"Use Stream_SetPosition instead",
1015 BOOL Stream_SetPointer(
wStream* _s, BYTE* _p));
1016 WINPR_API WINPR_DEPRECATED_VAR(
"Use Stream_New(buffer, capacity) instead",
1017 BOOL Stream_SetBuffer(
wStream* _s, BYTE* _b));
1018 WINPR_API WINPR_DEPRECATED_VAR(
"Use Stream_New(buffer, capacity) instead",
1019 void Stream_SetCapacity(
wStream* _s,
size_t capacity));
1022 static INLINE
size_t Stream_Length(
const wStream* _s)
1028 #define Stream_GetLength(_s, _l) _l = Stream_Length(_s)
1029 WINPR_API BOOL Stream_SetLength(
wStream* _s,
size_t _l);
1031 static INLINE
size_t Stream_Capacity(
const wStream* _s)
1034 return _s->capacity;
1037 #define Stream_GetCapacity(_s, _c) _c = Stream_Capacity(_s);
1039 static INLINE
size_t Stream_GetPosition(
const wStream* _s)
1042 WINPR_ASSERT(_s->buffer <= _s->pointer);
1043 return WINPR_STREAM_CAST(
size_t, (_s->pointer - _s->buffer));
1046 WINPR_API BOOL Stream_SetPosition(
wStream* _s,
size_t _p);
1048 WINPR_API
void Stream_SealLength(
wStream* _s);
1050 static INLINE
void Stream_Clear(
wStream* _s)
1053 memset(_s->buffer, 0, _s->capacity);
1056 #define Stream_SafeSeek(s, size) Stream_SafeSeekEx(s, size, __FILE__, __LINE__, __func__)
1057 WINPR_API BOOL Stream_SafeSeekEx(
wStream* s,
size_t size,
const char* file,
size_t line,
1060 WINPR_API BOOL Stream_Read_UTF16_String(
wStream* s, WCHAR* dst,
size_t charLength);
1061 WINPR_API BOOL Stream_Write_UTF16_String(
wStream* s,
const WCHAR* src,
size_t charLength);
1072 WINPR_API
char* Stream_Read_UTF16_String_As_UTF8(
wStream* s,
size_t wcharLength,
1073 size_t* pUtfCharLength);
1084 WINPR_API SSIZE_T Stream_Read_UTF16_String_As_UTF8_Buffer(
wStream* s,
size_t wcharLength,
1086 size_t utfBufferCharLength);
1099 WINPR_API SSIZE_T Stream_Write_UTF16_String_From_UTF8(
wStream* s,
size_t wcharLength,
1100 const char* src,
size_t length,
1105 WINPR_API
void StreamPool_Return(wStreamPool* pool,
wStream* s);
1107 WINPR_API
wStream* StreamPool_Take(wStreamPool* pool,
size_t size);
1109 WINPR_API
void Stream_AddRef(
wStream* s);
1110 WINPR_API
void Stream_Release(
wStream* s);
1112 WINPR_API
wStream* StreamPool_Find(wStreamPool* pool, BYTE* ptr);
1114 WINPR_API
void StreamPool_Clear(wStreamPool* pool);
1116 WINPR_API
void StreamPool_Free(wStreamPool* pool);
1118 WINPR_ATTR_MALLOC(StreamPool_Free, 1)
1119 WINPR_API wStreamPool* StreamPool_New(BOOL synchronized,
size_t defaultSize);
1121 WINPR_API
char* StreamPool_GetStatistics(wStreamPool* pool,
char* buffer,
size_t size);