File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
src/tools/fdsdump/src/common Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 44
55#include < common/fieldView.hpp>
66
7+ #include < libfds/converters.h>
8+
79namespace fdsdump {
810
911uint64_t
@@ -115,4 +117,35 @@ FieldView::as_ipaddr() const
115117 throw std::invalid_argument (" Conversion error (ipaddr)" );
116118}
117119
120+ std::string
121+ FieldView::as_string () const
122+ {
123+ std::string value;
124+
125+ if (m_field.size > 0 ) {
126+ // &value[0] doesn't work for zero-sized strings, so we have to handle this specially
127+ value.resize (m_field.size );
128+ int ret = fds_get_string (m_field.data , m_field.size , &value[0 ]);
129+ if (ret != FDS_OK) {
130+ throw std::invalid_argument (" Conversion error (string)" );
131+ }
132+ }
133+
134+ return value;
135+ }
136+
137+ std::vector<uint8_t >
138+ FieldView::as_bytes () const
139+ {
140+ std::vector<uint8_t > value;
141+
142+ value.resize (m_field.size );
143+ int ret = fds_get_octet_array (m_field.data , m_field.size , value.data ());
144+ if (ret != FDS_OK) {
145+ throw std::invalid_argument (" Conversion error (bytes)" );
146+ }
147+
148+ return value;
149+ }
150+
118151} // fdsdump
Original file line number Diff line number Diff line change 11
22#pragma once
33
4+ #include < cstdint>
45#include < ctime>
6+ #include < string>
7+ #include < vector>
58
69#include < libfds.h>
710
@@ -21,6 +24,8 @@ class FieldView {
2124 struct timespec as_datetime () const ;
2225 uint64_t as_datetime_ms () const ;
2326 IPAddr as_ipaddr () const ;
27+ std::string as_string () const ;
28+ std::vector<uint8_t > as_bytes () const ;
2429
2530private:
2631 const struct fds_drec_field &m_field;
You can’t perform that action at this time.
0 commit comments