PageRenderTime 52ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

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

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