libptpmgmt 2.0
libptpmgmt library that provides the functionality of linuxptp pmc
Loading...
Searching...
No Matches
bin.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-3.0-or-later
2 SPDX-FileCopyrightText: Copyright © 2021 Erez Geva <ErezGeva2@gmail.com> */
3
12#ifndef __PTPMGMT_BIN_H
13#define __PTPMGMT_BIN_H
14
15#ifdef __cplusplus
16#include "name.h"
17
18__PTPMGMT_NAMESPACE_BEGIN
19
20const size_t EUI48 = 6;
21const size_t EUI64 = 8;
26class Binary
27{
28 private:
29 uint8_t *m_buf = nullptr; /* Used buffer */
30 size_t m_alloc = 0; /* Allocation size */
31 size_t m_size = 0; /* Binary size */
32 bool iResize(size_t newAllocSize);
33 public:
34 Binary();
35 ~Binary();
40 Binary(const Binary &rhs);
41 #ifndef SWIG
46 Binary(Binary &&rhs);
47 #endif /* SWIG */
53 Binary(const void *buf, const size_t length);
59 Binary(const size_t length, uint8_t set = 0);
66 Binary(const std::string &string);
72 Binary &operator=(const Binary &rhs);
77 size_t length() const;
82 size_t size() const;
87 bool empty() const;
92 const uint8_t *get() const;
99 std::string getBinString() const;
106 Binary &setBin(const void *buf, const size_t length);
112 Binary &setBin(const Binary &rhs);
120 Binary &setBin(const std::string &string);
128 Binary &setBin(const size_t position, const uint8_t value);
135 #ifndef SWIG
142 #endif /* SWIG */
148 const uint8_t getBin(const size_t position) const;
155 uint8_t &operator [](const size_t position);
160 Binary &resize(const size_t length);
169 void copy(uint8_t *target) const;
176 Binary &operator += (const uint8_t octet) { return append(octet); }
182 Binary &append(const uint8_t octet);
189 Binary &operator += (const Binary &rhs) { return append(rhs); }
195 Binary &append(const Binary &rhs);
203 std::string toIp() const;
210 bool fromIp(const std::string &string);
218 bool fromIp(const std::string &string, int domain);
225 std::string toId(const std::string &sep = ":") const;
234 static std::string bufToId(const uint8_t *id, size_t length,
235 const std::string &sep = ":");
242 bool fromId(const std::string &string);
248 bool fromMac(const std::string &string);
253 bool isMacLen() const;
264 bool fromHex(const std::string &hex);
269 std::string toHex() const;
276 static std::string bufToHex(const uint8_t *bin, size_t length);
288 bool fromBase64(const std::string &bin64, bool pad = false);
299 std::string toBase64(bool pad = true, char v62 = '+', char v63 = '/') const;
305 bool operator==(const Binary &rhs) const { return eq(rhs); }
311 bool eq(const Binary &rhs) const;
317 bool operator<(const Binary &rhs) const { return less(rhs); }
323 bool less(const Binary &rhs) const;
324};
325
326__PTPMGMT_NAMESPACE_END
327#else /* __cplusplus */
328#error "this header is for C++ and scripts use only, NOT for C"
329#endif /* __cplusplus */
330
331#endif /* __PTPMGMT_BIN_H */
__PTPMGMT_NAMESPACE_BEGIN const size_t EUI48
Definition bin.h:20
const size_t EUI64
Definition bin.h:21
Definition bin.h:27
Binary & operator=(const Binary &rhs)
Binary & operator+=(const uint8_t octet)
Definition bin.h:176
std::string toHex() const
uint8_t & operator[](const size_t position)
Binary & mvBin(Binary &rhs)
static std::string bufToId(const uint8_t *id, size_t length, const std::string &sep=":")
std::string getBinString() const
std::string toId(const std::string &sep=":") const
static std::string bufToHex(const uint8_t *bin, size_t length)
Binary & append(const Binary &rhs)
Binary & append(const uint8_t octet)
bool fromMac(const std::string &string)
bool fromBase64(const std::string &bin64, bool pad=false)
Binary(const std::string &string)
const uint8_t * get() const
bool fromIp(const std::string &string, int domain)
Binary & setBin(const Binary &rhs)
size_t size() const
Binary(const size_t length, uint8_t set=0)
bool isMacLen() const
bool fromHex(const std::string &hex)
bool eq(const Binary &rhs) const
bool fromIp(const std::string &string)
Binary(const void *buf, const size_t length)
Binary & mvBin(Binary &&rhs)
size_t length() const
const uint8_t getBin(const size_t position) const
bool fromId(const std::string &string)
Binary(const Binary &rhs)
Binary & resize(const size_t length)
void copy(uint8_t *target) const
bool empty() const
std::string toIp() const
Binary & setBin(const void *buf, const size_t length)
bool operator<(const Binary &rhs) const
Definition bin.h:317
bool eui48ToEui64()
bool operator==(const Binary &rhs) const
Definition bin.h:305
Binary(Binary &&rhs)
std::string toBase64(bool pad=true, char v62='+', char v63='/') const
bool less(const Binary &rhs) const
Binary & setBin(const std::string &string)
Binary & clear()
Binary & setBin(const size_t position, const uint8_t value)
Define name space.