Skip to content

Commit

Permalink
Add DebugString() for Attributes class. (envoyproxy#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiwzhang authored Jan 30, 2017
1 parent 73376d5 commit cfd37bb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mixerclient/include/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ struct Attributes {
};

std::map<std::string, Value> attributes;

// Generates a string for logging or debugging.
std::string DebugString() const;
};

class MixerClient {
Expand Down
33 changes: 33 additions & 0 deletions mixerclient/src/client_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* limitations under the License.
*/
#include "src/client_impl.h"
#include <sstream>
#include "mixer/api/v1/service.pb.h"

using ::istio::mixer::v1::CheckResponse;
Expand Down Expand Up @@ -71,5 +72,37 @@ std::unique_ptr<MixerClient> CreateMixerClient(
return std::unique_ptr<MixerClient>(new MixerClientImpl(options));
}

std::string Attributes::DebugString() const {
std::stringstream ss;
for (const auto &it : attributes) {
ss << it.first << ": ";
switch (it.second.type) {
case Attributes::Value::ValueType::STRING:
ss << "(STRING): " << it.second.str_v;
break;
case Attributes::Value::ValueType::BYTES:
ss << "(BYTES): " << it.second.str_v;
break;
case Attributes::Value::ValueType::INT64:
ss << "(INT64): " << it.second.value.int64_v;
break;
case Attributes::Value::ValueType::DOUBLE:
ss << "(DOUBLE): " << it.second.value.double_v;
break;
case Attributes::Value::ValueType::BOOL:
ss << "(BOOL): " << it.second.value.bool_v;
break;
case Attributes::Value::ValueType::TIME:
ss << "(TIME ms): "
<< std::chrono::duration_cast<std::chrono::microseconds>(
it.second.time_v.time_since_epoch())
.count();
break;
}
ss << std::endl;
}
return ss.str();
}

} // namespace mixer_client
} // namespace istio

0 comments on commit cfd37bb

Please sign in to comment.