AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
FramePacket.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19#include <agxData/Frame.h>
20#include <agxData/BinaryData.h>
21#include <agx/Json.h>
23
24namespace 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:
65 StructuredMessage(const agx::String& uri, const agxJson::Value& header, agxData::BinaryData *binarySegment = nullptr);
66
68
70 void setUri(const agx::String& uri);
71 void setHeader(const agxJson::Value& header);
73
76
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:
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 {
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 //---------------------------------------------------------------
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
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}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXCORE_EXPORT
Node(const agx::Name &name, agx::Index id)
Buffer(const agx::Name &name, agx::Index id, BinaryData *data, const Format *format, size_t numElements, size_t byteOffset)
PartialBuffer(agxData::Frame::PartialBuffer *buffer)
EntityStorage(const agxData::Frame::EntityStorage *storage)
CustomBuffer(const agx::Name &name, agx::Index id, const Format *format, size_t numElements)
Value(const agx::Name &name, agx::Index id, BinaryData *data, const Format *format, size_t offset)
virtual ~FramePacket()
Definition: FramePacket.h:153
const agx::String & getUri() const
Definition: FramePacket.h:199
agx::UInt32 getPostHeaderPaddingSize() const
Definition: FramePacket.h:202
FramePacket(const agxData::Frame *frame)
agx::UInt32 getBinarySegmentOffset() const
Definition: FramePacket.h:196
const agx::String & getHeaderString() const
Definition: FramePacket.h:201
static agxData::Frame * parseFrame(agx::UInt8 *data, size_t size)
agx::UInt32 getBinarySegmentSize() const
Definition: FramePacket.h:197
const StructuredMessage::PreHeader & getPreHeader() const
Definition: FramePacket.h:195
const agxJson::Value & getHeader() const
Definition: FramePacket.h:200
static agxData::Frame * parseFrame(const agxJson::Value &eFrame, agxData::BinaryData *binaryData)
agx::UInt32 getMessageId() const
void setMessageId(agx::UInt32 id) const
agxJson::Value & getHeader()
Definition: FramePacket.h:188
StructuredMessage(const agx::String &uri)
agx::UInt32 getResponseId() const
void setHeader(const agxJson::Value &header)
StructuredMessage * createResponse() const
void setBinarySegment(agxData::BinaryData *binarySegment)
static StructuredMessage * parse(const agx::UInt8 *data, size_t numBytes, bool copyBinaryData=false)
const agx::String & getUri() const
Definition: FramePacket.h:187
void setUri(const agx::String &uri)
agx::UInt32 binarySegmentOffset
Definition: FramePacket.h:113
agxData::BinaryData * getBinarySegment()
Definition: FramePacket.h:191
StructuredMessage(const agx::String &uri, const agxJson::Value &header, agxData::BinaryData *binarySegment=nullptr)
void setResponseId(agx::UInt32 id)
agx::UInt32 binarySegmentSize
Definition: FramePacket.h:114
Base class providing referencing counted objects.
Definition: Referenced.h:120
#define AGX_FORCE_INLINE
Definition: macros.h:58
Containins classes for sending/reading data over sockets as well as compression functionality.
Definition: MacUtil.h:23
uint32_t UInt32
Definition: Integer.h:32
uint8_t UInt8
Definition: Integer.h:30