-
Notifications
You must be signed in to change notification settings - Fork 232
/
Copy pathHAPBitSet.c
41 lines (30 loc) · 1.3 KB
/
HAPBitSet.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) 2015-2019 The HomeKit ADK Contributors
//
// Licensed under the Apache License, Version 2.0 (the “License”);
// you may not use this file except in compliance with the License.
// See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
#undef HAP_DISALLOW_USE_IGNORED
#define HAP_DISALLOW_USE_IGNORED 1
#include "HAP+Internal.h"
HAP_RESULT_USE_CHECK
bool HAPBitSetContainsInternal(const uint8_t* bitSet, size_t numBytes, uint8_t bitIndex) {
HAPPrecondition(bitSet);
size_t byteIndex = bitIndex / CHAR_BIT;
HAPPrecondition(byteIndex < numBytes);
uint8_t bitMask = (uint8_t)(1u << (uint8_t)(bitIndex % CHAR_BIT));
return bitSet[byteIndex] & bitMask;
}
void HAPBitSetInsertInternal(uint8_t* bitSet, size_t numBytes, uint8_t bitIndex) {
HAPPrecondition(bitSet);
size_t byteIndex = bitIndex / CHAR_BIT;
HAPPrecondition(byteIndex < numBytes);
uint8_t bitMask = (uint8_t)(1u << (uint8_t)(bitIndex % CHAR_BIT));
bitSet[byteIndex] |= bitMask;
}
void HAPBitSetRemoveInternal(uint8_t* bitSet, size_t numBytes, uint8_t bitIndex) {
HAPPrecondition(bitSet);
size_t byteIndex = bitIndex / CHAR_BIT;
HAPPrecondition(byteIndex < numBytes);
uint8_t bitMask = (uint8_t)(1u << (uint8_t)(bitIndex % CHAR_BIT));
bitSet[byteIndex] &= (uint8_t) ~bitMask;
}