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 protected:
141  void
142  setArrayAndLength(uint8_t *array, size_t length)
143  {
144  this->array = array;
145  this->length = length;
146  }
147 
148 private:
149  // Declare friends who can downcast to the private base.
150  friend class TcpTransportLite;
151  friend class UdpTransportLite;
152  friend class UnixTransportLite;
153  friend class ArduinoYunTcpTransportLite;
154  friend class Tlv0_2WireFormatLite;
155 };
156 
157 }
158 
159 #endif
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:36
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
Definition: unix-transport-lite.hpp:32
A Tlv0_2WireFormatLite implements implement encoding and decoding using NDN-TLV version 0...
Definition: tlv-0_2-wire-format-lite.hpp:41
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_DynamicUInt8Array struct to a DynamicUInt8ArrayLite.
Definition: dynamic-uint8-array-lite.hpp:123
void setArrayAndLength(uint8_t *array, size_t length)
Set the array and length.
Definition: dynamic-uint8-array-lite.hpp:142
Definition: udp-transport-lite.hpp:32
Definition: tcp-transport-lite.hpp:32