libfreerdp-utils: add new stream interface.
This commit is contained in:
parent
cfbb6c286c
commit
cc6598de8f
@ -1,8 +1,9 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* Stream Macro Utils
|
||||
* Stream Utils
|
||||
*
|
||||
* Copyright 2009-2011 Jay Sorg
|
||||
* Copyright 2011 Vic Lee
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -20,61 +21,35 @@
|
||||
#ifndef __STREAM_UTILS_H
|
||||
#define __STREAM_UTILS_H
|
||||
|
||||
#define GET_UINT8(_p1, _offset) *(((uint8 *) _p1) + _offset)
|
||||
#define GET_UINT8A(_dest, _src, _offset, _len) ( \
|
||||
memcpy( \
|
||||
((void *) _dest), \
|
||||
((const void *) (_src + _offset)), \
|
||||
((size_t) _len) \
|
||||
))
|
||||
#define GET_UINT16(_p1, _offset) ( \
|
||||
(uint16) (*(((uint8 *) _p1) + _offset)) + \
|
||||
((uint16) (*(((uint8 *) _p1) + _offset + 1)) << 8))
|
||||
#define GET_UINT32(_p1, _offset) ( \
|
||||
(uint32) (*(((uint8 *) _p1) + _offset)) + \
|
||||
((uint32) (*(((uint8 *) _p1) + _offset + 1)) << 8) + \
|
||||
((uint32) (*(((uint8 *) _p1) + _offset + 2)) << 16) + \
|
||||
((uint32) (*(((uint8 *) _p1) + _offset + 3)) << 24))
|
||||
#define GET_UINT64(_p1, _offset) ( \
|
||||
(uint64) (*(((uint8 *) _p1) + _offset)) + \
|
||||
((uint64) (*(((uint8 *) _p1) + _offset + 1)) << 8) + \
|
||||
((uint64) (*(((uint8 *) _p1) + _offset + 2)) << 16) + \
|
||||
((uint64) (*(((uint8 *) _p1) + _offset + 3)) << 24) + \
|
||||
((uint64) (*(((uint8 *) _p1) + _offset + 4)) << 32) + \
|
||||
((uint64) (*(((uint8 *) _p1) + _offset + 5)) << 40) + \
|
||||
((uint64) (*(((uint8 *) _p1) + _offset + 6)) << 48) + \
|
||||
((uint64) (*(((uint8 *) _p1) + _offset + 7)) << 56))
|
||||
#include <freerdp/types/base.h>
|
||||
|
||||
#define SET_UINT8(_p1, _offset, _value) *(((uint8 *) _p1) + _offset) = (uint8) (_value)
|
||||
#define SET_UINT8A(_dest, _offset, _src, _len) ( \
|
||||
memcpy( \
|
||||
((void *) (_dest + _offset)), \
|
||||
((const void *) _src), \
|
||||
((size_t) _len) \
|
||||
))
|
||||
#define SET_UINT8V(_dest, _offset, _value, _len) ( \
|
||||
memset( \
|
||||
((void *) (_dest + _offset)), \
|
||||
((int) _value), \
|
||||
((size_t) _len) \
|
||||
))
|
||||
#define SET_UINT16(_p1, _offset, _value) \
|
||||
*(((uint8 *) _p1) + _offset) = (uint8) (((uint16) (_value)) & 0xff), \
|
||||
*(((uint8 *) _p1) + _offset + 1) = (uint8) ((((uint16) (_value)) >> 8) & 0xff)
|
||||
#define SET_UINT32(_p1, _offset, _value) \
|
||||
*(((uint8 *) _p1) + _offset) = (uint8) (((uint32) (_value)) & 0xff), \
|
||||
*(((uint8 *) _p1) + _offset + 1) = (uint8) ((((uint32) (_value)) >> 8) & 0xff), \
|
||||
*(((uint8 *) _p1) + _offset + 2) = (uint8) ((((uint32) (_value)) >> 16) & 0xff), \
|
||||
*(((uint8 *) _p1) + _offset + 3) = (uint8) ((((uint32) (_value)) >> 24) & 0xff)
|
||||
#define SET_UINT64(_p1, _offset, _value) \
|
||||
*(((uint8 *) _p1) + _offset) = (uint8) (((uint64) (_value)) & 0xff), \
|
||||
*(((uint8 *) _p1) + _offset + 1) = (uint8) ((((uint64) (_value)) >> 8) & 0xff), \
|
||||
*(((uint8 *) _p1) + _offset + 2) = (uint8) ((((uint64) (_value)) >> 16) & 0xff), \
|
||||
*(((uint8 *) _p1) + _offset + 3) = (uint8) ((((uint64) (_value)) >> 24) & 0xff), \
|
||||
*(((uint8 *) _p1) + _offset + 4) = (uint8) ((((uint64) (_value)) >> 32) & 0xff), \
|
||||
*(((uint8 *) _p1) + _offset + 5) = (uint8) ((((uint64) (_value)) >> 40) & 0xff), \
|
||||
*(((uint8 *) _p1) + _offset + 6) = (uint8) ((((uint64) (_value)) >> 48) & 0xff), \
|
||||
*(((uint8 *) _p1) + _offset + 7) = (uint8) ((((uint64) (_value)) >> 56) & 0xff)
|
||||
typedef struct _STREAM STREAM;
|
||||
struct _STREAM
|
||||
{
|
||||
uint8 * buffer;
|
||||
uint8 * ptr;
|
||||
int size;
|
||||
};
|
||||
|
||||
typedef uint8 * STREAM_MARK;
|
||||
|
||||
STREAM *
|
||||
stream_new(int size);
|
||||
void
|
||||
stream_free(STREAM * stream);
|
||||
|
||||
#define stream_get_mark(_s) _s->ptr
|
||||
#define stream_set_mark(_s,_m) _s->ptr = _m
|
||||
|
||||
#define stream_get_uint8(_s, _v) do { _v = *_s->ptr++; } while (0)
|
||||
#define stream_get_uint16(_s, _v) do { _v = \
|
||||
(uint16)(*_s->ptr) + \
|
||||
(((uint16)(*(_s->ptr + 1))) << 8); } while (0)
|
||||
|
||||
#define stream_set_uint8(_s, _v) do { *_s->ptr++ = (uint8)(_v); } while (0)
|
||||
#define stream_set_uint16(_s, _v) do { \
|
||||
*_s->ptr++ = (_v) & 0xFF; \
|
||||
*_s->ptr++ = (_v) >> 8; } while (0)
|
||||
|
||||
#endif /* __STREAM_UTILS_H */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user