message_xdr.go 22 KB

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