File: messagecomplextypes.cc

package info (click to toggle)
sinfo 0.0.48-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 3,332 kB
  • sloc: sh: 11,213; cpp: 6,722; makefile: 271; xml: 151; perl: 149
file content (108 lines) | stat: -rw-r--r-- 1,957 bytes parent folder | download | duplicates (5)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "messagebasictypes.h"
#include "messagecomplextypes.h"


namespace Msg
{


void pushFrontstring(Message & message, const std::string & value)
{
  int charCountDown=value.size();
  bool lastPart=true;
  do
  {
    int partSize=charCountDown;
    if (partSize>127)
    {
      partSize=127;
    }
    int partCountDown=partSize;
    while (partCountDown>0)
    {
      pushFrontuint8(message,uint8(value[charCountDown-1]));
      charCountDown--;
      partCountDown--;
    }
    if (true==lastPart)
    {
      pushFrontuint8(message,partSize );
      lastPart=false;
    }
    else
    {
      pushFrontuint8(message,partSize | 0x80 ); // continue flag
    }
  }
  while (charCountDown>0);
}


void pushBackstring(Message & message, const std::string & value)
{
  int charSize=value.size();
  int charCountUp=0;
  do
  {
    int partSize=charSize-charCountUp;
    if (partSize>127)
    {
      partSize=127;
      pushBackuint8(message,partSize | 0x80 ); // continue flag
    }
    else
    {
      pushBackuint8(message,partSize );
    }
    int partCountUp=0;
    while (partCountUp<partSize)
    {
      pushBackuint8(message,uint8(value[charCountUp]));
      partCountUp++;
      charCountUp++;
    }
  }
  while (charCountUp<charSize);
}


void popFrontstring(Message & message, std::string & returnValue)
{
  returnValue="";
  bool continueFlag=true;
  while (continueFlag)
  {
    uint8 partSize;
    popFrontuint8(message,partSize);
    if (0x80 == (partSize&0x80) )
    {
      continueFlag=true;
      partSize&=0x7f;
    }
    else
    {
      continueFlag=false;
    }
    for (int i=0; i<partSize; i++)
    {
      uint8 stringPart;
      popFrontuint8(message,stringPart);
      returnValue+=char(stringPart);
    }
  }
}


void pushFront(Message & message, const std::string & value)
{
  pushFrontstring(message, value);
}


void popFront(Message & message, std::string & returnValue)
{
  popFrontstring(message, returnValue);
}


}