2017-10-09 22:11:01 +08:00
|
|
|
|
/*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
2017-09-27 16:20:30 +08:00
|
|
|
|
*
|
2021-01-17 18:31:50 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
2017-09-27 16:20:30 +08:00
|
|
|
|
*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Use of this source code is governed by MIT license that can be found in the
|
|
|
|
|
* LICENSE file in the root of the source tree. All contributing project authors
|
|
|
|
|
* may be found in the AUTHORS file in the root of the source tree.
|
2017-09-27 16:20:30 +08:00
|
|
|
|
*/
|
2020-04-04 20:30:09 +08:00
|
|
|
|
|
2017-04-01 16:35:56 +08:00
|
|
|
|
#include "utils.h"
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdarg.h>
|
2017-08-09 18:39:30 +08:00
|
|
|
|
#include "Util/util.h"
|
2017-08-10 14:31:04 +08:00
|
|
|
|
#include "Network/sockutil.h"
|
2018-10-24 17:17:55 +08:00
|
|
|
|
using namespace toolkit;
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Used to do unaligned loads on archs that don't support them. GCC can mostly
|
|
|
|
|
* optimize these away.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t load_be32(const void *p)
|
|
|
|
|
{
|
2020-03-20 11:51:24 +08:00
|
|
|
|
uint32_t val;
|
|
|
|
|
memcpy(&val, p, sizeof val);
|
|
|
|
|
return ntohl(val);
|
2017-04-01 16:35:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t load_be16(const void *p)
|
|
|
|
|
{
|
2020-03-20 11:51:24 +08:00
|
|
|
|
uint16_t val;
|
|
|
|
|
memcpy(&val, p, sizeof val);
|
|
|
|
|
return ntohs(val);
|
2017-04-01 16:35:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t load_le32(const void *p)
|
|
|
|
|
{
|
2020-03-20 11:51:24 +08:00
|
|
|
|
const uint8_t *data = (const uint8_t *) p;
|
|
|
|
|
return data[0] | ((uint32_t) data[1] << 8) |
|
|
|
|
|
((uint32_t) data[2] << 16) | ((uint32_t) data[3] << 24);
|
2017-04-01 16:35:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t load_be24(const void *p)
|
|
|
|
|
{
|
2020-03-20 11:51:24 +08:00
|
|
|
|
const uint8_t *data = (const uint8_t *) p;
|
|
|
|
|
return data[2] | ((uint32_t) data[1] << 8) | ((uint32_t) data[0] << 16);
|
2017-04-01 16:35:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_be24(void *p, uint32_t val)
|
|
|
|
|
{
|
2020-03-20 11:51:24 +08:00
|
|
|
|
uint8_t *data = (uint8_t *) p;
|
|
|
|
|
data[0] = val >> 16;
|
|
|
|
|
data[1] = val >> 8;
|
|
|
|
|
data[2] = val;
|
2017-04-01 16:35:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_le32(void *p, uint32_t val)
|
|
|
|
|
{
|
2020-03-20 11:51:24 +08:00
|
|
|
|
uint8_t *data = (uint8_t *) p;
|
|
|
|
|
data[0] = val;
|
|
|
|
|
data[1] = val >> 8;
|
|
|
|
|
data[2] = val >> 16;
|
|
|
|
|
data[3] = val >> 24;
|
2017-04-01 16:35:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_be32(void *p, uint32_t val)
|
|
|
|
|
{
|
2020-03-20 11:51:24 +08:00
|
|
|
|
uint8_t *data = (uint8_t *) p;
|
|
|
|
|
data[3] = val;
|
|
|
|
|
data[2] = val >> 8;
|
|
|
|
|
data[1] = val >> 16;
|
|
|
|
|
data[0] = val >> 24;
|
2017-04-01 16:35:56 +08:00
|
|
|
|
}
|
|
|
|
|
|