1
0

message_xdr.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. // Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
  2. // All rights reserved. Use of this source code is governed by an MIT-style
  3. // license that can be found in the LICENSE file.
  4. // ************************************************************
  5. // This file is automatically generated by genxdr. Do not edit.
  6. // ************************************************************
  7. package protocol
  8. import (
  9. "bytes"
  10. "io"
  11. "github.com/calmh/syncthing/xdr"
  12. )
  13. /*
  14. IndexMessage Structure:
  15. 0 1 2 3
  16. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  17. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  18. | Length of Repository |
  19. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  20. / /
  21. \ Repository (variable length) \
  22. / /
  23. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  24. | Number of Files |
  25. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  26. / /
  27. \ Zero or more FileInfo Structures \
  28. / /
  29. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  30. struct IndexMessage {
  31. string Repository<64>;
  32. FileInfo Files<10000000>;
  33. }
  34. */
  35. func (o IndexMessage) EncodeXDR(w io.Writer) (int, error) {
  36. var xw = xdr.NewWriter(w)
  37. return o.encodeXDR(xw)
  38. }
  39. func (o IndexMessage) MarshalXDR() []byte {
  40. return o.AppendXDR(make([]byte, 0, 128))
  41. }
  42. func (o IndexMessage) AppendXDR(bs []byte) []byte {
  43. var aw = xdr.AppendWriter(bs)
  44. var xw = xdr.NewWriter(&aw)
  45. o.encodeXDR(xw)
  46. return []byte(aw)
  47. }
  48. func (o IndexMessage) encodeXDR(xw *xdr.Writer) (int, error) {
  49. if len(o.Repository) > 64 {
  50. return xw.Tot(), xdr.ErrElementSizeExceeded
  51. }
  52. xw.WriteString(o.Repository)
  53. if len(o.Files) > 10000000 {
  54. return xw.Tot(), xdr.ErrElementSizeExceeded
  55. }
  56. xw.WriteUint32(uint32(len(o.Files)))
  57. for i := range o.Files {
  58. o.Files[i].encodeXDR(xw)
  59. }
  60. return xw.Tot(), xw.Error()
  61. }
  62. func (o *IndexMessage) DecodeXDR(r io.Reader) error {
  63. xr := xdr.NewReader(r)
  64. return o.decodeXDR(xr)
  65. }
  66. func (o *IndexMessage) UnmarshalXDR(bs []byte) error {
  67. var br = bytes.NewReader(bs)
  68. var xr = xdr.NewReader(br)
  69. return o.decodeXDR(xr)
  70. }
  71. func (o *IndexMessage) decodeXDR(xr *xdr.Reader) error {
  72. o.Repository = xr.ReadStringMax(64)
  73. _FilesSize := int(xr.ReadUint32())
  74. if _FilesSize > 10000000 {
  75. return xdr.ErrElementSizeExceeded
  76. }
  77. o.Files = make([]FileInfo, _FilesSize)
  78. for i := range o.Files {
  79. (&o.Files[i]).decodeXDR(xr)
  80. }
  81. return xr.Error()
  82. }
  83. /*
  84. FileInfo Structure:
  85. 0 1 2 3
  86. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  87. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  88. | Length of Name |
  89. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  90. / /
  91. \ Name (variable length) \
  92. / /
  93. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  94. | Flags |
  95. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  96. | |
  97. + Modified (64 bits) +
  98. | |
  99. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  100. | |
  101. + Version (64 bits) +
  102. | |
  103. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  104. | Number of Blocks |
  105. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  106. / /
  107. \ Zero or more BlockInfo Structures \
  108. / /
  109. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  110. struct FileInfo {
  111. string Name<1024>;
  112. unsigned int Flags;
  113. hyper Modified;
  114. unsigned hyper Version;
  115. BlockInfo Blocks<1000000>;
  116. }
  117. */
  118. func (o FileInfo) EncodeXDR(w io.Writer) (int, error) {
  119. var xw = xdr.NewWriter(w)
  120. return o.encodeXDR(xw)
  121. }
  122. func (o FileInfo) MarshalXDR() []byte {
  123. return o.AppendXDR(make([]byte, 0, 128))
  124. }
  125. func (o FileInfo) AppendXDR(bs []byte) []byte {
  126. var aw = xdr.AppendWriter(bs)
  127. var xw = xdr.NewWriter(&aw)
  128. o.encodeXDR(xw)
  129. return []byte(aw)
  130. }
  131. func (o FileInfo) encodeXDR(xw *xdr.Writer) (int, error) {
  132. if len(o.Name) > 1024 {
  133. return xw.Tot(), xdr.ErrElementSizeExceeded
  134. }
  135. xw.WriteString(o.Name)
  136. xw.WriteUint32(o.Flags)
  137. xw.WriteUint64(uint64(o.Modified))
  138. xw.WriteUint64(o.Version)
  139. if len(o.Blocks) > 1000000 {
  140. return xw.Tot(), xdr.ErrElementSizeExceeded
  141. }
  142. xw.WriteUint32(uint32(len(o.Blocks)))
  143. for i := range o.Blocks {
  144. o.Blocks[i].encodeXDR(xw)
  145. }
  146. return xw.Tot(), xw.Error()
  147. }
  148. func (o *FileInfo) DecodeXDR(r io.Reader) error {
  149. xr := xdr.NewReader(r)
  150. return o.decodeXDR(xr)
  151. }
  152. func (o *FileInfo) UnmarshalXDR(bs []byte) error {
  153. var br = bytes.NewReader(bs)
  154. var xr = xdr.NewReader(br)
  155. return o.decodeXDR(xr)
  156. }
  157. func (o *FileInfo) decodeXDR(xr *xdr.Reader) error {
  158. o.Name = xr.ReadStringMax(1024)
  159. o.Flags = xr.ReadUint32()
  160. o.Modified = int64(xr.ReadUint64())
  161. o.Version = xr.ReadUint64()
  162. _BlocksSize := int(xr.ReadUint32())
  163. if _BlocksSize > 1000000 {
  164. return xdr.ErrElementSizeExceeded
  165. }
  166. o.Blocks = make([]BlockInfo, _BlocksSize)
  167. for i := range o.Blocks {
  168. (&o.Blocks[i]).decodeXDR(xr)
  169. }
  170. return xr.Error()
  171. }
  172. /*
  173. BlockInfo Structure:
  174. 0 1 2 3
  175. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  176. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  177. | Size |
  178. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  179. | Length of Hash |
  180. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  181. / /
  182. \ Hash (variable length) \
  183. / /
  184. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  185. struct BlockInfo {
  186. unsigned int Size;
  187. opaque Hash<64>;
  188. }
  189. */
  190. func (o BlockInfo) EncodeXDR(w io.Writer) (int, error) {
  191. var xw = xdr.NewWriter(w)
  192. return o.encodeXDR(xw)
  193. }
  194. func (o BlockInfo) MarshalXDR() []byte {
  195. return o.AppendXDR(make([]byte, 0, 128))
  196. }
  197. func (o BlockInfo) AppendXDR(bs []byte) []byte {
  198. var aw = xdr.AppendWriter(bs)
  199. var xw = xdr.NewWriter(&aw)
  200. o.encodeXDR(xw)
  201. return []byte(aw)
  202. }
  203. func (o BlockInfo) encodeXDR(xw *xdr.Writer) (int, error) {
  204. xw.WriteUint32(o.Size)
  205. if len(o.Hash) > 64 {
  206. return xw.Tot(), xdr.ErrElementSizeExceeded
  207. }
  208. xw.WriteBytes(o.Hash)
  209. return xw.Tot(), xw.Error()
  210. }
  211. func (o *BlockInfo) DecodeXDR(r io.Reader) error {
  212. xr := xdr.NewReader(r)
  213. return o.decodeXDR(xr)
  214. }
  215. func (o *BlockInfo) UnmarshalXDR(bs []byte) error {
  216. var br = bytes.NewReader(bs)
  217. var xr = xdr.NewReader(br)
  218. return o.decodeXDR(xr)
  219. }
  220. func (o *BlockInfo) decodeXDR(xr *xdr.Reader) error {
  221. o.Size = xr.ReadUint32()
  222. o.Hash = xr.ReadBytesMax(64)
  223. return xr.Error()
  224. }
  225. /*
  226. RequestMessage Structure:
  227. 0 1 2 3
  228. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  229. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  230. | Length of Repository |
  231. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  232. / /
  233. \ Repository (variable length) \
  234. / /
  235. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  236. | Length of Name |
  237. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  238. / /
  239. \ Name (variable length) \
  240. / /
  241. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  242. | |
  243. + Offset (64 bits) +
  244. | |
  245. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  246. | Size |
  247. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  248. struct RequestMessage {
  249. string Repository<64>;
  250. string Name<1024>;
  251. unsigned hyper Offset;
  252. unsigned int Size;
  253. }
  254. */
  255. func (o RequestMessage) EncodeXDR(w io.Writer) (int, error) {
  256. var xw = xdr.NewWriter(w)
  257. return o.encodeXDR(xw)
  258. }
  259. func (o RequestMessage) MarshalXDR() []byte {
  260. return o.AppendXDR(make([]byte, 0, 128))
  261. }
  262. func (o RequestMessage) AppendXDR(bs []byte) []byte {
  263. var aw = xdr.AppendWriter(bs)
  264. var xw = xdr.NewWriter(&aw)
  265. o.encodeXDR(xw)
  266. return []byte(aw)
  267. }
  268. func (o RequestMessage) encodeXDR(xw *xdr.Writer) (int, error) {
  269. if len(o.Repository) > 64 {
  270. return xw.Tot(), xdr.ErrElementSizeExceeded
  271. }
  272. xw.WriteString(o.Repository)
  273. if len(o.Name) > 1024 {
  274. return xw.Tot(), xdr.ErrElementSizeExceeded
  275. }
  276. xw.WriteString(o.Name)
  277. xw.WriteUint64(o.Offset)
  278. xw.WriteUint32(o.Size)
  279. return xw.Tot(), xw.Error()
  280. }
  281. func (o *RequestMessage) DecodeXDR(r io.Reader) error {
  282. xr := xdr.NewReader(r)
  283. return o.decodeXDR(xr)
  284. }
  285. func (o *RequestMessage) UnmarshalXDR(bs []byte) error {
  286. var br = bytes.NewReader(bs)
  287. var xr = xdr.NewReader(br)
  288. return o.decodeXDR(xr)
  289. }
  290. func (o *RequestMessage) decodeXDR(xr *xdr.Reader) error {
  291. o.Repository = xr.ReadStringMax(64)
  292. o.Name = xr.ReadStringMax(1024)
  293. o.Offset = xr.ReadUint64()
  294. o.Size = xr.ReadUint32()
  295. return xr.Error()
  296. }
  297. /*
  298. ClusterConfigMessage Structure:
  299. 0 1 2 3
  300. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  301. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  302. | Length of Client Name |
  303. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  304. / /
  305. \ Client Name (variable length) \
  306. / /
  307. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  308. | Length of Client Version |
  309. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  310. / /
  311. \ Client Version (variable length) \
  312. / /
  313. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  314. | Number of Repositories |
  315. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  316. / /
  317. \ Zero or more Repository Structures \
  318. / /
  319. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  320. | Number of Options |
  321. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  322. / /
  323. \ Zero or more Option Structures \
  324. / /
  325. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  326. struct ClusterConfigMessage {
  327. string ClientName<64>;
  328. string ClientVersion<64>;
  329. Repository Repositories<64>;
  330. Option Options<64>;
  331. }
  332. */
  333. func (o ClusterConfigMessage) EncodeXDR(w io.Writer) (int, error) {
  334. var xw = xdr.NewWriter(w)
  335. return o.encodeXDR(xw)
  336. }
  337. func (o ClusterConfigMessage) MarshalXDR() []byte {
  338. return o.AppendXDR(make([]byte, 0, 128))
  339. }
  340. func (o ClusterConfigMessage) AppendXDR(bs []byte) []byte {
  341. var aw = xdr.AppendWriter(bs)
  342. var xw = xdr.NewWriter(&aw)
  343. o.encodeXDR(xw)
  344. return []byte(aw)
  345. }
  346. func (o ClusterConfigMessage) encodeXDR(xw *xdr.Writer) (int, error) {
  347. if len(o.ClientName) > 64 {
  348. return xw.Tot(), xdr.ErrElementSizeExceeded
  349. }
  350. xw.WriteString(o.ClientName)
  351. if len(o.ClientVersion) > 64 {
  352. return xw.Tot(), xdr.ErrElementSizeExceeded
  353. }
  354. xw.WriteString(o.ClientVersion)
  355. if len(o.Repositories) > 64 {
  356. return xw.Tot(), xdr.ErrElementSizeExceeded
  357. }
  358. xw.WriteUint32(uint32(len(o.Repositories)))
  359. for i := range o.Repositories {
  360. o.Repositories[i].encodeXDR(xw)
  361. }
  362. if len(o.Options) > 64 {
  363. return xw.Tot(), xdr.ErrElementSizeExceeded
  364. }
  365. xw.WriteUint32(uint32(len(o.Options)))
  366. for i := range o.Options {
  367. o.Options[i].encodeXDR(xw)
  368. }
  369. return xw.Tot(), xw.Error()
  370. }
  371. func (o *ClusterConfigMessage) DecodeXDR(r io.Reader) error {
  372. xr := xdr.NewReader(r)
  373. return o.decodeXDR(xr)
  374. }
  375. func (o *ClusterConfigMessage) UnmarshalXDR(bs []byte) error {
  376. var br = bytes.NewReader(bs)
  377. var xr = xdr.NewReader(br)
  378. return o.decodeXDR(xr)
  379. }
  380. func (o *ClusterConfigMessage) decodeXDR(xr *xdr.Reader) error {
  381. o.ClientName = xr.ReadStringMax(64)
  382. o.ClientVersion = xr.ReadStringMax(64)
  383. _RepositoriesSize := int(xr.ReadUint32())
  384. if _RepositoriesSize > 64 {
  385. return xdr.ErrElementSizeExceeded
  386. }
  387. o.Repositories = make([]Repository, _RepositoriesSize)
  388. for i := range o.Repositories {
  389. (&o.Repositories[i]).decodeXDR(xr)
  390. }
  391. _OptionsSize := int(xr.ReadUint32())
  392. if _OptionsSize > 64 {
  393. return xdr.ErrElementSizeExceeded
  394. }
  395. o.Options = make([]Option, _OptionsSize)
  396. for i := range o.Options {
  397. (&o.Options[i]).decodeXDR(xr)
  398. }
  399. return xr.Error()
  400. }
  401. /*
  402. Repository Structure:
  403. 0 1 2 3
  404. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  405. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  406. | Length of ID |
  407. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  408. / /
  409. \ ID (variable length) \
  410. / /
  411. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  412. | Number of Nodes |
  413. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  414. / /
  415. \ Zero or more Node Structures \
  416. / /
  417. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  418. struct Repository {
  419. string ID<64>;
  420. Node Nodes<64>;
  421. }
  422. */
  423. func (o Repository) EncodeXDR(w io.Writer) (int, error) {
  424. var xw = xdr.NewWriter(w)
  425. return o.encodeXDR(xw)
  426. }
  427. func (o Repository) MarshalXDR() []byte {
  428. return o.AppendXDR(make([]byte, 0, 128))
  429. }
  430. func (o Repository) AppendXDR(bs []byte) []byte {
  431. var aw = xdr.AppendWriter(bs)
  432. var xw = xdr.NewWriter(&aw)
  433. o.encodeXDR(xw)
  434. return []byte(aw)
  435. }
  436. func (o Repository) encodeXDR(xw *xdr.Writer) (int, error) {
  437. if len(o.ID) > 64 {
  438. return xw.Tot(), xdr.ErrElementSizeExceeded
  439. }
  440. xw.WriteString(o.ID)
  441. if len(o.Nodes) > 64 {
  442. return xw.Tot(), xdr.ErrElementSizeExceeded
  443. }
  444. xw.WriteUint32(uint32(len(o.Nodes)))
  445. for i := range o.Nodes {
  446. o.Nodes[i].encodeXDR(xw)
  447. }
  448. return xw.Tot(), xw.Error()
  449. }
  450. func (o *Repository) DecodeXDR(r io.Reader) error {
  451. xr := xdr.NewReader(r)
  452. return o.decodeXDR(xr)
  453. }
  454. func (o *Repository) UnmarshalXDR(bs []byte) error {
  455. var br = bytes.NewReader(bs)
  456. var xr = xdr.NewReader(br)
  457. return o.decodeXDR(xr)
  458. }
  459. func (o *Repository) decodeXDR(xr *xdr.Reader) error {
  460. o.ID = xr.ReadStringMax(64)
  461. _NodesSize := int(xr.ReadUint32())
  462. if _NodesSize > 64 {
  463. return xdr.ErrElementSizeExceeded
  464. }
  465. o.Nodes = make([]Node, _NodesSize)
  466. for i := range o.Nodes {
  467. (&o.Nodes[i]).decodeXDR(xr)
  468. }
  469. return xr.Error()
  470. }
  471. /*
  472. Node Structure:
  473. 0 1 2 3
  474. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  475. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  476. | Length of ID |
  477. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  478. / /
  479. \ ID (variable length) \
  480. / /
  481. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  482. | Flags |
  483. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  484. | |
  485. + Max Version (64 bits) +
  486. | |
  487. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  488. struct Node {
  489. opaque ID<32>;
  490. unsigned int Flags;
  491. unsigned hyper MaxVersion;
  492. }
  493. */
  494. func (o Node) EncodeXDR(w io.Writer) (int, error) {
  495. var xw = xdr.NewWriter(w)
  496. return o.encodeXDR(xw)
  497. }
  498. func (o Node) MarshalXDR() []byte {
  499. return o.AppendXDR(make([]byte, 0, 128))
  500. }
  501. func (o Node) AppendXDR(bs []byte) []byte {
  502. var aw = xdr.AppendWriter(bs)
  503. var xw = xdr.NewWriter(&aw)
  504. o.encodeXDR(xw)
  505. return []byte(aw)
  506. }
  507. func (o Node) encodeXDR(xw *xdr.Writer) (int, error) {
  508. if len(o.ID) > 32 {
  509. return xw.Tot(), xdr.ErrElementSizeExceeded
  510. }
  511. xw.WriteBytes(o.ID)
  512. xw.WriteUint32(o.Flags)
  513. xw.WriteUint64(o.MaxVersion)
  514. return xw.Tot(), xw.Error()
  515. }
  516. func (o *Node) DecodeXDR(r io.Reader) error {
  517. xr := xdr.NewReader(r)
  518. return o.decodeXDR(xr)
  519. }
  520. func (o *Node) UnmarshalXDR(bs []byte) error {
  521. var br = bytes.NewReader(bs)
  522. var xr = xdr.NewReader(br)
  523. return o.decodeXDR(xr)
  524. }
  525. func (o *Node) decodeXDR(xr *xdr.Reader) error {
  526. o.ID = xr.ReadBytesMax(32)
  527. o.Flags = xr.ReadUint32()
  528. o.MaxVersion = xr.ReadUint64()
  529. return xr.Error()
  530. }
  531. /*
  532. Option Structure:
  533. 0 1 2 3
  534. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  535. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  536. | Length of Key |
  537. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  538. / /
  539. \ Key (variable length) \
  540. / /
  541. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  542. | Length of Value |
  543. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  544. / /
  545. \ Value (variable length) \
  546. / /
  547. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  548. struct Option {
  549. string Key<64>;
  550. string Value<1024>;
  551. }
  552. */
  553. func (o Option) EncodeXDR(w io.Writer) (int, error) {
  554. var xw = xdr.NewWriter(w)
  555. return o.encodeXDR(xw)
  556. }
  557. func (o Option) MarshalXDR() []byte {
  558. return o.AppendXDR(make([]byte, 0, 128))
  559. }
  560. func (o Option) AppendXDR(bs []byte) []byte {
  561. var aw = xdr.AppendWriter(bs)
  562. var xw = xdr.NewWriter(&aw)
  563. o.encodeXDR(xw)
  564. return []byte(aw)
  565. }
  566. func (o Option) encodeXDR(xw *xdr.Writer) (int, error) {
  567. if len(o.Key) > 64 {
  568. return xw.Tot(), xdr.ErrElementSizeExceeded
  569. }
  570. xw.WriteString(o.Key)
  571. if len(o.Value) > 1024 {
  572. return xw.Tot(), xdr.ErrElementSizeExceeded
  573. }
  574. xw.WriteString(o.Value)
  575. return xw.Tot(), xw.Error()
  576. }
  577. func (o *Option) DecodeXDR(r io.Reader) error {
  578. xr := xdr.NewReader(r)
  579. return o.decodeXDR(xr)
  580. }
  581. func (o *Option) UnmarshalXDR(bs []byte) error {
  582. var br = bytes.NewReader(bs)
  583. var xr = xdr.NewReader(br)
  584. return o.decodeXDR(xr)
  585. }
  586. func (o *Option) decodeXDR(xr *xdr.Reader) error {
  587. o.Key = xr.ReadStringMax(64)
  588. o.Value = xr.ReadStringMax(1024)
  589. return xr.Error()
  590. }