message_xdr.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  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. ResponseMessage 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 Data |
  298. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  299. / /
  300. \ Data (variable length) \
  301. / /
  302. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  303. struct ResponseMessage {
  304. opaque Data<>;
  305. }
  306. */
  307. func (o ResponseMessage) EncodeXDR(w io.Writer) (int, error) {
  308. var xw = xdr.NewWriter(w)
  309. return o.encodeXDR(xw)
  310. }
  311. func (o ResponseMessage) MarshalXDR() []byte {
  312. return o.AppendXDR(make([]byte, 0, 128))
  313. }
  314. func (o ResponseMessage) AppendXDR(bs []byte) []byte {
  315. var aw = xdr.AppendWriter(bs)
  316. var xw = xdr.NewWriter(&aw)
  317. o.encodeXDR(xw)
  318. return []byte(aw)
  319. }
  320. func (o ResponseMessage) encodeXDR(xw *xdr.Writer) (int, error) {
  321. xw.WriteBytes(o.Data)
  322. return xw.Tot(), xw.Error()
  323. }
  324. func (o *ResponseMessage) DecodeXDR(r io.Reader) error {
  325. xr := xdr.NewReader(r)
  326. return o.decodeXDR(xr)
  327. }
  328. func (o *ResponseMessage) UnmarshalXDR(bs []byte) error {
  329. var br = bytes.NewReader(bs)
  330. var xr = xdr.NewReader(br)
  331. return o.decodeXDR(xr)
  332. }
  333. func (o *ResponseMessage) decodeXDR(xr *xdr.Reader) error {
  334. o.Data = xr.ReadBytes()
  335. return xr.Error()
  336. }
  337. /*
  338. ClusterConfigMessage Structure:
  339. 0 1 2 3
  340. 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
  341. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  342. | Length of Client Name |
  343. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  344. / /
  345. \ Client Name (variable length) \
  346. / /
  347. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  348. | Length of Client Version |
  349. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  350. / /
  351. \ Client Version (variable length) \
  352. / /
  353. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  354. | Number of Repositories |
  355. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  356. / /
  357. \ Zero or more Repository Structures \
  358. / /
  359. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  360. | Number of Options |
  361. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  362. / /
  363. \ Zero or more Option Structures \
  364. / /
  365. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  366. struct ClusterConfigMessage {
  367. string ClientName<64>;
  368. string ClientVersion<64>;
  369. Repository Repositories<64>;
  370. Option Options<64>;
  371. }
  372. */
  373. func (o ClusterConfigMessage) EncodeXDR(w io.Writer) (int, error) {
  374. var xw = xdr.NewWriter(w)
  375. return o.encodeXDR(xw)
  376. }
  377. func (o ClusterConfigMessage) MarshalXDR() []byte {
  378. return o.AppendXDR(make([]byte, 0, 128))
  379. }
  380. func (o ClusterConfigMessage) AppendXDR(bs []byte) []byte {
  381. var aw = xdr.AppendWriter(bs)
  382. var xw = xdr.NewWriter(&aw)
  383. o.encodeXDR(xw)
  384. return []byte(aw)
  385. }
  386. func (o ClusterConfigMessage) encodeXDR(xw *xdr.Writer) (int, error) {
  387. if len(o.ClientName) > 64 {
  388. return xw.Tot(), xdr.ErrElementSizeExceeded
  389. }
  390. xw.WriteString(o.ClientName)
  391. if len(o.ClientVersion) > 64 {
  392. return xw.Tot(), xdr.ErrElementSizeExceeded
  393. }
  394. xw.WriteString(o.ClientVersion)
  395. if len(o.Repositories) > 64 {
  396. return xw.Tot(), xdr.ErrElementSizeExceeded
  397. }
  398. xw.WriteUint32(uint32(len(o.Repositories)))
  399. for i := range o.Repositories {
  400. o.Repositories[i].encodeXDR(xw)
  401. }
  402. if len(o.Options) > 64 {
  403. return xw.Tot(), xdr.ErrElementSizeExceeded
  404. }
  405. xw.WriteUint32(uint32(len(o.Options)))
  406. for i := range o.Options {
  407. o.Options[i].encodeXDR(xw)
  408. }
  409. return xw.Tot(), xw.Error()
  410. }
  411. func (o *ClusterConfigMessage) DecodeXDR(r io.Reader) error {
  412. xr := xdr.NewReader(r)
  413. return o.decodeXDR(xr)
  414. }
  415. func (o *ClusterConfigMessage) UnmarshalXDR(bs []byte) error {
  416. var br = bytes.NewReader(bs)
  417. var xr = xdr.NewReader(br)
  418. return o.decodeXDR(xr)
  419. }
  420. func (o *ClusterConfigMessage) decodeXDR(xr *xdr.Reader) error {
  421. o.ClientName = xr.ReadStringMax(64)
  422. o.ClientVersion = xr.ReadStringMax(64)
  423. _RepositoriesSize := int(xr.ReadUint32())
  424. if _RepositoriesSize > 64 {
  425. return xdr.ErrElementSizeExceeded
  426. }
  427. o.Repositories = make([]Repository, _RepositoriesSize)
  428. for i := range o.Repositories {
  429. (&o.Repositories[i]).decodeXDR(xr)
  430. }
  431. _OptionsSize := int(xr.ReadUint32())
  432. if _OptionsSize > 64 {
  433. return xdr.ErrElementSizeExceeded
  434. }
  435. o.Options = make([]Option, _OptionsSize)
  436. for i := range o.Options {
  437. (&o.Options[i]).decodeXDR(xr)
  438. }
  439. return xr.Error()
  440. }
  441. /*
  442. Repository Structure:
  443. 0 1 2 3
  444. 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
  445. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  446. | Length of ID |
  447. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  448. / /
  449. \ ID (variable length) \
  450. / /
  451. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  452. | Number of Nodes |
  453. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  454. / /
  455. \ Zero or more Node Structures \
  456. / /
  457. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  458. struct Repository {
  459. string ID<64>;
  460. Node Nodes<64>;
  461. }
  462. */
  463. func (o Repository) EncodeXDR(w io.Writer) (int, error) {
  464. var xw = xdr.NewWriter(w)
  465. return o.encodeXDR(xw)
  466. }
  467. func (o Repository) MarshalXDR() []byte {
  468. return o.AppendXDR(make([]byte, 0, 128))
  469. }
  470. func (o Repository) AppendXDR(bs []byte) []byte {
  471. var aw = xdr.AppendWriter(bs)
  472. var xw = xdr.NewWriter(&aw)
  473. o.encodeXDR(xw)
  474. return []byte(aw)
  475. }
  476. func (o Repository) encodeXDR(xw *xdr.Writer) (int, error) {
  477. if len(o.ID) > 64 {
  478. return xw.Tot(), xdr.ErrElementSizeExceeded
  479. }
  480. xw.WriteString(o.ID)
  481. if len(o.Nodes) > 64 {
  482. return xw.Tot(), xdr.ErrElementSizeExceeded
  483. }
  484. xw.WriteUint32(uint32(len(o.Nodes)))
  485. for i := range o.Nodes {
  486. o.Nodes[i].encodeXDR(xw)
  487. }
  488. return xw.Tot(), xw.Error()
  489. }
  490. func (o *Repository) DecodeXDR(r io.Reader) error {
  491. xr := xdr.NewReader(r)
  492. return o.decodeXDR(xr)
  493. }
  494. func (o *Repository) UnmarshalXDR(bs []byte) error {
  495. var br = bytes.NewReader(bs)
  496. var xr = xdr.NewReader(br)
  497. return o.decodeXDR(xr)
  498. }
  499. func (o *Repository) decodeXDR(xr *xdr.Reader) error {
  500. o.ID = xr.ReadStringMax(64)
  501. _NodesSize := int(xr.ReadUint32())
  502. if _NodesSize > 64 {
  503. return xdr.ErrElementSizeExceeded
  504. }
  505. o.Nodes = make([]Node, _NodesSize)
  506. for i := range o.Nodes {
  507. (&o.Nodes[i]).decodeXDR(xr)
  508. }
  509. return xr.Error()
  510. }
  511. /*
  512. Node Structure:
  513. 0 1 2 3
  514. 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
  515. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  516. | Length of ID |
  517. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  518. / /
  519. \ ID (variable length) \
  520. / /
  521. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  522. | Flags |
  523. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  524. | |
  525. + Max Local Version (64 bits) +
  526. | |
  527. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  528. struct Node {
  529. opaque ID<32>;
  530. unsigned int Flags;
  531. unsigned hyper MaxLocalVersion;
  532. }
  533. */
  534. func (o Node) EncodeXDR(w io.Writer) (int, error) {
  535. var xw = xdr.NewWriter(w)
  536. return o.encodeXDR(xw)
  537. }
  538. func (o Node) MarshalXDR() []byte {
  539. return o.AppendXDR(make([]byte, 0, 128))
  540. }
  541. func (o Node) AppendXDR(bs []byte) []byte {
  542. var aw = xdr.AppendWriter(bs)
  543. var xw = xdr.NewWriter(&aw)
  544. o.encodeXDR(xw)
  545. return []byte(aw)
  546. }
  547. func (o Node) encodeXDR(xw *xdr.Writer) (int, error) {
  548. if len(o.ID) > 32 {
  549. return xw.Tot(), xdr.ErrElementSizeExceeded
  550. }
  551. xw.WriteBytes(o.ID)
  552. xw.WriteUint32(o.Flags)
  553. xw.WriteUint64(o.MaxLocalVersion)
  554. return xw.Tot(), xw.Error()
  555. }
  556. func (o *Node) DecodeXDR(r io.Reader) error {
  557. xr := xdr.NewReader(r)
  558. return o.decodeXDR(xr)
  559. }
  560. func (o *Node) UnmarshalXDR(bs []byte) error {
  561. var br = bytes.NewReader(bs)
  562. var xr = xdr.NewReader(br)
  563. return o.decodeXDR(xr)
  564. }
  565. func (o *Node) decodeXDR(xr *xdr.Reader) error {
  566. o.ID = xr.ReadBytesMax(32)
  567. o.Flags = xr.ReadUint32()
  568. o.MaxLocalVersion = xr.ReadUint64()
  569. return xr.Error()
  570. }
  571. /*
  572. Option Structure:
  573. 0 1 2 3
  574. 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
  575. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  576. | Length of Key |
  577. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  578. / /
  579. \ Key (variable length) \
  580. / /
  581. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  582. | Length of Value |
  583. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  584. / /
  585. \ Value (variable length) \
  586. / /
  587. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  588. struct Option {
  589. string Key<64>;
  590. string Value<1024>;
  591. }
  592. */
  593. func (o Option) EncodeXDR(w io.Writer) (int, error) {
  594. var xw = xdr.NewWriter(w)
  595. return o.encodeXDR(xw)
  596. }
  597. func (o Option) MarshalXDR() []byte {
  598. return o.AppendXDR(make([]byte, 0, 128))
  599. }
  600. func (o Option) AppendXDR(bs []byte) []byte {
  601. var aw = xdr.AppendWriter(bs)
  602. var xw = xdr.NewWriter(&aw)
  603. o.encodeXDR(xw)
  604. return []byte(aw)
  605. }
  606. func (o Option) encodeXDR(xw *xdr.Writer) (int, error) {
  607. if len(o.Key) > 64 {
  608. return xw.Tot(), xdr.ErrElementSizeExceeded
  609. }
  610. xw.WriteString(o.Key)
  611. if len(o.Value) > 1024 {
  612. return xw.Tot(), xdr.ErrElementSizeExceeded
  613. }
  614. xw.WriteString(o.Value)
  615. return xw.Tot(), xw.Error()
  616. }
  617. func (o *Option) DecodeXDR(r io.Reader) error {
  618. xr := xdr.NewReader(r)
  619. return o.decodeXDR(xr)
  620. }
  621. func (o *Option) UnmarshalXDR(bs []byte) error {
  622. var br = bytes.NewReader(bs)
  623. var xr = xdr.NewReader(br)
  624. return o.decodeXDR(xr)
  625. }
  626. func (o *Option) decodeXDR(xr *xdr.Reader) error {
  627. o.Key = xr.ReadStringMax(64)
  628. o.Value = xr.ReadStringMax(1024)
  629. return xr.Error()
  630. }
  631. /*
  632. CloseMessage Structure:
  633. 0 1 2 3
  634. 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
  635. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  636. | Length of Reason |
  637. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  638. / /
  639. \ Reason (variable length) \
  640. / /
  641. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  642. struct CloseMessage {
  643. string Reason<1024>;
  644. }
  645. */
  646. func (o CloseMessage) EncodeXDR(w io.Writer) (int, error) {
  647. var xw = xdr.NewWriter(w)
  648. return o.encodeXDR(xw)
  649. }
  650. func (o CloseMessage) MarshalXDR() []byte {
  651. return o.AppendXDR(make([]byte, 0, 128))
  652. }
  653. func (o CloseMessage) AppendXDR(bs []byte) []byte {
  654. var aw = xdr.AppendWriter(bs)
  655. var xw = xdr.NewWriter(&aw)
  656. o.encodeXDR(xw)
  657. return []byte(aw)
  658. }
  659. func (o CloseMessage) encodeXDR(xw *xdr.Writer) (int, error) {
  660. if len(o.Reason) > 1024 {
  661. return xw.Tot(), xdr.ErrElementSizeExceeded
  662. }
  663. xw.WriteString(o.Reason)
  664. return xw.Tot(), xw.Error()
  665. }
  666. func (o *CloseMessage) DecodeXDR(r io.Reader) error {
  667. xr := xdr.NewReader(r)
  668. return o.decodeXDR(xr)
  669. }
  670. func (o *CloseMessage) UnmarshalXDR(bs []byte) error {
  671. var br = bytes.NewReader(bs)
  672. var xr = xdr.NewReader(br)
  673. return o.decodeXDR(xr)
  674. }
  675. func (o *CloseMessage) decodeXDR(xr *xdr.Reader) error {
  676. o.Reason = xr.ReadStringMax(1024)
  677. return xr.Error()
  678. }
  679. /*
  680. EmptyMessage Structure:
  681. 0 1 2 3
  682. 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
  683. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  684. struct EmptyMessage {
  685. }
  686. */
  687. func (o EmptyMessage) EncodeXDR(w io.Writer) (int, error) {
  688. var xw = xdr.NewWriter(w)
  689. return o.encodeXDR(xw)
  690. }
  691. func (o EmptyMessage) MarshalXDR() []byte {
  692. return o.AppendXDR(make([]byte, 0, 128))
  693. }
  694. func (o EmptyMessage) AppendXDR(bs []byte) []byte {
  695. var aw = xdr.AppendWriter(bs)
  696. var xw = xdr.NewWriter(&aw)
  697. o.encodeXDR(xw)
  698. return []byte(aw)
  699. }
  700. func (o EmptyMessage) encodeXDR(xw *xdr.Writer) (int, error) {
  701. return xw.Tot(), xw.Error()
  702. }
  703. func (o *EmptyMessage) DecodeXDR(r io.Reader) error {
  704. xr := xdr.NewReader(r)
  705. return o.decodeXDR(xr)
  706. }
  707. func (o *EmptyMessage) UnmarshalXDR(bs []byte) error {
  708. var br = bytes.NewReader(bs)
  709. var xr = xdr.NewReader(br)
  710. return o.decodeXDR(xr)
  711. }
  712. func (o *EmptyMessage) decodeXDR(xr *xdr.Reader) error {
  713. return xr.Error()
  714. }