1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "WhistlePercept.h"

#include "Messages/Representations.pb.h"
#include <google/protobuf/io/zero_copy_stream_impl.h>

using namespace naoth;

WhistlePercept::WhistlePercept():<--- Member variable 'WhistlePercept::frameWhenWhistleDetected' is not initialized in the constructor.
  whistleDetected(false)
{
}

void WhistlePercept::print(std::ostream& stream) const
{ 
  stream << "whistleDetected: " << whistleDetected << std::endl;
  stream << "Frame number of last whistle: " << frameWhenWhistleDetected << std::endl;
  stream << "capture to file: " << captureFile << std::endl;
  stream << "recognized whistles: " << recognizedWhistles.size() << std::endl;
  for (size_t wIdx = 0; wIdx < recognizedWhistles.size(); wIdx++) 
  {
    stream << " " << recognizedWhistles[wIdx].name << " @" << recognizedWhistles[wIdx].positionInCapture << " response=" << recognizedWhistles[wIdx] .responseValue << std::endl; 
  }
}

WhistlePercept::~WhistlePercept()
{ 
}

void Serializer<WhistlePercept>::deserialize(std::istream& stream, WhistlePercept& representation)
{
  naothmessages::WhistlePercept message;
  google::protobuf::io::IstreamInputStream buf(&stream);
  message.ParseFromZeroCopyStream(&buf);

  // NOTE: obsolete
  if(message.has_framewhenwhistledetected()) {
    representation.frameWhenWhistleDetected = message.framewhenwhistledetected();
  }

  if(message.has_capturefile()) {
    representation.captureFile = message.capturefile();
  }

  if(message.has_whistledetected()) {
    representation.whistleDetected = message.whistledetected();
  }

  representation.recognizedWhistles.clear();
  for (int i = 0; i < message.recognizedwhistles_size(); i++)
  {
    const naothmessages::WhistlePercept::Whistle& msgWhistle = message.recognizedwhistles(i);
    WhistlePercept::Whistle whistle(msgWhistle.name(), msgWhistle.positionincapture(), msgWhistle.responsevalue());
    representation.recognizedWhistles.push_back(whistle);
  }
}//end deserialize


void Serializer<WhistlePercept>::serialize(const WhistlePercept& representation, std::ostream& stream)
{
  naothmessages::WhistlePercept message;

  // NOTE: obsolete
  message.set_capturefile(representation.captureFile);
  message.set_whistledetected(representation.whistleDetected);

  for (size_t i = 0; i < representation.recognizedWhistles.size(); i++)
  {
    naothmessages::WhistlePercept::Whistle* msgWhistle = message.add_recognizedwhistles();
    msgWhistle->set_name(representation.recognizedWhistles[i].name);
    msgWhistle->set_positionincapture(representation.recognizedWhistles[i].positionInCapture);
    msgWhistle->set_responsevalue(representation.recognizedWhistles[i].responseValue);
  }

  google::protobuf::io::OstreamOutputStream buf(&stream);
  message.SerializeToZeroCopyStream(&buf);
}//end serialize