Panda3D
 All Classes Functions Variables Enumerations
ioPtaDatagramShort.cxx
1 // Filename: ioPtaDatagramShort.cxx
2 // Created by: jason (26Jun00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "pandabase.h"
16 
17 #include "ioPtaDatagramShort.h"
18 #include "datagram.h"
19 #include "datagramIterator.h"
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: IoPtaDatagramShort::write_datagram
23 // Access: Public, Static
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 void IoPtaDatagramShort::
27 write_datagram(BamWriter *, Datagram &dest, CPTA_ushort array) {
28  dest.add_uint32(array.size());
29  for(int i = 0; i < (int)array.size(); ++i) {
30  dest.add_uint16(array[i]);
31  }
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: IoPtaDatagramShort::read_datagram
36 // Access: Public, Static
37 // Description:
38 ////////////////////////////////////////////////////////////////////
39 PTA_ushort IoPtaDatagramShort::
40 read_datagram(BamReader *, DatagramIterator &source) {
41  PTA_ushort array;
42 
43  int size = source.get_uint32();
44  for(int i = 0; i < size; ++i) {
45  array.push_back(source.get_uint16());
46  }
47 
48  return array;
49 }
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
PN_uint32 get_uint32()
Extracts an unsigned 32-bit integer.
PN_uint16 get_uint16()
Extracts an unsigned 16-bit integer.
void add_uint16(PN_uint16 value)
Adds an unsigned 16-bit integer to the datagram.
Definition: datagram.I:181
void add_uint32(PN_uint32 value)
Adds an unsigned 32-bit integer to the datagram.
Definition: datagram.I:192
A class to retrieve the individual data elements previously stored in a Datagram. ...
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
Similar to PointerToArray, except that its contents may not be modified.