Changeset 10
- Timestamp:
- Oct 12, 2009, 12:52:28 PM (15 years ago)
- Location:
- ProtocolBuffers
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
ProtocolBuffers/Demo.compiled
r5 r10 2 2 <CONFIG> 3 3 <Compiler Value="E:\Programy\Lazarus_0.9.27\fpc\2.2.4\bin\i386-win32\fpc.exe" Date="992089738"/> 4 <Params Value=" -MObjFPC -Scgi - O1 -gl -WG -vewnhi -l -FiE:\Projekty\PascalClassLibrary\ProtocolBuffers\ -FuE:\Programy\Lazarus_0.9.27\lcl\units\i386-win32\ -FuE:\Programy\Lazarus_0.9.27\lcl\units\i386-win32\win32\ -FuE:\Programy\Lazarus_0.9.27\packager\units\i386-win32\ -FuE:\Projekty\PascalClassLibrary\ProtocolBuffers\ -Fu. -FEE:\Projekty\PascalClassLibrary\ProtocolBuffers\ -oDemo.exe -dLCL -dLCLwin32 Demo.lpr"/>4 <Params Value=" -MObjFPC -Scgi -Cirot -O1 -gl -WG -vewnhi -l -FiE:\Projekty\PascalClassLibrary\ProtocolBuffers\ -FuE:\Programy\Lazarus_0.9.27\lcl\units\i386-win32\ -FuE:\Programy\Lazarus_0.9.27\lcl\units\i386-win32\win32\ -FuE:\Programy\Lazarus_0.9.27\packager\units\i386-win32\ -FuE:\Projekty\PascalClassLibrary\ProtocolBuffers\ -Fu. -FEE:\Projekty\PascalClassLibrary\ProtocolBuffers\ -oDemo.exe -dLCL -dLCLwin32 Demo.lpr"/> 5 5 </CONFIG> -
ProtocolBuffers/Demo.lpi
r9 r10 9 9 <Icon Value="0"/> 10 10 <UseXPManifest Value="True"/> 11 <ActiveEditorIndexAtStart Value=" 1"/>11 <ActiveEditorIndexAtStart Value="0"/> 12 12 </General> 13 13 <VersionInfo> … … 33 33 </Item1> 34 34 </RequiredPackages> 35 <Units Count=" 9">35 <Units Count="10"> 36 36 <Unit0> 37 37 <Filename Value="Demo.lpr"/> 38 38 <IsPartOfProject Value="True"/> 39 39 <UnitName Value="Demo"/> 40 <CursorPos X=" 75" Y="10"/>40 <CursorPos X="23" Y="11"/> 41 41 <TopLine Value="1"/> 42 42 <EditorIndex Value="6"/> 43 <UsageCount Value="3 0"/>43 <UsageCount Value="34"/> 44 44 <Loaded Value="True"/> 45 45 </Unit0> … … 50 50 <ResourceBaseClass Value="Form"/> 51 51 <UnitName Value="UMainForm"/> 52 <CursorPos X=" 42" Y="112"/>53 <TopLine Value=" 79"/>52 <CursorPos X="19" Y="137"/> 53 <TopLine Value="124"/> 54 54 <EditorIndex Value="0"/> 55 <UsageCount Value="3 0"/>55 <UsageCount Value="34"/> 56 56 <Loaded Value="True"/> 57 57 </Unit1> … … 60 60 <IsPartOfProject Value="True"/> 61 61 <UnitName Value="UProtocolBuffers"/> 62 <CursorPos X=" 45" Y="137"/>63 <TopLine Value=" 131"/>62 <CursorPos X="30" Y="223"/> 63 <TopLine Value="217"/> 64 64 <EditorIndex Value="1"/> 65 <UsageCount Value="3 0"/>65 <UsageCount Value="34"/> 66 66 <Loaded Value="True"/> 67 67 </Unit2> … … 70 70 <IsPartOfProject Value="True"/> 71 71 <UnitName Value="UMemoryStreamEx"/> 72 <CursorPos X=" 1" Y="1"/>73 <TopLine Value=" 1"/>74 <EditorIndex Value=" 5"/>75 <UsageCount Value="3 0"/>72 <CursorPos X="3" Y="60"/> 73 <TopLine Value="56"/> 74 <EditorIndex Value="2"/> 75 <UsageCount Value="34"/> 76 76 <Loaded Value="True"/> 77 77 </Unit3> 78 78 <Unit4> 79 79 <Filename Value="..\..\..\Programy\Lazarus_0.9.27\fpc\2.2.4\source\rtl\objpas\classes\classesh.inc"/> 80 <CursorPos X="1 9" Y="826"/>81 <TopLine Value=" 810"/>82 <EditorIndex Value=" 4"/>83 <UsageCount Value="1 4"/>80 <CursorPos X="15" Y="806"/> 81 <TopLine Value="790"/> 82 <EditorIndex Value="5"/> 83 <UsageCount Value="16"/> 84 84 <Loaded Value="True"/> 85 85 </Unit4> … … 89 89 <CursorPos X="20" Y="4"/> 90 90 <TopLine Value="1"/> 91 <EditorIndex Value=" 3"/>92 <UsageCount Value=" 28"/>91 <EditorIndex Value="4"/> 92 <UsageCount Value="32"/> 93 93 <Loaded Value="True"/> 94 94 <SyntaxHighlighter Value="None"/> … … 100 100 <CursorPos X="66" Y="26"/> 101 101 <TopLine Value="2"/> 102 <EditorIndex Value=" 2"/>103 <UsageCount Value=" 27"/>102 <EditorIndex Value="3"/> 103 <UsageCount Value="31"/> 104 104 <Loaded Value="True"/> 105 105 </Unit6> … … 117 117 <UsageCount Value="10"/> 118 118 </Unit8> 119 <Unit9> 120 <Filename Value="..\..\..\Programy\Lazarus_0.9.27\fpc\2.2.4\source\rtl\objpas\classes\streams.inc"/> 121 <CursorPos X="47" Y="533"/> 122 <TopLine Value="530"/> 123 <UsageCount Value="10"/> 124 </Unit9> 119 125 </Units> 120 126 <JumpHistory Count="30" HistoryIndex="29"> 121 127 <Position1> 122 128 <Filename Value="UProtocolBuffers.pas"/> 123 <Caret Line=" 219" Column="1" TopLine="203"/>129 <Caret Line="158" Column="1" TopLine="142"/> 124 130 </Position1> 125 131 <Position2> 126 132 <Filename Value="UProtocolBuffers.pas"/> 127 <Caret Line=" 29" Column="15" TopLine="13"/>133 <Caret Line="159" Column="1" TopLine="143"/> 128 134 </Position2> 129 135 <Position3> 130 136 <Filename Value="UProtocolBuffers.pas"/> 131 <Caret Line=" 227" Column="5" TopLine="195"/>137 <Caret Line="160" Column="1" TopLine="144"/> 132 138 </Position3> 133 139 <Position4> 134 <Filename Value="U MainForm.pas"/>135 <Caret Line="1 56" Column="9" TopLine="135"/>140 <Filename Value="UProtocolBuffers.pas"/> 141 <Caret Line="161" Column="1" TopLine="145"/> 136 142 </Position4> 137 143 <Position5> 138 <Filename Value="U MainForm.pas"/>139 <Caret Line="1 55" Column="16" TopLine="134"/>144 <Filename Value="UProtocolBuffers.pas"/> 145 <Caret Line="162" Column="1" TopLine="146"/> 140 146 </Position5> 141 147 <Position6> 142 148 <Filename Value="UProtocolBuffers.pas"/> 143 <Caret Line="1 36" Column="27" TopLine="120"/>149 <Caret Line="165" Column="1" TopLine="149"/> 144 150 </Position6> 145 151 <Position7> 146 152 <Filename Value="UProtocolBuffers.pas"/> 147 <Caret Line="1 12" Column="9" TopLine="121"/>153 <Caret Line="166" Column="1" TopLine="150"/> 148 154 </Position7> 149 155 <Position8> 150 156 <Filename Value="UProtocolBuffers.pas"/> 151 <Caret Line="1 34" Column="1" TopLine="118"/>157 <Caret Line="159" Column="1" TopLine="143"/> 152 158 </Position8> 153 159 <Position9> 154 160 <Filename Value="UProtocolBuffers.pas"/> 155 <Caret Line="1 35" Column="1" TopLine="119"/>161 <Caret Line="160" Column="1" TopLine="144"/> 156 162 </Position9> 157 163 <Position10> 158 164 <Filename Value="UProtocolBuffers.pas"/> 159 <Caret Line="1 36" Column="1" TopLine="120"/>165 <Caret Line="161" Column="1" TopLine="145"/> 160 166 </Position10> 161 167 <Position11> 162 168 <Filename Value="UProtocolBuffers.pas"/> 163 <Caret Line="1 37" Column="1" TopLine="121"/>169 <Caret Line="172" Column="1" TopLine="156"/> 164 170 </Position11> 165 171 <Position12> 166 172 <Filename Value="UProtocolBuffers.pas"/> 167 <Caret Line="1 35" Column="1" TopLine="119"/>173 <Caret Line="173" Column="1" TopLine="157"/> 168 174 </Position12> 169 175 <Position13> 170 176 <Filename Value="UProtocolBuffers.pas"/> 171 <Caret Line="1 36" Column="1" TopLine="120"/>177 <Caret Line="159" Column="1" TopLine="143"/> 172 178 </Position13> 173 179 <Position14> 174 180 <Filename Value="UProtocolBuffers.pas"/> 175 <Caret Line="1 37" Column="1" TopLine="121"/>181 <Caret Line="160" Column="1" TopLine="144"/> 176 182 </Position14> 177 183 <Position15> 178 184 <Filename Value="UProtocolBuffers.pas"/> 179 <Caret Line="1 38" Column="1" TopLine="122"/>185 <Caret Line="161" Column="1" TopLine="145"/> 180 186 </Position15> 181 187 <Position16> 182 188 <Filename Value="UProtocolBuffers.pas"/> 183 <Caret Line="1 41" Column="1" TopLine="125"/>189 <Caret Line="162" Column="1" TopLine="146"/> 184 190 </Position16> 185 191 <Position17> 186 192 <Filename Value="UProtocolBuffers.pas"/> 187 <Caret Line="1 42" Column="1" TopLine="126"/>193 <Caret Line="165" Column="1" TopLine="149"/> 188 194 </Position17> 189 195 <Position18> 190 196 <Filename Value="UProtocolBuffers.pas"/> 191 <Caret Line="1 35" Column="1" TopLine="119"/>197 <Caret Line="166" Column="1" TopLine="150"/> 192 198 </Position18> 193 199 <Position19> 194 <Filename Value=" UProtocolBuffers.pas"/>195 <Caret Line="1 36" Column="1" TopLine="120"/>200 <Filename Value="Demo.lpr"/> 201 <Caret Line="10" Column="75" TopLine="1"/> 196 202 </Position19> 197 203 <Position20> 198 <Filename Value="U ProtocolBuffers.pas"/>199 <Caret Line="1 37" Column="1" TopLine="121"/>204 <Filename Value="UMainForm.pas"/> 205 <Caret Line="107" Column="11" TopLine="92"/> 200 206 </Position20> 201 207 <Position21> 202 208 <Filename Value="UProtocolBuffers.pas"/> 203 <Caret Line="13 8" Column="1" TopLine="122"/>209 <Caret Line="132" Column="42" TopLine="118"/> 204 210 </Position21> 205 211 <Position22> 206 212 <Filename Value="UProtocolBuffers.pas"/> 207 <Caret Line="1 41" Column="1" TopLine="125"/>213 <Caret Line="128" Column="1" TopLine="112"/> 208 214 </Position22> 209 215 <Position23> 210 216 <Filename Value="UProtocolBuffers.pas"/> 211 <Caret Line="1 42" Column="1" TopLine="126"/>217 <Caret Line="129" Column="1" TopLine="113"/> 212 218 </Position23> 213 219 <Position24> 214 220 <Filename Value="UProtocolBuffers.pas"/> 215 <Caret Line="1 49" Column="1" TopLine="133"/>221 <Caret Line="132" Column="22" TopLine="114"/> 216 222 </Position24> 217 223 <Position25> 218 224 <Filename Value="UProtocolBuffers.pas"/> 219 <Caret Line=" 81" Column="39" TopLine="65"/>225 <Caret Line="128" Column="1" TopLine="112"/> 220 226 </Position25> 221 227 <Position26> 222 228 <Filename Value="UProtocolBuffers.pas"/> 223 <Caret Line="1 34" Column="1" TopLine="118"/>229 <Caret Line="129" Column="1" TopLine="113"/> 224 230 </Position26> 225 231 <Position27> 226 232 <Filename Value="UProtocolBuffers.pas"/> 227 <Caret Line="13 5" Column="1" TopLine="119"/>233 <Caret Line="130" Column="1" TopLine="114"/> 228 234 </Position27> 229 235 <Position28> 230 236 <Filename Value="UProtocolBuffers.pas"/> 231 <Caret Line="13 6" Column="6" TopLine="120"/>237 <Caret Line="132" Column="12" TopLine="120"/> 232 238 </Position28> 233 239 <Position29> 234 240 <Filename Value="UProtocolBuffers.pas"/> 235 <Caret Line=" 82" Column="19" TopLine="78"/>241 <Caret Line="185" Column="24" TopLine="181"/> 236 242 </Position29> 237 243 <Position30> 238 <Filename Value="U MainForm.pas"/>239 <Caret Line=" 112" Column="39" TopLine="88"/>244 <Filename Value="UProtocolBuffers.pas"/> 245 <Caret Line="316" Column="5" TopLine="302"/> 240 246 </Position30> 241 247 </JumpHistory> … … 247 253 <IncludeFiles Value="$(ProjOutDir)\"/> 248 254 </SearchPaths> 255 <CodeGeneration> 256 <Checks> 257 <IOChecks Value="True"/> 258 <RangeChecks Value="True"/> 259 <OverflowChecks Value="True"/> 260 <StackChecks Value="True"/> 261 </Checks> 262 </CodeGeneration> 249 263 <Linking> 250 264 <Options> … … 259 273 </CompilerOptions> 260 274 <Debugging> 261 <BreakPoints Count="1">262 <Item1>263 <Source Value="UProtocolBuffers.pas"/>264 <Line Value="135"/>265 </Item1>266 </BreakPoints>267 275 <Exceptions Count="3"> 268 276 <Item1> -
ProtocolBuffers/UMainForm.pas
r9 r10 22 22 procedure Button1Click(Sender: TObject); 23 23 procedure Button2Click(Sender: TObject); 24 procedure Button3Click(Sender: TObject); 24 25 procedure FormCreate(Sender: TObject); 25 26 procedure FormDestroy(Sender: TObject); … … 61 62 end; 62 63 64 procedure TMainForm.Button3Click(Sender: TObject); 65 begin 66 67 end; 68 63 69 procedure TMainForm.Button1Click(Sender: TObject); 64 70 var … … 73 79 Name := 'SampleMessage'; 74 80 NewItem := TPBIntegerItem.Create; 75 TPBIntegerItem(NewItem).Name := 'Height'; 76 TPBIntegerItem(NewItem).Tag := 1; 77 TPBIntegerItem(NewItem).Value := 12; 78 Items.Add(NewItem); 79 NewItem := TPBIntegerItem.Create; 80 TPBIntegerItem(NewItem).Name := 'Width'; 81 TPBIntegerItem(NewItem).Tag := 2; 82 TPBIntegerItem(NewItem).Value := 34; 83 Items.Add(NewItem); 84 NewItem := TPBIntegerItem.Create; 85 TPBIntegerItem(NewItem).Name := 'Age'; 86 TPBIntegerItem(NewItem).Tag := 3; 87 TPBIntegerItem(NewItem).Value := 45; 88 Items.Add(NewItem); 81 with TPBIntegerItem(NewItem) do begin 82 Name := 'Height'; 83 Tag := 1; 84 Value := 12; 85 end; 86 Items.Add(NewItem); 87 NewItem := TPBStringItem.Create; 88 with TPBStringItem(NewItem) do begin 89 Name := 'Name'; 90 Tag := 2; 91 Value := 'John Doe'; 92 end; 93 Items.Add(NewItem); 94 NewItem := TPBIntegerItem.Create; 95 with TPBIntegerItem(NewItem) do begin 96 Name := 'Age'; 97 Tag := 3; 98 Value := 45; 99 end; 100 Items.Add(NewItem); 101 NewItem := TPBMessageItem.Create; 102 Items.Add(NewItem); 103 with TPBMessageItem(Items[Items.Count - 1]) do begin 104 Name := 'Address'; 105 Tag := 5; 106 NewItem := TPBIntegerItem.Create; 107 with TPBIntegerItem(NewItem) do begin 108 Name := 'Street'; 109 Tag := 1; 110 Value := 67; 111 end; 112 Items.Add(NewItem); 113 end; 89 114 end; 90 115 DisplayTree(PB, TreeView1); … … 101 126 Name := 'SampleMessage'; 102 127 NewItem := TPBIntegerItem.Create; 103 TPBIntegerItem(NewItem).Name := 'Height'; 104 TPBIntegerItem(NewItem).Tag := 1; 105 Items.Add(NewItem); 106 NewItem := TPBIntegerItem.Create; 107 TPBIntegerItem(NewItem).Name := 'Age'; 108 TPBIntegerItem(NewItem).Tag := 3; 109 Items.Add(NewItem); 110 NewItem := TPBIntegerItem.Create; 111 TPBIntegerItem(NewItem).Name := 'Weight'; 112 TPBIntegerItem(NewItem).Tag := 4; 113 Items.Add(NewItem); 128 with TPBIntegerItem(NewItem) do begin 129 Name := 'Height'; 130 Tag := 1; 131 end; 132 Items.Add(NewItem); 133 NewItem := TPBStringItem.Create; 134 with TPBStringItem(NewItem) do begin 135 Name := 'Name'; 136 Tag := 2; 137 Value := ''; 138 end; 139 Items.Add(NewItem); 140 NewItem := TPBIntegerItem.Create; 141 with TPBIntegerItem(NewItem) do begin 142 Name := 'Weight'; 143 Tag := 4; 144 end; 145 Items.Add(NewItem); 146 NewItem := TPBMessageItem.Create; 147 Items.Add(NewItem); 148 with TPBMessageItem(Items[Items.Count - 1]) do begin 149 Name := 'Address'; 150 Tag := 5; 151 NewItem := TPBIntegerItem.Create; 152 with TPBIntegerItem(NewItem) do begin 153 Name := 'Street'; 154 Tag := 1; 155 end; 156 Items.Add(NewItem); 157 end; 114 158 end; 115 159 LoadFromStream(Stream); -
ProtocolBuffers/UProtocolBuffers.pas
r9 r10 25 25 procedure SaveVariantToStream(Stream: TStream; Value: Integer); 26 26 function LoadVariantFromStream(Stream: TStream): Integer; 27 procedure SaveLengthDelimitedToStream(Stream: TStream; Block: TStream); 28 procedure LoadLengthDelimitedFromStream(Stream: TStream; Block: TStream); 27 29 procedure SaveHeadToStream(Stream: TStream); 28 30 procedure LoadHeadFromStream(Stream: TStream); … … 51 53 { TPBMessageItem } 52 54 TPBMessageItem = class(TPBItem) 55 GenerateHead: Boolean; 53 56 Items: TList; // TList<TPBItem>; 54 57 function SearchItemByTag(Tag: Integer): TPBItem; … … 78 81 procedure TProtocolBuffer.LoadFromStream(Stream: TStream); 79 82 begin 80 BaseMessage. LoadHeadFromStream(Stream);83 BaseMessage.GenerateHead := False; 81 84 BaseMessage.LoadFromStream(Stream); 82 85 end; … … 84 87 procedure TProtocolBuffer.SaveToStream(Stream: TStream); 85 88 begin 89 BaseMessage.GenerateHead := False; 86 90 BaseMessage.SaveToStream(Stream); 87 91 end; … … 118 122 var 119 123 I: Integer; 120 begin 121 inherited; 122 SaveHeadToStream(Stream); 124 TempStream: TMemoryStream; 125 begin 126 inherited; 127 // Generate message content to temporary stream 128 TempStream := TMemoryStream.Create; 123 129 for I := 0 to Items.Count - 1 do 124 TPBItem(Items[I]).SaveToStream(Stream); 130 TPBItem(Items[I]).SaveToStream(TempStream); 131 // if head is used than write lenght-delimited head type with block byte length 132 if GenerateHead then begin 133 SaveHeadToStream(Stream); 134 SaveVariantToStream(Stream, TempStream.Size); 135 end; 136 TempStream.Position := 0; 137 TempStream.SaveToStream(Stream); 138 TempStream.Free; 125 139 end; 126 140 … … 130 144 TempItem: TPBItem; 131 145 SearchItem: TPBItem; 132 begin 133 inherited; 146 EndIndex: Integer; 147 TempStream: TMemoryStream; 148 begin 149 inherited; 150 TempStream := TMemoryStream.Create; 151 152 if GenerateHead then begin 153 I := LoadVariantFromStream(Stream); 154 EndIndex := Stream.Position + I; 155 end else EndIndex := Stream.Size; 156 134 157 TempItem := TPBItem.Create; 135 for I := 0 to Items.Count - 1do begin158 while Stream.Position < EndIndex do begin 136 159 TempItem.LoadHeadFromStream(Stream); 137 160 SearchItem := SearchItemByTag(TempItem.Tag); … … 146 169 else if SearchItem is TPBMessageItem then 147 170 TPBMessageItem(SearchItem).LoadFromStream(Stream); 171 end else begin 172 if TempItem.ItemType = itVariant then 173 TempItem.LoadVariantFromStream(Stream) 174 else if TempItem.ItemType = itLengthDelimited then 175 TempItem.LoadLengthDelimitedFromStream(Stream, TempStream); 148 176 end; 149 177 end; 178 TempStream.Free; 150 179 end; 151 180 … … 154 183 ItemType := itLengthDelimited; 155 184 Items := TList.Create; 185 GenerateHead := True; 156 186 end; 157 187 … … 243 273 end; 244 274 275 procedure TPBItem.SaveLengthDelimitedToStream(Stream: TStream; Block: TStream); 276 begin 277 SaveVariantToStream(Stream, Block.Size); 278 Block.Position := 0; 279 TMemoryStreamEx(Block).ReadStream(Stream, Block.Size); 280 end; 281 282 procedure TPBItem.LoadLengthDelimitedFromStream(Stream: TStream; Block: TStream 283 ); 284 var 285 Size: Integer; 286 begin 287 Size := LoadVariantFromStream(Stream); 288 TMemoryStreamEx(Stream).ReadStream(Block, Size); 289 end; 290 245 291 { TPBIntegerItem } 246 292
Note:
See TracChangeset
for help on using the changeset viewer.