summaryrefslogtreecommitdiffstats
path: root/lldb/tools/debugserver/source/MacOSX/CFData.cpp
blob: 94c93da544a4ed5a8f8464cd4c1e96bb36ec1cc6 (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//===-- CFData.cpp ----------------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  Created by Greg Clayton on 1/16/08.
//
//===----------------------------------------------------------------------===//

#include "CFData.h"

//----------------------------------------------------------------------
// CFData constructor
//----------------------------------------------------------------------
CFData::CFData(CFDataRef data) :
    CFReleaser<CFDataRef>(data)
{

}

//----------------------------------------------------------------------
// CFData copy constructor
//----------------------------------------------------------------------
CFData::CFData(const CFData& rhs) :
    CFReleaser<CFDataRef>(rhs)
{

}

//----------------------------------------------------------------------
// CFData copy constructor
//----------------------------------------------------------------------
CFData&
CFData::operator=(const CFData& rhs)

{
    *this = rhs;
    return *this;
}

//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
CFData::~CFData()
{
}


CFIndex
CFData::GetLength() const
{
    CFDataRef data = get();
    if (data)
        return CFDataGetLength (data);
    return 0;
}


const uint8_t*
CFData::GetBytePtr() const
{
    CFDataRef data = get();
    if (data)
        return CFDataGetBytePtr (data);
    return NULL;
}

CFDataRef
CFData::Serialize(CFPropertyListRef plist, CFPropertyListFormat format)
{
    CFAllocatorRef alloc = kCFAllocatorDefault;
    reset();
    CFReleaser<CFWriteStreamRef> stream (::CFWriteStreamCreateWithAllocatedBuffers (alloc, alloc));
    ::CFWriteStreamOpen (stream.get());
    CFIndex len = ::CFPropertyListWriteToStream (plist, stream.get(), format, NULL);
    if (len > 0)
        reset((CFDataRef)::CFWriteStreamCopyProperty (stream.get(), kCFStreamPropertyDataWritten));
    ::CFWriteStreamClose (stream.get());
    return get();
}

OpenPOWER on IntegriCloud