gwnavruntime/visualdebug/amp/Amp_Stream.h Source File

Amp_Stream.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 /**************************************************************************
8 
9 Filename : Amp_Stream.h
10 Content : Stream used by AMP to serialize messages
11 Created : December 2009
12 Authors : Alex Mantzaris
13 
14 **************************************************************************/
15 
16 #pragma once
17 
19 
20 namespace Kaim {
21 namespace Net {
22 namespace AMP {
23 
24 // Custom stream class used to send messages across the network
25 // The size of each message precedes the data so we can split messages into
26 // packets and reconstruct them after they have been received on the other end
27 //
28 // The data are stored as a Little-endian array of bytes
29 // The object normally holds only one message for write operations
30 // because the first four bytes are used to hold the message size
31 // For read operations, multiple messages can be contained on the stream
32 // After a message has been processed, PopFirstMessage is called to remove it
33 class AmpStream : public File
34 {
35 public:
36  // Default constructor (for writing a new message)
37  AmpStream();
38  // Buffer constructor (for parsing a received message)
39  AmpStream(const UByte* buffer, UPInt bufferSize);
40 
41  // File virtual method overrides
42  virtual const char* GetFilePath() { return ""; }
43  virtual bool IsValid() { return true; }
44  virtual bool IsWritable() { return true; }
45  virtual int Tell ();
46  virtual SInt64 LTell () { return Tell(); }
47  virtual int GetLength () { return static_cast<int>(Data.GetSize()); }
48  virtual SInt64 LGetLength () { return GetLength(); }
49  virtual int GetErrorCode() { return 0; }
50  virtual bool Flush() { return true; }
51  virtual bool Close() { return false; }
52  virtual int Write(const UByte *pbufer, int numBytes);
53  virtual int Read(UByte *pbufer, int numBytes);
54  virtual int SkipBytes(int numBytes);
55  virtual int BytesAvailable();
56  virtual int Seek(int offset, int origin=Seek_Set);
57  virtual SInt64 LSeek(SInt64 offset, int origin=Seek_Set);
58  virtual bool ChangeSize(int newSize);
59  virtual int CopyFromStream(File *pstream, int byteSize);
60 
61  // Serialization
62  void Read(File& str);
63  void Write(File& str) const;
64 
65  // Append an buffer that is already in the AmpStream format
66  void Append(const UByte* buffer, UPInt bufferSize);
67 
68  // Data accessors
69  const UByte* GetBuffer() const;
70  UPInt GetBufferSize() const;
71 
72  // Clear the stream
73  void Clear();
74 
75  // Set the current read position to the beginning
76  void Rewind();
77 
78  // Message retrieval methods
79  UPInt FirstMessageSize();
80  bool PopFirstMessage();
81 
82 private:
83  typedef ArrayConstPolicy<0, 4, true> NeverShrinkPolicy;
84  ArrayLH<UByte, Stat_Default_Mem, NeverShrinkPolicy> Data;
85  int readPosition; // next location to be read
86 
87  // Update the header with the message size
88  // Assumes that there is only one message currently in the stream
89  void IncreaseMessageSize(UInt32 newSize);
90 };
91 
92 } // namespace AMP
93 } // namespace Net
94 } // namespace Kaim
95 
96 
std::int64_t SInt64
int64_t
Definition: SF_Types.h:132
std::uint8_t UByte
uint8_t
Definition: SF_Types.h:134
std::uint32_t UInt32
uint32_t
Definition: SF_Types.h:137
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17