| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <inttypes.h> |
| 6 #include <stdio.h> |
| 7 |
| 8 #include <sstream> |
| 9 #include <string> |
| 10 |
| 11 #include "base/macros.h" |
| 12 |
| 13 // Disable runtime include in generarated proto headers. |
| 14 #define PROTO_ZERO_NO_RUNTIME |
| 15 |
| 16 namespace tracing { |
| 17 namespace proto { |
| 18 |
| 19 class AppendOnlyProtoMessage { |
| 20 public: |
| 21 explicit AppendOnlyProtoMessage(); |
| 22 ~AppendOnlyProtoMessage(); |
| 23 |
| 24 std::string GetLastCall() { |
| 25 std::string str = last_.str(); |
| 26 last_.str(""); |
| 27 last_.clear(); |
| 28 return str; |
| 29 } |
| 30 |
| 31 protected: |
| 32 template <class T> |
| 33 void OpenNestedMessage(int field, T** message) { |
| 34 // In actual runtime message is constructing on pre-allocated memory. |
| 35 // Hence there is no need to delete the pointer after use. |
| 36 // In testing case we can sacrifice memory leak. |
| 37 *message = new T(); |
| 38 last_ << "message " << field; |
| 39 } |
| 40 void AppendTinyNumber(int field, int32_t value) { |
| 41 last_ << "tiny f" << field << " = " << value; |
| 42 } |
| 43 void AppendBool(int field, bool value) { |
| 44 last_ << "bool f" << field << " = " << (value ? "true" : "false"); |
| 45 } |
| 46 void AppendInt32(int field, int32_t value) { |
| 47 last_ << "int32 f" << field << " = " << value; |
| 48 } |
| 49 void AppendInt64(int field, int64_t value) { |
| 50 last_ << "int64 f" << field << " = " << value; |
| 51 } |
| 52 void AppendUint32(int field, uint32_t value) { |
| 53 last_ << "uint32 f" << field << " = " << value; |
| 54 } |
| 55 void AppendUint64(int field, uint64_t value) { |
| 56 last_ << "uint64 f" << field << " = " << value; |
| 57 } |
| 58 void AppendSint32(int field, int32_t value) { |
| 59 last_ << "sint32 f" << field << " = " << value; |
| 60 } |
| 61 void AppendSint64(int field, int64_t value) { |
| 62 last_ << "sint64 f" << field << " = " << value; |
| 63 } |
| 64 void AppendFixed32(int field, uint32_t value) { |
| 65 last_ << "fixed32 f" << field << " = " << value; |
| 66 } |
| 67 void AppendFixed64(int field, uint64_t value) { |
| 68 last_ << "fixed64 f" << field << " = " << value; |
| 69 } |
| 70 void AppendSfixed32(int field, int32_t value) { |
| 71 last_ << "sfixed32 f" << field << " = " << value; |
| 72 } |
| 73 void AppendSfixed64(int field, int64_t value) { |
| 74 last_ << "sfixed64 f" << field << " = " << value; |
| 75 } |
| 76 void AppendFloat(int field, float value) { |
| 77 last_ << "float f" << field << " = " << value; |
| 78 } |
| 79 void AppendDouble(int field, double value) { |
| 80 last_ << "double f" << field << " = " << value; |
| 81 } |
| 82 void AppendString(int field, const char* value) { |
| 83 last_ << "string f" << field << " = \"" << value << "\""; |
| 84 } |
| 85 void AppendBytes(int field, const uint8_t* data, size_t size) { |
| 86 last_ << "bytes f" << field << " = [" << size << "]"; |
| 87 } |
| 88 |
| 89 private: |
| 90 std::ostringstream last_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(AppendOnlyProtoMessage); |
| 93 }; |
| 94 |
| 95 AppendOnlyProtoMessage::AppendOnlyProtoMessage() { |
| 96 } |
| 97 |
| 98 AppendOnlyProtoMessage::~AppendOnlyProtoMessage() { |
| 99 } |
| 100 |
| 101 } |
| 102 } |
| OLD | NEW |