OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" | 11 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" |
| 12 #include "webrtc/typedefs.h" |
12 | 13 |
13 namespace webrtc { | 14 namespace webrtc { |
14 | 15 |
15 size_t ReadMessageBytesFromFile(FILE* file, rtc::scoped_ptr<uint8_t[]>* bytes) { | 16 size_t ReadMessageBytesFromFile(FILE* file, std::unique_ptr<uint8_t[]>* bytes) { |
16 // The "wire format" for the size is little-endian. Assume we're running on | 17 // The "wire format" for the size is little-endian. Assume we're running on |
17 // a little-endian machine. | 18 // a little-endian machine. |
18 #ifndef WEBRTC_ARCH_LITTLE_ENDIAN | 19 #ifndef WEBRTC_ARCH_LITTLE_ENDIAN |
19 #error "Need to convert messsage from little-endian." | 20 #error "Need to convert messsage from little-endian." |
20 #endif | 21 #endif |
21 int32_t size = 0; | 22 int32_t size = 0; |
22 if (fread(&size, sizeof(size), 1, file) != 1) | 23 if (fread(&size, sizeof(size), 1, file) != 1) |
23 return 0; | 24 return 0; |
24 if (size <= 0) | 25 if (size <= 0) |
25 return 0; | 26 return 0; |
26 | 27 |
27 bytes->reset(new uint8_t[size]); | 28 bytes->reset(new uint8_t[size]); |
28 return fread(bytes->get(), sizeof((*bytes)[0]), size, file); | 29 return fread(bytes->get(), sizeof((*bytes)[0]), size, file); |
29 } | 30 } |
30 | 31 |
31 // Returns true on success, false on error or end-of-file. | 32 // Returns true on success, false on error or end-of-file. |
32 bool ReadMessageFromFile(FILE* file, ::google::protobuf::MessageLite* msg) { | 33 bool ReadMessageFromFile(FILE* file, ::google::protobuf::MessageLite* msg) { |
33 rtc::scoped_ptr<uint8_t[]> bytes; | 34 std::unique_ptr<uint8_t[]> bytes; |
34 size_t size = ReadMessageBytesFromFile(file, &bytes); | 35 size_t size = ReadMessageBytesFromFile(file, &bytes); |
35 if (!size) | 36 if (!size) |
36 return false; | 37 return false; |
37 | 38 |
38 msg->Clear(); | 39 msg->Clear(); |
39 return msg->ParseFromArray(bytes.get(), size); | 40 return msg->ParseFromArray(bytes.get(), size); |
40 } | 41 } |
41 | 42 |
42 } // namespace webrtc | 43 } // namespace webrtc |
OLD | NEW |