PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/source/library/Interlace.Pinch/Interlace.Pinch.Tests/TestVersion3.cs

https://bitbucket.org/VahidN/interlace
C# | 1578 lines | 1218 code | 346 blank | 14 comment | 58 complexity | b6b3e8b93a16f06c92aebbd6accd73ba MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. using System.Collections.Generic;
  2. using System.ComponentModel;
  3. using Interlace.Pinch.Implementation;
  4. namespace Interlace.Pinch.TestsVersion3
  5. {
  6. public enum Enumeration
  7. {
  8. A = 1,
  9. B = 3,
  10. C = 2,
  11. D = 4
  12. }
  13. public class ChoiceMessageFactory : IPinchableFactory
  14. {
  15. static ChoiceMessageFactory _instance = new ChoiceMessageFactory();
  16. public object Create(IPinchDecodingContext context)
  17. {
  18. return new ChoiceMessage(context);
  19. }
  20. public static IPinchableFactory Instance
  21. {
  22. get
  23. {
  24. return _instance;
  25. }
  26. }
  27. }
  28. public partial class ChoiceMessage : IPinchable, INotifyPropertyChanged
  29. {
  30. int _test;
  31. ChoiceStructure _choice;
  32. static PinchFieldProperties _testProperties = new PinchFieldProperties(2, 1, null);
  33. static PinchFieldProperties _choiceProperties = new PinchFieldProperties(1, 1, null);
  34. public ChoiceMessage()
  35. {
  36. }
  37. public ChoiceMessage(IPinchDecodingContext context)
  38. {
  39. }
  40. public int Test
  41. {
  42. get { return _test; }
  43. set
  44. {
  45. _test = value;
  46. FirePropertyChanged("Test");
  47. }
  48. }
  49. public ChoiceStructure Choice
  50. {
  51. get { return _choice; }
  52. set
  53. {
  54. _choice = value;
  55. FirePropertyChanged("Choice");
  56. }
  57. }
  58. int IPinchable.ProtocolVersion
  59. {
  60. get
  61. {
  62. return 3;
  63. }
  64. }
  65. protected virtual void OnAdditionalFutureFields(IPinchDecoder decoder)
  66. {
  67. }
  68. void IPinchable.Encode(IPinchEncoder encoder)
  69. {
  70. encoder.OpenSequence(2);
  71. // Encode fields for version 1:
  72. encoder.EncodeRequiredStructure(_choice, _choiceProperties);
  73. encoder.EncodeRequiredInt32(_test, _testProperties);
  74. encoder.CloseSequence();
  75. }
  76. void IPinchable.Decode(IPinchDecoder decoder)
  77. {
  78. int remainingFields = decoder.OpenSequence();
  79. // Decode members for version 1:
  80. if (remainingFields >= 2)
  81. {
  82. _choice = (ChoiceStructure)decoder.DecodeRequiredStructure(ChoiceStructureFactory.Instance, _choiceProperties);
  83. _test = (int)decoder.DecodeRequiredInt32(_testProperties);
  84. remainingFields -= 2;
  85. }
  86. else
  87. {
  88. if (remainingFields != 0) throw new PinchInvalidCodingException();
  89. }
  90. if (remainingFields > 0)
  91. {
  92. OnAdditionalFutureFields(decoder);
  93. decoder.SkipFields(remainingFields);
  94. }
  95. decoder.CloseSequence();
  96. }
  97. #region INotifyPropertyChanged Members
  98. public event PropertyChangedEventHandler PropertyChanged;
  99. protected void FirePropertyChanged(string propertyName)
  100. {
  101. if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  102. }
  103. #endregion
  104. }
  105. public class ChoiceStructureFactory : IPinchableFactory
  106. {
  107. static ChoiceStructureFactory _instance = new ChoiceStructureFactory();
  108. public object Create(IPinchDecodingContext context)
  109. {
  110. return new ChoiceStructure(context);
  111. }
  112. public static IPinchableFactory Instance
  113. {
  114. get
  115. {
  116. return _instance;
  117. }
  118. }
  119. }
  120. public enum ChoiceStructureKind
  121. {
  122. None = 0,
  123. Small = 3,
  124. RequiredDecimal = 2,
  125. OptionalDecimal = 1,
  126. Versioning = 4,
  127. }
  128. public partial class ChoiceStructure : IPinchable, INotifyPropertyChanged
  129. {
  130. object _value;
  131. ChoiceStructureKind _valueKind;
  132. static PinchFieldProperties _smallProperties = new PinchFieldProperties(3, 1, null);
  133. static PinchFieldProperties _requiredDecimalProperties = new PinchFieldProperties(2, 1, null);
  134. static PinchFieldProperties _optionalDecimalProperties = new PinchFieldProperties(1, 1, null);
  135. static PinchFieldProperties _versioningProperties = new PinchFieldProperties(4, 1, null);
  136. public ChoiceStructure(SmallStructure value)
  137. {
  138. _value = value;
  139. _valueKind = ChoiceStructureKind.Small;
  140. }
  141. public static implicit operator ChoiceStructure(SmallStructure value)
  142. {
  143. return new ChoiceStructure(value);
  144. }
  145. public ChoiceStructure(RequiredDecimalStructure value)
  146. {
  147. _value = value;
  148. _valueKind = ChoiceStructureKind.RequiredDecimal;
  149. }
  150. public static implicit operator ChoiceStructure(RequiredDecimalStructure value)
  151. {
  152. return new ChoiceStructure(value);
  153. }
  154. public ChoiceStructure(OptionalDecimalStructure value)
  155. {
  156. _value = value;
  157. _valueKind = ChoiceStructureKind.OptionalDecimal;
  158. }
  159. public static implicit operator ChoiceStructure(OptionalDecimalStructure value)
  160. {
  161. return new ChoiceStructure(value);
  162. }
  163. public ChoiceStructure(VersioningStructure value)
  164. {
  165. _value = value;
  166. _valueKind = ChoiceStructureKind.Versioning;
  167. }
  168. public static implicit operator ChoiceStructure(VersioningStructure value)
  169. {
  170. return new ChoiceStructure(value);
  171. }
  172. public ChoiceStructure()
  173. {
  174. _value = null;
  175. _valueKind = ChoiceStructureKind.None;
  176. }
  177. public ChoiceStructure(IPinchDecodingContext context)
  178. {
  179. }
  180. public object Value
  181. {
  182. get { return _value; }
  183. }
  184. public ChoiceStructureKind ValueKind
  185. {
  186. get { return _valueKind; }
  187. }
  188. public SmallStructure Small
  189. {
  190. get { return _valueKind == ChoiceStructureKind.Small ? (SmallStructure)_value : null; }
  191. set
  192. {
  193. ChoiceStructureKind existingKind = _valueKind;
  194. _value = value;
  195. _valueKind = ChoiceStructureKind.Small;
  196. if (existingKind != _valueKind) FirePropertyChanged(existingKind);
  197. FirePropertyChanged(_valueKind);
  198. }
  199. }
  200. public RequiredDecimalStructure RequiredDecimal
  201. {
  202. get { return _valueKind == ChoiceStructureKind.RequiredDecimal ? (RequiredDecimalStructure)_value : null; }
  203. set
  204. {
  205. ChoiceStructureKind existingKind = _valueKind;
  206. _value = value;
  207. _valueKind = ChoiceStructureKind.RequiredDecimal;
  208. if (existingKind != _valueKind) FirePropertyChanged(existingKind);
  209. FirePropertyChanged(_valueKind);
  210. }
  211. }
  212. public OptionalDecimalStructure OptionalDecimal
  213. {
  214. get { return _valueKind == ChoiceStructureKind.OptionalDecimal ? (OptionalDecimalStructure)_value : null; }
  215. set
  216. {
  217. ChoiceStructureKind existingKind = _valueKind;
  218. _value = value;
  219. _valueKind = ChoiceStructureKind.OptionalDecimal;
  220. if (existingKind != _valueKind) FirePropertyChanged(existingKind);
  221. FirePropertyChanged(_valueKind);
  222. }
  223. }
  224. public VersioningStructure Versioning
  225. {
  226. get { return _valueKind == ChoiceStructureKind.Versioning ? (VersioningStructure)_value : null; }
  227. set
  228. {
  229. ChoiceStructureKind existingKind = _valueKind;
  230. _value = value;
  231. _valueKind = ChoiceStructureKind.Versioning;
  232. if (existingKind != _valueKind) FirePropertyChanged(existingKind);
  233. FirePropertyChanged(_valueKind);
  234. }
  235. }
  236. int IPinchable.ProtocolVersion
  237. {
  238. get
  239. {
  240. return 3;
  241. }
  242. }
  243. public void FirePropertyChanged(ChoiceStructureKind kind)
  244. {
  245. switch (kind)
  246. {
  247. case ChoiceStructureKind.None:
  248. break;
  249. case ChoiceStructureKind.Small:
  250. FirePropertyChanged("Small");
  251. break;
  252. case ChoiceStructureKind.RequiredDecimal:
  253. FirePropertyChanged("RequiredDecimal");
  254. break;
  255. case ChoiceStructureKind.OptionalDecimal:
  256. FirePropertyChanged("OptionalDecimal");
  257. break;
  258. case ChoiceStructureKind.Versioning:
  259. FirePropertyChanged("Versioning");
  260. break;
  261. default:
  262. break;
  263. }
  264. }
  265. void IPinchable.Encode(IPinchEncoder encoder)
  266. {
  267. encoder.EncodeChoiceMarker((int)_valueKind);
  268. switch (_valueKind)
  269. {
  270. case ChoiceStructureKind.None:
  271. throw new PinchNullRequiredFieldException();
  272. case ChoiceStructureKind.Small:
  273. encoder.EncodeRequiredStructure((IPinchable)_value, _smallProperties);
  274. break;
  275. case ChoiceStructureKind.RequiredDecimal:
  276. encoder.EncodeRequiredStructure((IPinchable)_value, _requiredDecimalProperties);
  277. break;
  278. case ChoiceStructureKind.OptionalDecimal:
  279. encoder.EncodeRequiredStructure((IPinchable)_value, _optionalDecimalProperties);
  280. break;
  281. case ChoiceStructureKind.Versioning:
  282. encoder.EncodeRequiredStructure((IPinchable)_value, _versioningProperties);
  283. break;
  284. }
  285. }
  286. void IPinchable.Decode(IPinchDecoder decoder)
  287. {
  288. _valueKind = (ChoiceStructureKind)decoder.DecodeChoiceMarker();
  289. switch (_valueKind)
  290. {
  291. case ChoiceStructureKind.Small:
  292. _value = decoder.DecodeRequiredStructure(SmallStructureFactory.Instance, _smallProperties);
  293. break;
  294. case ChoiceStructureKind.RequiredDecimal:
  295. _value = decoder.DecodeRequiredStructure(RequiredDecimalStructureFactory.Instance, _requiredDecimalProperties);
  296. break;
  297. case ChoiceStructureKind.OptionalDecimal:
  298. _value = decoder.DecodeRequiredStructure(OptionalDecimalStructureFactory.Instance, _optionalDecimalProperties);
  299. break;
  300. case ChoiceStructureKind.Versioning:
  301. _value = decoder.DecodeRequiredStructure(VersioningStructureFactory.Instance, _versioningProperties);
  302. break;
  303. default:
  304. throw new PinchInvalidCodingException();
  305. }
  306. }
  307. #region INotifyPropertyChanged Members
  308. public event PropertyChangedEventHandler PropertyChanged;
  309. protected void FirePropertyChanged(string propertyName)
  310. {
  311. if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  312. }
  313. #endregion
  314. }
  315. public class SmallStructureFactory : IPinchableFactory
  316. {
  317. static SmallStructureFactory _instance = new SmallStructureFactory();
  318. public object Create(IPinchDecodingContext context)
  319. {
  320. return new SmallStructure(context);
  321. }
  322. public static IPinchableFactory Instance
  323. {
  324. get
  325. {
  326. return _instance;
  327. }
  328. }
  329. }
  330. public partial class SmallStructure : IPinchable, INotifyPropertyChanged
  331. {
  332. byte _test;
  333. static PinchFieldProperties _testProperties = new PinchFieldProperties(1, 1, null);
  334. public SmallStructure()
  335. {
  336. }
  337. public SmallStructure(IPinchDecodingContext context)
  338. {
  339. }
  340. public byte Test
  341. {
  342. get { return _test; }
  343. set
  344. {
  345. _test = value;
  346. FirePropertyChanged("Test");
  347. }
  348. }
  349. int IPinchable.ProtocolVersion
  350. {
  351. get
  352. {
  353. return 3;
  354. }
  355. }
  356. protected virtual void OnAdditionalFutureFields(IPinchDecoder decoder)
  357. {
  358. }
  359. void IPinchable.Encode(IPinchEncoder encoder)
  360. {
  361. encoder.OpenSequence(1);
  362. // Encode fields for version 1:
  363. encoder.EncodeRequiredInt8(_test, _testProperties);
  364. encoder.CloseSequence();
  365. }
  366. void IPinchable.Decode(IPinchDecoder decoder)
  367. {
  368. int remainingFields = decoder.OpenSequence();
  369. // Decode members for version 1:
  370. if (remainingFields >= 1)
  371. {
  372. _test = (byte)decoder.DecodeRequiredInt8(_testProperties);
  373. remainingFields -= 1;
  374. }
  375. else
  376. {
  377. if (remainingFields != 0) throw new PinchInvalidCodingException();
  378. }
  379. if (remainingFields > 0)
  380. {
  381. OnAdditionalFutureFields(decoder);
  382. decoder.SkipFields(remainingFields);
  383. }
  384. decoder.CloseSequence();
  385. }
  386. #region INotifyPropertyChanged Members
  387. public event PropertyChangedEventHandler PropertyChanged;
  388. protected void FirePropertyChanged(string propertyName)
  389. {
  390. if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  391. }
  392. #endregion
  393. }
  394. public class RequiredDecimalStructureFactory : IPinchableFactory
  395. {
  396. static RequiredDecimalStructureFactory _instance = new RequiredDecimalStructureFactory();
  397. public object Create(IPinchDecodingContext context)
  398. {
  399. return new RequiredDecimalStructure(context);
  400. }
  401. public static IPinchableFactory Instance
  402. {
  403. get
  404. {
  405. return _instance;
  406. }
  407. }
  408. }
  409. public partial class RequiredDecimalStructure : IPinchable, INotifyPropertyChanged
  410. {
  411. decimal _value;
  412. static PinchFieldProperties _valueProperties = new PinchFieldProperties(1, 1, null);
  413. public RequiredDecimalStructure()
  414. {
  415. }
  416. public RequiredDecimalStructure(IPinchDecodingContext context)
  417. {
  418. }
  419. public decimal Value
  420. {
  421. get { return _value; }
  422. set
  423. {
  424. _value = value;
  425. FirePropertyChanged("Value");
  426. }
  427. }
  428. int IPinchable.ProtocolVersion
  429. {
  430. get
  431. {
  432. return 3;
  433. }
  434. }
  435. protected virtual void OnAdditionalFutureFields(IPinchDecoder decoder)
  436. {
  437. }
  438. void IPinchable.Encode(IPinchEncoder encoder)
  439. {
  440. encoder.OpenSequence(1);
  441. // Encode fields for version 1:
  442. encoder.EncodeRequiredDecimal(_value, _valueProperties);
  443. encoder.CloseSequence();
  444. }
  445. void IPinchable.Decode(IPinchDecoder decoder)
  446. {
  447. int remainingFields = decoder.OpenSequence();
  448. // Decode members for version 1:
  449. if (remainingFields >= 1)
  450. {
  451. _value = (decimal)decoder.DecodeRequiredDecimal(_valueProperties);
  452. remainingFields -= 1;
  453. }
  454. else
  455. {
  456. if (remainingFields != 0) throw new PinchInvalidCodingException();
  457. }
  458. if (remainingFields > 0)
  459. {
  460. OnAdditionalFutureFields(decoder);
  461. decoder.SkipFields(remainingFields);
  462. }
  463. decoder.CloseSequence();
  464. }
  465. #region INotifyPropertyChanged Members
  466. public event PropertyChangedEventHandler PropertyChanged;
  467. protected void FirePropertyChanged(string propertyName)
  468. {
  469. if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  470. }
  471. #endregion
  472. }
  473. public class OptionalDecimalStructureFactory : IPinchableFactory
  474. {
  475. static OptionalDecimalStructureFactory _instance = new OptionalDecimalStructureFactory();
  476. public object Create(IPinchDecodingContext context)
  477. {
  478. return new OptionalDecimalStructure(context);
  479. }
  480. public static IPinchableFactory Instance
  481. {
  482. get
  483. {
  484. return _instance;
  485. }
  486. }
  487. }
  488. public partial class OptionalDecimalStructure : IPinchable, INotifyPropertyChanged
  489. {
  490. decimal? _value;
  491. static PinchFieldProperties _valueProperties = new PinchFieldProperties(1, 1, null);
  492. public OptionalDecimalStructure()
  493. {
  494. }
  495. public OptionalDecimalStructure(IPinchDecodingContext context)
  496. {
  497. }
  498. public decimal? Value
  499. {
  500. get { return _value; }
  501. set
  502. {
  503. _value = value;
  504. FirePropertyChanged("Value");
  505. }
  506. }
  507. int IPinchable.ProtocolVersion
  508. {
  509. get
  510. {
  511. return 3;
  512. }
  513. }
  514. protected virtual void OnAdditionalFutureFields(IPinchDecoder decoder)
  515. {
  516. }
  517. void IPinchable.Encode(IPinchEncoder encoder)
  518. {
  519. encoder.OpenSequence(1);
  520. // Encode fields for version 1:
  521. encoder.EncodeOptionalDecimal(_value, _valueProperties);
  522. encoder.CloseSequence();
  523. }
  524. void IPinchable.Decode(IPinchDecoder decoder)
  525. {
  526. int remainingFields = decoder.OpenSequence();
  527. // Decode members for version 1:
  528. if (remainingFields >= 1)
  529. {
  530. _value = (decimal?)decoder.DecodeOptionalDecimal(_valueProperties);
  531. remainingFields -= 1;
  532. }
  533. else
  534. {
  535. if (remainingFields != 0) throw new PinchInvalidCodingException();
  536. }
  537. if (remainingFields > 0)
  538. {
  539. OnAdditionalFutureFields(decoder);
  540. decoder.SkipFields(remainingFields);
  541. }
  542. decoder.CloseSequence();
  543. }
  544. #region INotifyPropertyChanged Members
  545. public event PropertyChangedEventHandler PropertyChanged;
  546. protected void FirePropertyChanged(string propertyName)
  547. {
  548. if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  549. }
  550. #endregion
  551. }
  552. public class VersioningStructureFactory : IPinchableFactory
  553. {
  554. static VersioningStructureFactory _instance = new VersioningStructureFactory();
  555. public object Create(IPinchDecodingContext context)
  556. {
  557. return new VersioningStructure(context);
  558. }
  559. public static IPinchableFactory Instance
  560. {
  561. get
  562. {
  563. return _instance;
  564. }
  565. }
  566. }
  567. public partial class VersioningStructure : IPinchable, INotifyPropertyChanged
  568. {
  569. byte _reqScalar;
  570. string _reqPointer;
  571. SmallStructure _reqStructure;
  572. byte? _optScalar;
  573. string _optPointer;
  574. SmallStructure _optStructure;
  575. byte _addedReqScalar;
  576. string _addedReqPointer;
  577. SmallStructure _addedReqStructure;
  578. byte? _addedOptScalar;
  579. string _addedOptPointer;
  580. SmallStructure _addedOptStructure;
  581. static PinchFieldProperties _reqScalarProperties = new PinchFieldProperties(8, 1, null);
  582. static PinchFieldProperties _reqPointerProperties = new PinchFieldProperties(7, 1, null);
  583. static PinchFieldProperties _reqStructureProperties = new PinchFieldProperties(9, 1, null);
  584. static PinchFieldProperties _optScalarProperties = new PinchFieldProperties(2, 1, null);
  585. static PinchFieldProperties _optPointerProperties = new PinchFieldProperties(1, 1, null);
  586. static PinchFieldProperties _optStructureProperties = new PinchFieldProperties(3, 1, null);
  587. static PinchFieldProperties _removedOptScalarProperties = new PinchFieldProperties(5, 1, 2);
  588. static PinchFieldProperties _removedOptPointerProperties = new PinchFieldProperties(4, 1, 2);
  589. static PinchFieldProperties _removedOptStructureProperties = new PinchFieldProperties(6, 1, 2);
  590. static PinchFieldProperties _addedReqScalarProperties = new PinchFieldProperties(14, 2, null);
  591. static PinchFieldProperties _addedReqPointerProperties = new PinchFieldProperties(13, 2, null);
  592. static PinchFieldProperties _addedReqStructureProperties = new PinchFieldProperties(15, 2, null);
  593. static PinchFieldProperties _addedOptScalarProperties = new PinchFieldProperties(11, 2, null);
  594. static PinchFieldProperties _addedOptPointerProperties = new PinchFieldProperties(10, 2, null);
  595. static PinchFieldProperties _addedOptStructureProperties = new PinchFieldProperties(12, 2, null);
  596. public VersioningStructure()
  597. {
  598. }
  599. public VersioningStructure(IPinchDecodingContext context)
  600. {
  601. }
  602. public byte ReqScalar
  603. {
  604. get { return _reqScalar; }
  605. set
  606. {
  607. _reqScalar = value;
  608. FirePropertyChanged("ReqScalar");
  609. }
  610. }
  611. public string ReqPointer
  612. {
  613. get { return _reqPointer; }
  614. set
  615. {
  616. _reqPointer = value;
  617. FirePropertyChanged("ReqPointer");
  618. }
  619. }
  620. public SmallStructure ReqStructure
  621. {
  622. get { return _reqStructure; }
  623. set
  624. {
  625. _reqStructure = value;
  626. FirePropertyChanged("ReqStructure");
  627. }
  628. }
  629. public byte? OptScalar
  630. {
  631. get { return _optScalar; }
  632. set
  633. {
  634. _optScalar = value;
  635. FirePropertyChanged("OptScalar");
  636. }
  637. }
  638. public string OptPointer
  639. {
  640. get { return _optPointer; }
  641. set
  642. {
  643. _optPointer = value;
  644. FirePropertyChanged("OptPointer");
  645. }
  646. }
  647. public SmallStructure OptStructure
  648. {
  649. get { return _optStructure; }
  650. set
  651. {
  652. _optStructure = value;
  653. FirePropertyChanged("OptStructure");
  654. }
  655. }
  656. public byte AddedReqScalar
  657. {
  658. get { return _addedReqScalar; }
  659. set
  660. {
  661. _addedReqScalar = value;
  662. FirePropertyChanged("AddedReqScalar");
  663. }
  664. }
  665. public string AddedReqPointer
  666. {
  667. get { return _addedReqPointer; }
  668. set
  669. {
  670. _addedReqPointer = value;
  671. FirePropertyChanged("AddedReqPointer");
  672. }
  673. }
  674. public SmallStructure AddedReqStructure
  675. {
  676. get { return _addedReqStructure; }
  677. set
  678. {
  679. _addedReqStructure = value;
  680. FirePropertyChanged("AddedReqStructure");
  681. }
  682. }
  683. public byte? AddedOptScalar
  684. {
  685. get { return _addedOptScalar; }
  686. set
  687. {
  688. _addedOptScalar = value;
  689. FirePropertyChanged("AddedOptScalar");
  690. }
  691. }
  692. public string AddedOptPointer
  693. {
  694. get { return _addedOptPointer; }
  695. set
  696. {
  697. _addedOptPointer = value;
  698. FirePropertyChanged("AddedOptPointer");
  699. }
  700. }
  701. public SmallStructure AddedOptStructure
  702. {
  703. get { return _addedOptStructure; }
  704. set
  705. {
  706. _addedOptStructure = value;
  707. FirePropertyChanged("AddedOptStructure");
  708. }
  709. }
  710. int IPinchable.ProtocolVersion
  711. {
  712. get
  713. {
  714. return 3;
  715. }
  716. }
  717. protected virtual void OnAdditionalFutureFields(IPinchDecoder decoder)
  718. {
  719. }
  720. void IPinchable.Encode(IPinchEncoder encoder)
  721. {
  722. encoder.OpenSequence(15);
  723. // Encode fields for version 1:
  724. encoder.EncodeOptionalString(_optPointer, _optPointerProperties);
  725. encoder.EncodeOptionalInt8(_optScalar, _optScalarProperties);
  726. encoder.EncodeOptionalStructure(_optStructure, _optStructureProperties);
  727. encoder.EncodeRemoved();
  728. encoder.EncodeRemoved();
  729. encoder.EncodeRemoved();
  730. encoder.EncodeRequiredString(_reqPointer, _reqPointerProperties);
  731. encoder.EncodeRequiredInt8(_reqScalar, _reqScalarProperties);
  732. encoder.EncodeRequiredStructure(_reqStructure, _reqStructureProperties);
  733. // Encode fields for version 2:
  734. encoder.EncodeOptionalString(_addedOptPointer, _addedOptPointerProperties);
  735. encoder.EncodeOptionalInt8(_addedOptScalar, _addedOptScalarProperties);
  736. encoder.EncodeOptionalStructure(_addedOptStructure, _addedOptStructureProperties);
  737. encoder.EncodeRequiredString(_addedReqPointer, _addedReqPointerProperties);
  738. encoder.EncodeRequiredInt8(_addedReqScalar, _addedReqScalarProperties);
  739. encoder.EncodeRequiredStructure(_addedReqStructure, _addedReqStructureProperties);
  740. encoder.CloseSequence();
  741. }
  742. void IPinchable.Decode(IPinchDecoder decoder)
  743. {
  744. int remainingFields = decoder.OpenSequence();
  745. int decodedUpToVersion = 0;
  746. // Decode members for version 1:
  747. if (remainingFields >= 9)
  748. {
  749. _optPointer = (string)decoder.DecodeOptionalString(_optPointerProperties);
  750. _optScalar = (byte?)decoder.DecodeOptionalInt8(_optScalarProperties);
  751. _optStructure = (SmallStructure)decoder.DecodeOptionalStructure(SmallStructureFactory.Instance, _optStructureProperties);
  752. decoder.SkipRemoved();
  753. decoder.SkipRemoved();
  754. decoder.SkipRemoved();
  755. _reqPointer = (string)decoder.DecodeRequiredString(_reqPointerProperties);
  756. _reqScalar = (byte)decoder.DecodeRequiredInt8(_reqScalarProperties);
  757. _reqStructure = (SmallStructure)decoder.DecodeRequiredStructure(SmallStructureFactory.Instance, _reqStructureProperties);
  758. remainingFields -= 9;
  759. decodedUpToVersion = 1;
  760. }
  761. else
  762. {
  763. if (remainingFields != 0) throw new PinchInvalidCodingException();
  764. OnMissingNewFields(decodedUpToVersion, 1);
  765. }
  766. // Decode members for version 2:
  767. if (remainingFields >= 6)
  768. {
  769. _addedOptPointer = (string)decoder.DecodeOptionalString(_addedOptPointerProperties);
  770. _addedOptScalar = (byte?)decoder.DecodeOptionalInt8(_addedOptScalarProperties);
  771. _addedOptStructure = (SmallStructure)decoder.DecodeOptionalStructure(SmallStructureFactory.Instance, _addedOptStructureProperties);
  772. _addedReqPointer = (string)decoder.DecodeRequiredString(_addedReqPointerProperties);
  773. _addedReqScalar = (byte)decoder.DecodeRequiredInt8(_addedReqScalarProperties);
  774. _addedReqStructure = (SmallStructure)decoder.DecodeRequiredStructure(SmallStructureFactory.Instance, _addedReqStructureProperties);
  775. remainingFields -= 6;
  776. decodedUpToVersion = 2;
  777. }
  778. else
  779. {
  780. if (remainingFields != 0) throw new PinchInvalidCodingException();
  781. OnMissingNewFields(decodedUpToVersion, 2);
  782. }
  783. if (remainingFields > 0)
  784. {
  785. OnAdditionalFutureFields(decoder);
  786. decoder.SkipFields(remainingFields);
  787. }
  788. decoder.CloseSequence();
  789. }
  790. #region INotifyPropertyChanged Members
  791. public event PropertyChangedEventHandler PropertyChanged;
  792. protected void FirePropertyChanged(string propertyName)
  793. {
  794. if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  795. }
  796. #endregion
  797. }
  798. public enum TypesEnumeration
  799. {
  800. A = 1,
  801. B = 2,
  802. C = 3
  803. }
  804. public class TypesStructureFactory : IPinchableFactory
  805. {
  806. static TypesStructureFactory _instance = new TypesStructureFactory();
  807. public object Create(IPinchDecodingContext context)
  808. {
  809. return new TypesStructure(context);
  810. }
  811. public static IPinchableFactory Instance
  812. {
  813. get
  814. {
  815. return _instance;
  816. }
  817. }
  818. }
  819. public partial class TypesStructure : IPinchable, INotifyPropertyChanged
  820. {
  821. float _reqFloat32;
  822. double _reqFloat64;
  823. byte _reqInt8;
  824. short _reqInt16;
  825. int _reqInt32;
  826. long _reqInt64;
  827. decimal _reqDecimal;
  828. bool _reqBool;
  829. string _reqString;
  830. byte[] _reqBytes;
  831. TypesEnumeration _reqEnumeration;
  832. SmallStructure _reqStructure;
  833. List<SmallStructure> _reqListOfEnum;
  834. float? _optFloat32;
  835. double? _optFloat64;
  836. byte? _optInt8;
  837. short? _optInt16;
  838. int? _optInt32;
  839. long? _optInt64;
  840. decimal? _optDecimal;
  841. bool? _optBool;
  842. string _optString;
  843. byte[] _optBytes;
  844. TypesEnumeration? _optEnumeration;
  845. SmallStructure _optStructure;
  846. List<SmallStructure> _optListOfEnum;
  847. static PinchFieldProperties _reqFloat32Properties = new PinchFieldProperties(18, 1, null);
  848. static PinchFieldProperties _reqFloat64Properties = new PinchFieldProperties(19, 1, null);
  849. static PinchFieldProperties _reqInt8Properties = new PinchFieldProperties(23, 1, null);
  850. static PinchFieldProperties _reqInt16Properties = new PinchFieldProperties(20, 1, null);
  851. static PinchFieldProperties _reqInt32Properties = new PinchFieldProperties(21, 1, null);
  852. static PinchFieldProperties _reqInt64Properties = new PinchFieldProperties(22, 1, null);
  853. static PinchFieldProperties _reqDecimalProperties = new PinchFieldProperties(16, 1, null);
  854. static PinchFieldProperties _reqBoolProperties = new PinchFieldProperties(14, 1, null);
  855. static PinchFieldProperties _reqStringProperties = new PinchFieldProperties(25, 1, null);
  856. static PinchFieldProperties _reqBytesProperties = new PinchFieldProperties(15, 1, null);
  857. static PinchFieldProperties _reqEnumerationProperties = new PinchFieldProperties(17, 1, null);
  858. static PinchFieldProperties _reqStructureProperties = new PinchFieldProperties(26, 1, null);
  859. static PinchFieldProperties _reqListOfEnumProperties = new PinchFieldProperties(24, 1, null);
  860. static PinchFieldProperties _optFloat32Properties = new PinchFieldProperties(5, 1, null);
  861. static PinchFieldProperties _optFloat64Properties = new PinchFieldProperties(6, 1, null);
  862. static PinchFieldProperties _optInt8Properties = new PinchFieldProperties(10, 1, null);
  863. static PinchFieldProperties _optInt16Properties = new PinchFieldProperties(7, 1, null);
  864. static PinchFieldProperties _optInt32Properties = new PinchFieldProperties(8, 1, null);
  865. static PinchFieldProperties _optInt64Properties = new PinchFieldProperties(9, 1, null);
  866. static PinchFieldProperties _optDecimalProperties = new PinchFieldProperties(3, 1, null);
  867. static PinchFieldProperties _optBoolProperties = new PinchFieldProperties(1, 1, null);
  868. static PinchFieldProperties _optStringProperties = new PinchFieldProperties(12, 1, null);
  869. static PinchFieldProperties _optBytesProperties = new PinchFieldProperties(2, 1, null);
  870. static PinchFieldProperties _optEnumerationProperties = new PinchFieldProperties(4, 1, null);
  871. static PinchFieldProperties _optStructureProperties = new PinchFieldProperties(13, 1, null);
  872. static PinchFieldProperties _optListOfEnumProperties = new PinchFieldProperties(11, 1, null);
  873. public TypesStructure()
  874. {
  875. _reqListOfEnum = new List<SmallStructure>();
  876. _optListOfEnum = new List<SmallStructure>();
  877. }
  878. public TypesStructure(IPinchDecodingContext context)
  879. {
  880. }
  881. public float ReqFloat32
  882. {
  883. get { return _reqFloat32; }
  884. set
  885. {
  886. _reqFloat32 = value;
  887. FirePropertyChanged("ReqFloat32");
  888. }
  889. }
  890. public double ReqFloat64
  891. {
  892. get { return _reqFloat64; }
  893. set
  894. {
  895. _reqFloat64 = value;
  896. FirePropertyChanged("ReqFloat64");
  897. }
  898. }
  899. public byte ReqInt8
  900. {
  901. get { return _reqInt8; }
  902. set
  903. {
  904. _reqInt8 = value;
  905. FirePropertyChanged("ReqInt8");
  906. }
  907. }
  908. public short ReqInt16
  909. {
  910. get { return _reqInt16; }
  911. set
  912. {
  913. _reqInt16 = value;
  914. FirePropertyChanged("ReqInt16");
  915. }
  916. }
  917. public int ReqInt32
  918. {
  919. get { return _reqInt32; }
  920. set
  921. {
  922. _reqInt32 = value;
  923. FirePropertyChanged("ReqInt32");
  924. }
  925. }
  926. public long ReqInt64
  927. {
  928. get { return _reqInt64; }
  929. set
  930. {
  931. _reqInt64 = value;
  932. FirePropertyChanged("ReqInt64");
  933. }
  934. }
  935. public decimal ReqDecimal
  936. {
  937. get { return _reqDecimal; }
  938. set
  939. {
  940. _reqDecimal = value;
  941. FirePropertyChanged("ReqDecimal");
  942. }
  943. }
  944. public bool ReqBool
  945. {
  946. get { return _reqBool; }
  947. set
  948. {
  949. _reqBool = value;
  950. FirePropertyChanged("ReqBool");
  951. }
  952. }
  953. public string ReqString
  954. {
  955. get { return _reqString; }
  956. set
  957. {
  958. _reqString = value;
  959. FirePropertyChanged("ReqString");
  960. }
  961. }
  962. public byte[] ReqBytes
  963. {
  964. get { return _reqBytes; }
  965. set
  966. {
  967. _reqBytes = value;
  968. FirePropertyChanged("ReqBytes");
  969. }
  970. }
  971. public TypesEnumeration ReqEnumeration
  972. {
  973. get { return _reqEnumeration; }
  974. set
  975. {
  976. _reqEnumeration = value;
  977. FirePropertyChanged("ReqEnumeration");
  978. }
  979. }
  980. public SmallStructure ReqStructure
  981. {
  982. get { return _reqStructure; }
  983. set
  984. {
  985. _reqStructure = value;
  986. FirePropertyChanged("ReqStructure");
  987. }
  988. }
  989. public List<SmallStructure> ReqListOfEnum
  990. {
  991. get { return _reqListOfEnum; }
  992. set
  993. {
  994. _reqListOfEnum = value;
  995. FirePropertyChanged("ReqListOfEnum");
  996. }
  997. }
  998. public float? OptFloat32
  999. {
  1000. get { return _optFloat32; }
  1001. set
  1002. {
  1003. _optFloat32 = value;
  1004. FirePropertyChanged("OptFloat32");
  1005. }
  1006. }
  1007. public double? OptFloat64
  1008. {
  1009. get { return _optFloat64; }
  1010. set
  1011. {
  1012. _optFloat64 = value;
  1013. FirePropertyChanged("OptFloat64");
  1014. }
  1015. }
  1016. public byte? OptInt8
  1017. {
  1018. get { return _optInt8; }
  1019. set
  1020. {
  1021. _optInt8 = value;
  1022. FirePropertyChanged("OptInt8");
  1023. }
  1024. }
  1025. public short? OptInt16
  1026. {
  1027. get { return _optInt16; }
  1028. set
  1029. {
  1030. _optInt16 = value;
  1031. FirePropertyChanged("OptInt16");
  1032. }
  1033. }
  1034. public int? OptInt32
  1035. {
  1036. get { return _optInt32; }
  1037. set
  1038. {
  1039. _optInt32 = value;
  1040. FirePropertyChanged("OptInt32");
  1041. }
  1042. }
  1043. public long? OptInt64
  1044. {
  1045. get { return _optInt64; }
  1046. set
  1047. {
  1048. _optInt64 = value;
  1049. FirePropertyChanged("OptInt64");
  1050. }
  1051. }
  1052. public decimal? OptDecimal
  1053. {
  1054. get { return _optDecimal; }
  1055. set
  1056. {
  1057. _optDecimal = value;
  1058. FirePropertyChanged("OptDecimal");
  1059. }
  1060. }
  1061. public bool? OptBool
  1062. {
  1063. get { return _optBool; }
  1064. set
  1065. {
  1066. _optBool = value;
  1067. FirePropertyChanged("OptBool");
  1068. }
  1069. }
  1070. public string OptString
  1071. {
  1072. get { return _optString; }
  1073. set
  1074. {
  1075. _optString = value;
  1076. FirePropertyChanged("OptString");
  1077. }
  1078. }
  1079. public byte[] OptBytes
  1080. {
  1081. get { return _optBytes; }
  1082. set
  1083. {
  1084. _optBytes = value;
  1085. FirePropertyChanged("OptBytes");
  1086. }
  1087. }
  1088. public TypesEnumeration? OptEnumeration
  1089. {
  1090. get { return _optEnumeration; }
  1091. set
  1092. {
  1093. _optEnumeration = value;
  1094. FirePropertyChanged("OptEnumeration");
  1095. }
  1096. }
  1097. public SmallStructure OptStructure
  1098. {
  1099. get { return _optStructure; }
  1100. set
  1101. {
  1102. _optStructure = value;
  1103. FirePropertyChanged("OptStructure");
  1104. }
  1105. }
  1106. public List<SmallStructure> OptListOfEnum
  1107. {
  1108. get { return _optListOfEnum; }
  1109. set
  1110. {
  1111. _optListOfEnum = value;
  1112. FirePropertyChanged("OptListOfEnum");
  1113. }
  1114. }
  1115. int IPinchable.ProtocolVersion
  1116. {
  1117. get
  1118. {
  1119. return 3;
  1120. }
  1121. }
  1122. protected virtual void OnAdditionalFutureFields(IPinchDecoder decoder)
  1123. {
  1124. }
  1125. void IPinchable.Encode(IPinchEncoder encoder)
  1126. {
  1127. encoder.OpenSequence(26);
  1128. // Encode fields for version 1:
  1129. encoder.EncodeOptionalBool(_optBool, _optBoolProperties);
  1130. encoder.EncodeOptionalBytes(_optBytes, _optBytesProperties);
  1131. encoder.EncodeOptionalDecimal(_optDecimal, _optDecimalProperties);
  1132. encoder.EncodeOptionalEnumeration(_optEnumeration, _optEnumerationProperties);
  1133. encoder.EncodeOptionalFloat32(_optFloat32, _optFloat32Properties);
  1134. encoder.EncodeOptionalFloat64(_optFloat64, _optFloat64Properties);
  1135. encoder.EncodeOptionalInt16(_optInt16, _optInt16Properties);
  1136. encoder.EncodeOptionalInt32(_optInt32, _optInt32Properties);
  1137. encoder.EncodeOptionalInt64(_optInt64, _optInt64Properties);
  1138. encoder.EncodeOptionalInt8(_optInt8, _optInt8Properties);
  1139. encoder.OpenSequence(_optListOfEnum.Count);
  1140. foreach (SmallStructure value in _optListOfEnum)
  1141. {
  1142. encoder.EncodeOptionalStructure(value, _optListOfEnumProperties);
  1143. }
  1144. encoder.CloseSequence();
  1145. encoder.EncodeOptionalString(_optString, _optStringProperties);
  1146. encoder.EncodeOptionalStructure(_optStructure, _optStructureProperties);
  1147. encoder.EncodeRequiredBool(_reqBool, _reqBoolProperties);
  1148. encoder.EncodeRequiredBytes(_reqBytes, _reqBytesProperties);
  1149. encoder.EncodeRequiredDecimal(_reqDecimal, _reqDecimalProperties);
  1150. encoder.EncodeRequiredEnumeration(_reqEnumeration, _reqEnumerationProperties);
  1151. encoder.EncodeRequiredFloat32(_reqFloat32, _reqFloat32Properties);
  1152. encoder.EncodeRequiredFloat64(_reqFloat64, _reqFloat64Properties);
  1153. encoder.EncodeRequiredInt16(_reqInt16, _reqInt16Properties);
  1154. encoder.EncodeRequiredInt32(_reqInt32, _reqInt32Properties);
  1155. encoder.EncodeRequiredInt64(_reqInt64, _reqInt64Properties);
  1156. encoder.EncodeRequiredInt8(_reqInt8, _reqInt8Properties);
  1157. encoder.OpenSequence(_reqListOfEnum.Count);
  1158. foreach (SmallStructure value in _reqListOfEnum)
  1159. {
  1160. encoder.EncodeRequiredStructure(value, _reqListOfEnumProperties);
  1161. }
  1162. encoder.CloseSequence();
  1163. encoder.EncodeRequiredString(_reqString, _reqStringProperties);
  1164. encoder.EncodeRequiredStructure(_reqStructure, _reqStructureProperties);
  1165. encoder.CloseSequence();
  1166. }
  1167. void IPinchable.Decode(IPinchDecoder decoder)
  1168. {
  1169. int remainingFields = decoder.OpenSequence();
  1170. // Decode members for version 1:
  1171. if (remainingFields >= 26)
  1172. {
  1173. _optBool = (bool?)decoder.DecodeOptionalBool(_optBoolProperties);
  1174. _optBytes = (byte[])decoder.DecodeOptionalBytes(_optBytesProperties);
  1175. _optDecimal = (decimal?)decoder.DecodeOptionalDecimal(_optDecimalProperties);
  1176. _optEnumeration = (TypesEnumeration?)decoder.DecodeOptionalEnumeration(_optEnumerationProperties);
  1177. _optFloat32 = (float?)decoder.DecodeOptionalFloat32(_optFloat32Properties);
  1178. _optFloat64 = (double?)decoder.DecodeOptionalFloat64(_optFloat64Properties);
  1179. _optInt16 = (short?)decoder.DecodeOptionalInt16(_optInt16Properties);
  1180. _optInt32 = (int?)decoder.DecodeOptionalInt32(_optInt32Properties);
  1181. _optInt64 = (long?)decoder.DecodeOptionalInt64(_optInt64Properties);
  1182. _optInt8 = (byte?)decoder.DecodeOptionalInt8(_optInt8Properties);
  1183. int optListOfEnumCount = decoder.OpenSequence();
  1184. _optListOfEnum = new List<SmallStructure>();
  1185. for (int i = 0; i < optListOfEnumCount; i++)
  1186. {
  1187. _optListOfEnum.Add((SmallStructure)decoder.DecodeOptionalStructure(SmallStructureFactory.Instance, _optListOfEnumProperties));
  1188. }
  1189. decoder.CloseSequence();
  1190. _optString = (string)decoder.DecodeOptionalString(_optStringProperties);
  1191. _optStructure = (SmallStructure)decoder.DecodeOptionalStructure(SmallStructureFactory.Instance, _optStructureProperties);
  1192. _reqBool = (bool)decoder.DecodeRequiredBool(_reqBoolProperties);
  1193. _reqBytes = (byte[])decoder.DecodeRequiredBytes(_reqBytesProperties);
  1194. _reqDecimal = (decimal)decoder.DecodeRequiredDecimal(_reqDecimalProperties);
  1195. _reqEnumeration = (TypesEnumeration)decoder.DecodeRequiredEnumeration(_reqEnumerationProperties);
  1196. _reqFloat32 = (float)decoder.DecodeRequiredFloat32(_reqFloat32Properties);
  1197. _reqFloat64 = (double)decoder.DecodeRequiredFloat64(_reqFloat64Properties);
  1198. _reqInt16 = (short)decoder.DecodeRequiredInt16(_reqInt16Properties);
  1199. _reqInt32 = (int)decoder.DecodeRequiredInt32(_reqInt32Properties);
  1200. _reqInt64 = (long)decoder.DecodeRequiredInt64(_reqInt64Properties);
  1201. _reqInt8 = (byte)decoder.DecodeRequiredInt8(_reqInt8Properties);
  1202. int reqListOfEnumCount = decoder.OpenSequence();
  1203. _reqListOfEnum = new List<SmallStructure>();
  1204. for (int i = 0; i

Large files files are truncated, but you can click here to view the full file