AGXDynamics  2.35.0.3
FramePacket.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #pragma once
18 
19 #include <agxData/Frame.h>
20 #include <agxData/BinaryData.h>
21 #include <agx/Json.h>
23 
24 namespace agxNet
25 {
26 
56  {
57  public:
58  struct PreHeader;
59  static const agx::UInt32 BINARY_SEGMENT_ALIGNMENT = 32;
60 
61  static StructuredMessage* parse(const agx::UInt8* data, size_t numBytes, bool copyBinaryData = false);
62  public:
64  StructuredMessage(const agx::String& uri);
65  StructuredMessage(const agx::String& uri, const agxJson::Value& header, agxData::BinaryData *binarySegment = nullptr);
66 
67  StructuredMessage *createResponse() const;
68 
69  void setResponseId(agx::UInt32 id);
70  void setUri(const agx::String& uri);
71  void setHeader(const agxJson::Value& header);
72  void setBinarySegment(agxData::BinaryData *binarySegment);
73 
75  agx::UInt32 getMessageId() const;
76 
78  agx::UInt32 getResponseId() const;
79 
80  const agx::String& getUri() const;
81 
82  agxJson::Value& getHeader();
83  const agxJson::Value& getHeader() const;
84 
85  agxData::BinaryData *getBinarySegment();
86  const agxData::BinaryData *getBinarySegment() const;
87 
88  // PreHeader getPreHeader() const;
89 
90  protected:
91  virtual ~StructuredMessage();
92 
93  friend class WebSocket;
94  void setMessageId( agx::UInt32 id ) const;
95 
96  private:
97  agx::String m_uri;
98  agxJson::Value m_header;
99  agxData::BinaryDataRef m_binarySegment;
100  agx::UInt32 m_messageId;
101  agx::UInt32 m_responseId;
102  };
103 
104  // Used for parsing a structured message
105  struct AGXCORE_EXPORT StructuredMessage::PreHeader
106  {
107  PreHeader();
108 
115 
116  static const agx::UInt32 STREAM_END_OF_FILE = 0;
117  };
118 
119 
120 
121 
122 
123 
124 
125 
128  {
129  public:
130  FramePacket(const agxData::Frame* frame);
131 
133  const StructuredMessage::PreHeader& getPreHeader() const;
134 
136  agx::UInt32 getBinarySegmentOffset() const;
137 
139  agx::UInt32 getBinarySegmentSize() const;
140 
141  const agx::String& getUri() const;
142  const agxJson::Value& getHeader() const;
143  const agx::String& getHeaderString() const;
144 
146  agx::UInt32 getPostHeaderPaddingSize() const;
147 
148 
149  static agxData::Frame* parseFrame(agx::UInt8* data, size_t size);
150  static agxData::Frame* parseFrame(const agxJson::Value& eFrame, agxData::BinaryData* binaryData);
151 
152  protected:
153  virtual ~FramePacket() {}
154 
155  private:
156  // agxJson::Value& createNode(agxJson::Value& eParent, const char *componentName);
157 
158  void addChildren(agxJson::Value& eParent, agxData::SerializedFrame::Component *component);
159 
160  void add(agxJson::Value& eParent, agxData::SerializedFrame::Node *node);
161  void add(agxJson::Value& eParent, agxData::SerializedFrame::Component *component);
162  void add(agxJson::Value& eParent, agxData::SerializedFrame::Value *value);
163  void add(agxJson::Value& eParent, agxData::SerializedFrame::Buffer *buffer);
164  void add(agxJson::Value& eParent, agxData::SerializedFrame::CustomBuffer *buffer);
165  void add(agxJson::Value& eParent, agxData::SerializedFrame::PartialBuffer *buffer);
166  void add(agxJson::Value& eParent, agxData::SerializedFrame::EntityStorage *storage);
167 
168  static agxData::SerializedFrame::Component *createComponent(const agxJson::Value& eComponent, agxData::BinaryData *binaryData);
169  static agxData::SerializedFrame::Node *createStorage(const agxJson::Value& eStorage, agxData::BinaryData *binaryData);
170  static agxData::SerializedFrame::Node *createBuffer(const agxJson::Value& eBuffer, agxData::BinaryData *binaryData);
171  static agxData::SerializedFrame::Node *createValue(const agxJson::Value& eValue, agxData::BinaryData *binaryData);
172  static void addChildren(agxData::SerializedFrame::Component *parent, const agxJson::Value& eComponent, agxData::BinaryData *binaryData);
173 
174 
175  private:
176  StructuredMessage::PreHeader m_preHeader;
177  agxJson::Value m_header;
178  agx::String m_uri;
179  agx::String m_headerString;
180  agx::UInt32 m_postHeaderPaddingSize;
181  };
182 
183 
184  /* Implementation */
185 
186  //---------------------------------------------------------------
187  AGX_FORCE_INLINE const agx::String& StructuredMessage::getUri() const { return m_uri; }
188  AGX_FORCE_INLINE agxJson::Value& StructuredMessage::getHeader() { return m_header; }
189  AGX_FORCE_INLINE const agxJson::Value& StructuredMessage::getHeader() const { return m_header; }
190 
192  AGX_FORCE_INLINE const agxData::BinaryData *StructuredMessage::getBinarySegment() const { return m_binarySegment; }
193 
194  //---------------------------------------------------------------
196  AGX_FORCE_INLINE agx::UInt32 FramePacket::getBinarySegmentOffset() const { return m_preHeader.binarySegmentOffset; }
197  AGX_FORCE_INLINE agx::UInt32 FramePacket::getBinarySegmentSize() const { return m_preHeader.binarySegmentSize; }
198 
199  AGX_FORCE_INLINE const agx::String& FramePacket::getUri() const { return m_uri; }
200  AGX_FORCE_INLINE const agxJson::Value& FramePacket::getHeader() const { return m_header; }
201  AGX_FORCE_INLINE const agx::String& FramePacket::getHeaderString() const { return m_headerString; }
202  AGX_FORCE_INLINE agx::UInt32 FramePacket::getPostHeaderPaddingSize() const { return m_postHeaderPaddingSize; }
203 
204 }
agxNet::FramePacket::getHeader
const agxJson::Value & getHeader() const
Definition: FramePacket.h:200
AGXCORE_EXPORT
#define AGXCORE_EXPORT
agxNet::StructuredMessage::headerSize
agx::UInt32 headerSize
Definition: FramePacket.h:112
agxNet::FramePacket::getPostHeaderPaddingSize
agx::UInt32 getPostHeaderPaddingSize() const
Definition: FramePacket.h:202
agxNet::FramePacket::getUri
const agx::String & getUri() const
Definition: FramePacket.h:199
agxData::SerializedFrame
Definition: SerializedFrame.h:41
agxNet::StructuredMessage::binarySegmentOffset
agx::UInt32 binarySegmentOffset
Definition: FramePacket.h:113
agxNet::FramePacket::getHeaderString
const agx::String & getHeaderString() const
Definition: FramePacket.h:201
agxNet::FramePacket::getPreHeader
const StructuredMessage::PreHeader & getPreHeader() const
Definition: FramePacket.h:195
agxData::SerializedFrame::EntityStorage
EntityStorage(const agxData::Frame::EntityStorage *storage)
SerializedFrame.h
agxNet::StructuredMessage::PreHeader
PreHeader()
agxNet::FramePacket
Definition: FramePacket.h:127
agx::ref_ptr< BinaryData >
agx::UInt8
uint8_t UInt8
Definition: Integer.h:38
agxNet::StructuredMessage::binarySegmentSize
agx::UInt32 binarySegmentSize
Definition: FramePacket.h:114
agxNet::StructuredMessage::getHeader
agxJson::Value & getHeader()
Definition: FramePacket.h:188
agxNet::StructuredMessage::uriSize
agx::UInt32 uriSize
Definition: FramePacket.h:111
agxData::SerializedFrame::CustomBuffer
CustomBuffer(const agx::Name &name, agx::Index id, const Format *format, size_t numElements)
agxData::SerializedFrame::Component
friend class Component
Definition: SerializedFrame.h:457
agxNet::StructuredMessage::getBinarySegment
agxData::BinaryData * getBinarySegment()
Definition: FramePacket.h:191
agxData::SerializedFrame::PartialBuffer
PartialBuffer(agxData::Frame::PartialBuffer *buffer)
agxData::BinaryData
Definition: BinaryData.h:33
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:113
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
agxData::SerializedFrame::Node
Node(const agx::Name &name, agx::Index id)
agxNet::FramePacket::getBinarySegmentSize
agx::UInt32 getBinarySegmentSize() const
Definition: FramePacket.h:197
agxData::SerializedFrame::Buffer
Buffer(const agx::Name &name, agx::Index id, BinaryData *data, const Format *format, size_t numElements, size_t byteOffset)
agxNet::FramePacket::getBinarySegmentOffset
agx::UInt32 getBinarySegmentOffset() const
Definition: FramePacket.h:196
agxNet::StructuredMessage::id
agx::UInt32 id
Definition: FramePacket.h:109
BinaryData.h
agxNet::FramePacket::~FramePacket
virtual ~FramePacket()
Definition: FramePacket.h:153
agx::AgXString< std::string >
agxData::SerializedFrame::Value
Value(const agx::Name &name, agx::Index id, BinaryData *data, const Format *format, size_t offset)
Frame.h
Json.h
agx::UInt32
uint32_t UInt32
Definition: Integer.h:40
agxNet::StructuredMessage::responseId
agx::UInt32 responseId
Definition: FramePacket.h:110
agxNet::StructuredMessage::getUri
const agx::String & getUri() const
Definition: FramePacket.h:187
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agxNet
Containins classes for sending/reading data over sockets as well as compression functionality.
Definition: MacUtil.h:22
agxNet::StructuredMessage
Definition: FramePacket.h:55