gwnavruntime/visualdebug/amp/Amp_Stream.h Source File

Amp_Stream.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 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 #ifndef INC_KY_AMP_STREAM_H
17 #define INC_KY_AMP_STREAM_H
18 
20 
21 namespace Kaim {
22 namespace Net {
23 namespace AMP {
24 
25 // Custom stream class used to send messages across the network
26 // The size of each message precedes the data so we can split messages into
27 // packets and reconstruct them after they have been received on the other end
28 //
29 // The data are stored as a Little-endian array of bytes
30 // The object normally holds only one message for write operations
31 // because the first four bytes are used to hold the message size
32 // For read operations, multiple messages can be contained on the stream
33 // After a message has been processed, PopFirstMessage is called to remove it
34 class AmpStream : public File
35 {
36 public:
37  // Default constructor (for writing a new message)
38  AmpStream();
39  // Buffer constructor (for parsing a received message)
40  AmpStream(const UByte* buffer, UPInt bufferSize);
41 
42  // File virtual method overrides
43  virtual const char* GetFilePath() { return ""; }
44  virtual bool IsValid() { return true; }
45  virtual bool IsWritable() { return true; }
46  virtual int Tell ();
47  virtual SInt64 LTell () { return Tell(); }
48  virtual int GetLength () { return static_cast<int>(Data.GetSize()); }
49  virtual SInt64 LGetLength () { return GetLength(); }
50  virtual int GetErrorCode() { return 0; }
51  virtual bool Flush() { return true; }
52  virtual bool Close() { return false; }
53  virtual int Write(const UByte *pbufer, int numBytes);
54  virtual int Read(UByte *pbufer, int numBytes);
55  virtual int SkipBytes(int numBytes);
56  virtual int BytesAvailable();
57  virtual int Seek(int offset, int origin=Seek_Set);
58  virtual SInt64 LSeek(SInt64 offset, int origin=Seek_Set);
59  virtual bool ChangeSize(int newSize);
60  virtual int CopyFromStream(File *pstream, int byteSize);
61 
62  // Serialization
63  void Read(File& str);
64  void Write(File& str) const;
65 
66  // Append an buffer that is already in the AmpStream format
67  void Append(const UByte* buffer, UPInt bufferSize);
68 
69  // Data accessors
70  const UByte* GetBuffer() const;
71  UPInt GetBufferSize() const;
72 
73  // Clear the stream
74  void Clear();
75 
76  // Set the current read position to the beginning
77  void Rewind();
78 
79  // Message retrieval methods
80  UPInt FirstMessageSize();
81  bool PopFirstMessage();
82 
83 private:
84  typedef ArrayConstPolicy<0, 4, true> NeverShrinkPolicy;
85  ArrayLH<UByte, Stat_Default_Mem, NeverShrinkPolicy> Data;
86  int readPosition; // next location to be read
87 
88  // Update the header with the message size
89  // Assumes that there is only one message currently in the stream
90  void IncreaseMessageSize(UInt32 newSize);
91 };
92 
93 } // namespace AMP
94 } // namespace Net
95 } // namespace Kaim
96 
97 
98 #endif
Definition: gamekitcrowddispersion.h:20