Wraps a memory block which points to start and end address. Use this structure to stream memory, i.e. read bytes and increment the start address to point to the next unread byte.
MemoryStream | Wraps a memory block which points to start and end address. |
Copyright | This program is free software. |
Files | |
C-kern/ | Header file MemoryStream. |
C-kern/ | Implementation file MemoryStream impl. |
Types | |
struct memstream_t | Export memstream_t into global namespace. |
Functions | |
test | |
unittest_memory_memstream | Test memstream_t functionality. |
memstream_t | Wraps a memory block which points to start and end address. |
next | Points to next unread memory byte. |
end | Points one after the last memory byte. |
lifetime | |
memstream_FREE | Static initializer. |
memstream_INIT | Initializes memstream_t. |
query | |
size_memstream | Returns the nuber of unread bytes. |
generic | |
genericcast_memstream | Casts pointer obj into pointer to memstream_t. |
inline implementation | |
Macros | |
genericcast_memstream | Implements memstream_t.genericcast_memstream. |
size_memstream | Implements memstream_t.size_memstream. |
This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
© 2013 Jörg Seebohn
Header file MemoryStream.
Implementation file MemoryStream impl.
typedef struct memstream_t memstream_t
Export memstream_t into global namespace.
test | |
unittest_memory_memstream | Test memstream_t functionality. |
int unittest_memory_memstream( void )
Test memstream_t functionality.
struct memstream_t
Wraps a memory block which points to start and end address. The start address is the lowest address of an allocated memory block. The end address points one after the highest address of the allocated memory block.
next | Points to next unread memory byte. |
end | Points one after the last memory byte. |
lifetime | |
memstream_FREE | Static initializer. |
memstream_INIT | Initializes memstream_t. |
query | |
size_memstream | Returns the nuber of unread bytes. |
generic | |
genericcast_memstream | Casts pointer obj into pointer to memstream_t. |
uint8_t * next
Points to next unread memory byte. next is always lower or equal to end.
memstream_t * genericcast_memstream( void * obj, IDNAME nameprefix )
Casts pointer obj into pointer to memstream_t. obj must point a generic object with two members nameprefix##next and nameprefix##end of the same type as the members of memstream_t and in the same order.
#define genericcast_memstream( obj, nameprefix ) ( __extension__ ({ typeof(obj) _obj = (obj) ; static_assert( &((memstream_t*)((uintptr_t) &_obj->nameprefix##next))->next == &_obj->nameprefix##next && &((memstream_t*)((uintptr_t) &_obj->nameprefix##next))->end == &_obj->nameprefix##end, "obj is compatible") ; (memstream_t *)(&_obj->nameprefix##next) ; }))
Implements memstream_t.genericcast_memstream.
#define size_memstream( memstr ) ( __extension__ ({ const memstream_t * _m ; _m = (memstr) ; (size_t) (_m->end - _m->next) ; }))
Implements memstream_t.size_memstream.
Export memstream_t into global namespace.
typedef struct memstream_t memstream_t
Wraps a memory block which points to start and end address.
struct memstream_t
Test memstream_t functionality.
int unittest_memory_memstream( void )
Points to next unread memory byte.
uint8_t * next
Points one after the last memory byte.
uint8_t * end
Static initializer.
#define memstream_FREE { 0, 0 }
Initializes memstream_t.
#define memstream_INIT( start, end ) { start, end }
Returns the nuber of unread bytes.
size_t size_memstream( const memstream_t * memstr )
Casts pointer obj into pointer to memstream_t.
memstream_t * genericcast_memstream( void * obj, IDNAME nameprefix )
Implements memstream_t.genericcast_memstream.
#define genericcast_memstream( obj, nameprefix ) ( __extension__ ({ typeof(obj) _obj = (obj) ; static_assert( &((memstream_t*)((uintptr_t) &_obj->nameprefix##next))->next == &_obj->nameprefix##next && &((memstream_t*)((uintptr_t) &_obj->nameprefix##next))->end == &_obj->nameprefix##end, "obj is compatible") ; (memstream_t *)(&_obj->nameprefix##next) ; }))
Implements memstream_t.size_memstream.
#define size_memstream( memstr ) ( __extension__ ({ const memstream_t * _m ; _m = (memstr) ; (size_t) (_m->end - _m->next) ; }))