dynamic-uint8-array-lite.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_DYNAMIC_UINT8_ARRAY_LITE_HPP
23 #define NDN_DYNAMIC_UINT8_ARRAY_LITE_HPP
24 
25 #include "../../c/errors.h"
26 #include "../../c/util/dynamic-uint8-array-types.h"
27 
28 namespace ndn {
29 
36 public:
45  (uint8_t *array, size_t length, ndn_ReallocFunction reallocFunction);
46 
51  uint8_t*
52  getArray() { return array; }
53 
54  const uint8_t*
55  getArray() const { return array; }
56 
61  size_t
62  getLength() const { return length; }
63 
74  ndn_Error
75  ensureLength(size_t length);
76 
86  ndn_Error
87  copy(const uint8_t *value, size_t valueLength, size_t offset);
88 
99  ndn_Error
100  ensureLengthFromBack(size_t length);
101 
113  ndn_Error
114  copyFromBack(const uint8_t *value, size_t valueLength, size_t offsetFromBack);
115 
122  static DynamicUInt8ArrayLite&
124  {
125  return *(DynamicUInt8ArrayLite*)&dynamicArray;
126  }
127 
128  static const DynamicUInt8ArrayLite&
129  downCast(const ndn_DynamicUInt8Array& dynamicArray)
130  {
131  return *(DynamicUInt8ArrayLite*)&dynamicArray;
132  }
133 
134 private:
135  // Declare friends who can downcast to the private base.
136  friend class TcpTransportLite;
137  friend class UdpTransportLite;
138  friend class UnixTransportLite;
139  friend class ArduinoYunTcpTransportLite;
140  friend class Tlv0_1_1WireFormatLite;
141 };
142 
143 }
144 
145 #endif
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
A DynamicUInt8ArrayLite holds a pointer to an allocated array, the length of the allocated array...
Definition: dynamic-uint8-array-lite.hpp:35
ndn_Error ensureLengthFromBack(size_t length)
Ensure that getLength() is greater than or equal to the given length.
Definition: dynamic-uint8-array-lite.cpp:47
ndn_Error ensureLength(size_t length)
Ensure that getLength() is greater than or equal to length.
Definition: dynamic-uint8-array-lite.cpp:34
A struct ndn_DynamicUInt8Array holds a pointer to an allocated array, the length of the allocated arr...
Definition: dynamic-uint8-array-types.h:40
DynamicUInt8ArrayLite(uint8_t *array, size_t length, ndn_ReallocFunction reallocFunction)
Create a DynamicUInt8ArrayLite with the given array buffer.
Definition: dynamic-uint8-array-lite.cpp:28
size_t length
the length of the allocated array buffer
Definition: dynamic-uint8-array-types.h:42
ndn_Error copyFromBack(const uint8_t *value, size_t valueLength, size_t offsetFromBack)
First call ensureLengthFromBack to make sure this object's array has offsetFromBack bytes...
Definition: dynamic-uint8-array-lite.cpp:54
uint8_t * getArray()
Get the current allocated array.
Definition: dynamic-uint8-array-lite.hpp:52
ndn_Error copy(const uint8_t *value, size_t valueLength, size_t offset)
Copy value into this object's array at offset, using ensureLength to make sure the array has enough l...
Definition: dynamic-uint8-array-lite.cpp:41
size_t getLength() const
Get the current length of the allocated array.
Definition: dynamic-uint8-array-lite.hpp:62
uint8_t * array
the allocated array buffer
Definition: dynamic-uint8-array-types.h:41
static DynamicUInt8ArrayLite & downCast(ndn_DynamicUInt8Array &dynamicArray)
Downcast the reference to the ndn_DynamicUInt8ArrayLite struct to a DynamicUInt8ArrayLiteLite.
Definition: dynamic-uint8-array-lite.hpp:123