1//===-- CFCData.cpp -------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "CFCData.h"
10
11// CFCData constructor
12CFCData::CFCData(CFDataRef data) : CFCReleaser<CFDataRef>(data) {}
13
14// CFCData copy constructor
15CFCData::CFCData(const CFCData &rhs) = default;
16
17// CFCData copy constructor
18CFCData &CFCData::operator=(const CFCData &rhs)
19
20{
21 if (this != &rhs)
22 *this = rhs;
23 return *this;
24}
25
26// Destructor
27CFCData::~CFCData() = default;
28
29CFIndex CFCData::GetLength() const {
30 CFDataRef data = get();
31 if (data)
32 return CFDataGetLength(data);
33 return 0;
34}
35
36const uint8_t *CFCData::GetBytePtr() const {
37 CFDataRef data = get();
38 if (data)
39 return CFDataGetBytePtr(data);
40 return NULL;
41}
42
43CFDataRef CFCData::Serialize(CFPropertyListRef plist,
44 CFPropertyListFormat format) {
45 CFAllocatorRef alloc = kCFAllocatorDefault;
46 reset();
47 CFCReleaser<CFWriteStreamRef> stream(
48 ::CFWriteStreamCreateWithAllocatedBuffers(alloc, alloc));
49 ::CFWriteStreamOpen(stream.get());
50 CFIndex len = ::CFPropertyListWrite(plist, stream.get(), format, 0, nullptr);
51 if (len > 0)
52 reset((CFDataRef)::CFWriteStreamCopyProperty(stream.get(),
53 kCFStreamPropertyDataWritten));
54 ::CFWriteStreamClose(stream.get());
55 return get();
56}
57

source code of lldb/source/Host/macosx/cfcpp/CFCData.cpp