raft.pb.go 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546
  1. // Code generated by protoc-gen-gogo.
  2. // source: raft.proto
  3. // DO NOT EDIT!
  4. /*
  5. Package raftpb is a generated protocol buffer package.
  6. It is generated from these files:
  7. raft.proto
  8. It has these top-level messages:
  9. Entry
  10. SnapshotMetadata
  11. Snapshot
  12. Message
  13. HardState
  14. ConfState
  15. ConfChange
  16. */
  17. package raftpb
  18. import proto "github.com/coreos/etcd/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
  19. import math "math"
  20. // discarding unused import gogoproto "github.com/gogo/protobuf/gogoproto/gogo.pb"
  21. import io "io"
  22. import fmt "fmt"
  23. // Reference imports to suppress errors if they are not otherwise used.
  24. var _ = proto.Marshal
  25. var _ = math.Inf
  26. type EntryType int32
  27. const (
  28. EntryNormal EntryType = 0
  29. EntryConfChange EntryType = 1
  30. )
  31. var EntryType_name = map[int32]string{
  32. 0: "EntryNormal",
  33. 1: "EntryConfChange",
  34. }
  35. var EntryType_value = map[string]int32{
  36. "EntryNormal": 0,
  37. "EntryConfChange": 1,
  38. }
  39. func (x EntryType) Enum() *EntryType {
  40. p := new(EntryType)
  41. *p = x
  42. return p
  43. }
  44. func (x EntryType) String() string {
  45. return proto.EnumName(EntryType_name, int32(x))
  46. }
  47. func (x *EntryType) UnmarshalJSON(data []byte) error {
  48. value, err := proto.UnmarshalJSONEnum(EntryType_value, data, "EntryType")
  49. if err != nil {
  50. return err
  51. }
  52. *x = EntryType(value)
  53. return nil
  54. }
  55. type MessageType int32
  56. const (
  57. MsgHup MessageType = 0
  58. MsgBeat MessageType = 1
  59. MsgProp MessageType = 2
  60. MsgApp MessageType = 3
  61. MsgAppResp MessageType = 4
  62. MsgVote MessageType = 5
  63. MsgVoteResp MessageType = 6
  64. MsgSnap MessageType = 7
  65. MsgHeartbeat MessageType = 8
  66. MsgHeartbeatResp MessageType = 9
  67. MsgUnreachable MessageType = 10
  68. MsgSnapStatus MessageType = 11
  69. )
  70. var MessageType_name = map[int32]string{
  71. 0: "MsgHup",
  72. 1: "MsgBeat",
  73. 2: "MsgProp",
  74. 3: "MsgApp",
  75. 4: "MsgAppResp",
  76. 5: "MsgVote",
  77. 6: "MsgVoteResp",
  78. 7: "MsgSnap",
  79. 8: "MsgHeartbeat",
  80. 9: "MsgHeartbeatResp",
  81. 10: "MsgUnreachable",
  82. 11: "MsgSnapStatus",
  83. }
  84. var MessageType_value = map[string]int32{
  85. "MsgHup": 0,
  86. "MsgBeat": 1,
  87. "MsgProp": 2,
  88. "MsgApp": 3,
  89. "MsgAppResp": 4,
  90. "MsgVote": 5,
  91. "MsgVoteResp": 6,
  92. "MsgSnap": 7,
  93. "MsgHeartbeat": 8,
  94. "MsgHeartbeatResp": 9,
  95. "MsgUnreachable": 10,
  96. "MsgSnapStatus": 11,
  97. }
  98. func (x MessageType) Enum() *MessageType {
  99. p := new(MessageType)
  100. *p = x
  101. return p
  102. }
  103. func (x MessageType) String() string {
  104. return proto.EnumName(MessageType_name, int32(x))
  105. }
  106. func (x *MessageType) UnmarshalJSON(data []byte) error {
  107. value, err := proto.UnmarshalJSONEnum(MessageType_value, data, "MessageType")
  108. if err != nil {
  109. return err
  110. }
  111. *x = MessageType(value)
  112. return nil
  113. }
  114. type ConfChangeType int32
  115. const (
  116. ConfChangeAddNode ConfChangeType = 0
  117. ConfChangeRemoveNode ConfChangeType = 1
  118. ConfChangeUpdateNode ConfChangeType = 2
  119. )
  120. var ConfChangeType_name = map[int32]string{
  121. 0: "ConfChangeAddNode",
  122. 1: "ConfChangeRemoveNode",
  123. 2: "ConfChangeUpdateNode",
  124. }
  125. var ConfChangeType_value = map[string]int32{
  126. "ConfChangeAddNode": 0,
  127. "ConfChangeRemoveNode": 1,
  128. "ConfChangeUpdateNode": 2,
  129. }
  130. func (x ConfChangeType) Enum() *ConfChangeType {
  131. p := new(ConfChangeType)
  132. *p = x
  133. return p
  134. }
  135. func (x ConfChangeType) String() string {
  136. return proto.EnumName(ConfChangeType_name, int32(x))
  137. }
  138. func (x *ConfChangeType) UnmarshalJSON(data []byte) error {
  139. value, err := proto.UnmarshalJSONEnum(ConfChangeType_value, data, "ConfChangeType")
  140. if err != nil {
  141. return err
  142. }
  143. *x = ConfChangeType(value)
  144. return nil
  145. }
  146. type Entry struct {
  147. Type EntryType `protobuf:"varint,1,opt,enum=raftpb.EntryType" json:"Type"`
  148. Term uint64 `protobuf:"varint,2,opt" json:"Term"`
  149. Index uint64 `protobuf:"varint,3,opt" json:"Index"`
  150. Data []byte `protobuf:"bytes,4,opt" json:"Data,omitempty"`
  151. XXX_unrecognized []byte `json:"-"`
  152. }
  153. func (m *Entry) Reset() { *m = Entry{} }
  154. func (m *Entry) String() string { return proto.CompactTextString(m) }
  155. func (*Entry) ProtoMessage() {}
  156. type SnapshotMetadata struct {
  157. ConfState ConfState `protobuf:"bytes,1,opt,name=conf_state" json:"conf_state"`
  158. Index uint64 `protobuf:"varint,2,opt,name=index" json:"index"`
  159. Term uint64 `protobuf:"varint,3,opt,name=term" json:"term"`
  160. XXX_unrecognized []byte `json:"-"`
  161. }
  162. func (m *SnapshotMetadata) Reset() { *m = SnapshotMetadata{} }
  163. func (m *SnapshotMetadata) String() string { return proto.CompactTextString(m) }
  164. func (*SnapshotMetadata) ProtoMessage() {}
  165. type Snapshot struct {
  166. Data []byte `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"`
  167. Metadata SnapshotMetadata `protobuf:"bytes,2,opt,name=metadata" json:"metadata"`
  168. XXX_unrecognized []byte `json:"-"`
  169. }
  170. func (m *Snapshot) Reset() { *m = Snapshot{} }
  171. func (m *Snapshot) String() string { return proto.CompactTextString(m) }
  172. func (*Snapshot) ProtoMessage() {}
  173. type Message struct {
  174. Type MessageType `protobuf:"varint,1,opt,name=type,enum=raftpb.MessageType" json:"type"`
  175. To uint64 `protobuf:"varint,2,opt,name=to" json:"to"`
  176. From uint64 `protobuf:"varint,3,opt,name=from" json:"from"`
  177. Term uint64 `protobuf:"varint,4,opt,name=term" json:"term"`
  178. LogTerm uint64 `protobuf:"varint,5,opt,name=logTerm" json:"logTerm"`
  179. Index uint64 `protobuf:"varint,6,opt,name=index" json:"index"`
  180. Entries []Entry `protobuf:"bytes,7,rep,name=entries" json:"entries"`
  181. Commit uint64 `protobuf:"varint,8,opt,name=commit" json:"commit"`
  182. Snapshot Snapshot `protobuf:"bytes,9,opt,name=snapshot" json:"snapshot"`
  183. Reject bool `protobuf:"varint,10,opt,name=reject" json:"reject"`
  184. RejectHint uint64 `protobuf:"varint,11,opt,name=rejectHint" json:"rejectHint"`
  185. XXX_unrecognized []byte `json:"-"`
  186. }
  187. func (m *Message) Reset() { *m = Message{} }
  188. func (m *Message) String() string { return proto.CompactTextString(m) }
  189. func (*Message) ProtoMessage() {}
  190. type HardState struct {
  191. Term uint64 `protobuf:"varint,1,opt,name=term" json:"term"`
  192. Vote uint64 `protobuf:"varint,2,opt,name=vote" json:"vote"`
  193. Commit uint64 `protobuf:"varint,3,opt,name=commit" json:"commit"`
  194. XXX_unrecognized []byte `json:"-"`
  195. }
  196. func (m *HardState) Reset() { *m = HardState{} }
  197. func (m *HardState) String() string { return proto.CompactTextString(m) }
  198. func (*HardState) ProtoMessage() {}
  199. type ConfState struct {
  200. Nodes []uint64 `protobuf:"varint,1,rep,name=nodes" json:"nodes,omitempty"`
  201. XXX_unrecognized []byte `json:"-"`
  202. }
  203. func (m *ConfState) Reset() { *m = ConfState{} }
  204. func (m *ConfState) String() string { return proto.CompactTextString(m) }
  205. func (*ConfState) ProtoMessage() {}
  206. type ConfChange struct {
  207. ID uint64 `protobuf:"varint,1,opt" json:"ID"`
  208. Type ConfChangeType `protobuf:"varint,2,opt,enum=raftpb.ConfChangeType" json:"Type"`
  209. NodeID uint64 `protobuf:"varint,3,opt" json:"NodeID"`
  210. Context []byte `protobuf:"bytes,4,opt" json:"Context,omitempty"`
  211. XXX_unrecognized []byte `json:"-"`
  212. }
  213. func (m *ConfChange) Reset() { *m = ConfChange{} }
  214. func (m *ConfChange) String() string { return proto.CompactTextString(m) }
  215. func (*ConfChange) ProtoMessage() {}
  216. func init() {
  217. proto.RegisterEnum("raftpb.EntryType", EntryType_name, EntryType_value)
  218. proto.RegisterEnum("raftpb.MessageType", MessageType_name, MessageType_value)
  219. proto.RegisterEnum("raftpb.ConfChangeType", ConfChangeType_name, ConfChangeType_value)
  220. }
  221. func (m *Entry) Unmarshal(data []byte) error {
  222. l := len(data)
  223. iNdEx := 0
  224. for iNdEx < l {
  225. var wire uint64
  226. for shift := uint(0); ; shift += 7 {
  227. if iNdEx >= l {
  228. return io.ErrUnexpectedEOF
  229. }
  230. b := data[iNdEx]
  231. iNdEx++
  232. wire |= (uint64(b) & 0x7F) << shift
  233. if b < 0x80 {
  234. break
  235. }
  236. }
  237. fieldNum := int32(wire >> 3)
  238. wireType := int(wire & 0x7)
  239. switch fieldNum {
  240. case 1:
  241. if wireType != 0 {
  242. return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType)
  243. }
  244. for shift := uint(0); ; shift += 7 {
  245. if iNdEx >= l {
  246. return io.ErrUnexpectedEOF
  247. }
  248. b := data[iNdEx]
  249. iNdEx++
  250. m.Type |= (EntryType(b) & 0x7F) << shift
  251. if b < 0x80 {
  252. break
  253. }
  254. }
  255. case 2:
  256. if wireType != 0 {
  257. return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType)
  258. }
  259. for shift := uint(0); ; shift += 7 {
  260. if iNdEx >= l {
  261. return io.ErrUnexpectedEOF
  262. }
  263. b := data[iNdEx]
  264. iNdEx++
  265. m.Term |= (uint64(b) & 0x7F) << shift
  266. if b < 0x80 {
  267. break
  268. }
  269. }
  270. case 3:
  271. if wireType != 0 {
  272. return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType)
  273. }
  274. for shift := uint(0); ; shift += 7 {
  275. if iNdEx >= l {
  276. return io.ErrUnexpectedEOF
  277. }
  278. b := data[iNdEx]
  279. iNdEx++
  280. m.Index |= (uint64(b) & 0x7F) << shift
  281. if b < 0x80 {
  282. break
  283. }
  284. }
  285. case 4:
  286. if wireType != 2 {
  287. return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType)
  288. }
  289. var byteLen int
  290. for shift := uint(0); ; shift += 7 {
  291. if iNdEx >= l {
  292. return io.ErrUnexpectedEOF
  293. }
  294. b := data[iNdEx]
  295. iNdEx++
  296. byteLen |= (int(b) & 0x7F) << shift
  297. if b < 0x80 {
  298. break
  299. }
  300. }
  301. postIndex := iNdEx + byteLen
  302. if postIndex > l {
  303. return io.ErrUnexpectedEOF
  304. }
  305. m.Data = append([]byte{}, data[iNdEx:postIndex]...)
  306. iNdEx = postIndex
  307. default:
  308. var sizeOfWire int
  309. for {
  310. sizeOfWire++
  311. wire >>= 7
  312. if wire == 0 {
  313. break
  314. }
  315. }
  316. iNdEx -= sizeOfWire
  317. skippy, err := skipRaft(data[iNdEx:])
  318. if err != nil {
  319. return err
  320. }
  321. if (iNdEx + skippy) > l {
  322. return io.ErrUnexpectedEOF
  323. }
  324. m.XXX_unrecognized = append(m.XXX_unrecognized, data[iNdEx:iNdEx+skippy]...)
  325. iNdEx += skippy
  326. }
  327. }
  328. return nil
  329. }
  330. func (m *SnapshotMetadata) Unmarshal(data []byte) error {
  331. l := len(data)
  332. iNdEx := 0
  333. for iNdEx < l {
  334. var wire uint64
  335. for shift := uint(0); ; shift += 7 {
  336. if iNdEx >= l {
  337. return io.ErrUnexpectedEOF
  338. }
  339. b := data[iNdEx]
  340. iNdEx++
  341. wire |= (uint64(b) & 0x7F) << shift
  342. if b < 0x80 {
  343. break
  344. }
  345. }
  346. fieldNum := int32(wire >> 3)
  347. wireType := int(wire & 0x7)
  348. switch fieldNum {
  349. case 1:
  350. if wireType != 2 {
  351. return fmt.Errorf("proto: wrong wireType = %d for field ConfState", wireType)
  352. }
  353. var msglen int
  354. for shift := uint(0); ; shift += 7 {
  355. if iNdEx >= l {
  356. return io.ErrUnexpectedEOF
  357. }
  358. b := data[iNdEx]
  359. iNdEx++
  360. msglen |= (int(b) & 0x7F) << shift
  361. if b < 0x80 {
  362. break
  363. }
  364. }
  365. postIndex := iNdEx + msglen
  366. if postIndex > l {
  367. return io.ErrUnexpectedEOF
  368. }
  369. if err := m.ConfState.Unmarshal(data[iNdEx:postIndex]); err != nil {
  370. return err
  371. }
  372. iNdEx = postIndex
  373. case 2:
  374. if wireType != 0 {
  375. return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType)
  376. }
  377. for shift := uint(0); ; shift += 7 {
  378. if iNdEx >= l {
  379. return io.ErrUnexpectedEOF
  380. }
  381. b := data[iNdEx]
  382. iNdEx++
  383. m.Index |= (uint64(b) & 0x7F) << shift
  384. if b < 0x80 {
  385. break
  386. }
  387. }
  388. case 3:
  389. if wireType != 0 {
  390. return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType)
  391. }
  392. for shift := uint(0); ; shift += 7 {
  393. if iNdEx >= l {
  394. return io.ErrUnexpectedEOF
  395. }
  396. b := data[iNdEx]
  397. iNdEx++
  398. m.Term |= (uint64(b) & 0x7F) << shift
  399. if b < 0x80 {
  400. break
  401. }
  402. }
  403. default:
  404. var sizeOfWire int
  405. for {
  406. sizeOfWire++
  407. wire >>= 7
  408. if wire == 0 {
  409. break
  410. }
  411. }
  412. iNdEx -= sizeOfWire
  413. skippy, err := skipRaft(data[iNdEx:])
  414. if err != nil {
  415. return err
  416. }
  417. if (iNdEx + skippy) > l {
  418. return io.ErrUnexpectedEOF
  419. }
  420. m.XXX_unrecognized = append(m.XXX_unrecognized, data[iNdEx:iNdEx+skippy]...)
  421. iNdEx += skippy
  422. }
  423. }
  424. return nil
  425. }
  426. func (m *Snapshot) Unmarshal(data []byte) error {
  427. l := len(data)
  428. iNdEx := 0
  429. for iNdEx < l {
  430. var wire uint64
  431. for shift := uint(0); ; shift += 7 {
  432. if iNdEx >= l {
  433. return io.ErrUnexpectedEOF
  434. }
  435. b := data[iNdEx]
  436. iNdEx++
  437. wire |= (uint64(b) & 0x7F) << shift
  438. if b < 0x80 {
  439. break
  440. }
  441. }
  442. fieldNum := int32(wire >> 3)
  443. wireType := int(wire & 0x7)
  444. switch fieldNum {
  445. case 1:
  446. if wireType != 2 {
  447. return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType)
  448. }
  449. var byteLen int
  450. for shift := uint(0); ; shift += 7 {
  451. if iNdEx >= l {
  452. return io.ErrUnexpectedEOF
  453. }
  454. b := data[iNdEx]
  455. iNdEx++
  456. byteLen |= (int(b) & 0x7F) << shift
  457. if b < 0x80 {
  458. break
  459. }
  460. }
  461. postIndex := iNdEx + byteLen
  462. if postIndex > l {
  463. return io.ErrUnexpectedEOF
  464. }
  465. m.Data = append([]byte{}, data[iNdEx:postIndex]...)
  466. iNdEx = postIndex
  467. case 2:
  468. if wireType != 2 {
  469. return fmt.Errorf("proto: wrong wireType = %d for field Metadata", wireType)
  470. }
  471. var msglen int
  472. for shift := uint(0); ; shift += 7 {
  473. if iNdEx >= l {
  474. return io.ErrUnexpectedEOF
  475. }
  476. b := data[iNdEx]
  477. iNdEx++
  478. msglen |= (int(b) & 0x7F) << shift
  479. if b < 0x80 {
  480. break
  481. }
  482. }
  483. postIndex := iNdEx + msglen
  484. if postIndex > l {
  485. return io.ErrUnexpectedEOF
  486. }
  487. if err := m.Metadata.Unmarshal(data[iNdEx:postIndex]); err != nil {
  488. return err
  489. }
  490. iNdEx = postIndex
  491. default:
  492. var sizeOfWire int
  493. for {
  494. sizeOfWire++
  495. wire >>= 7
  496. if wire == 0 {
  497. break
  498. }
  499. }
  500. iNdEx -= sizeOfWire
  501. skippy, err := skipRaft(data[iNdEx:])
  502. if err != nil {
  503. return err
  504. }
  505. if (iNdEx + skippy) > l {
  506. return io.ErrUnexpectedEOF
  507. }
  508. m.XXX_unrecognized = append(m.XXX_unrecognized, data[iNdEx:iNdEx+skippy]...)
  509. iNdEx += skippy
  510. }
  511. }
  512. return nil
  513. }
  514. func (m *Message) Unmarshal(data []byte) error {
  515. l := len(data)
  516. iNdEx := 0
  517. for iNdEx < l {
  518. var wire uint64
  519. for shift := uint(0); ; shift += 7 {
  520. if iNdEx >= l {
  521. return io.ErrUnexpectedEOF
  522. }
  523. b := data[iNdEx]
  524. iNdEx++
  525. wire |= (uint64(b) & 0x7F) << shift
  526. if b < 0x80 {
  527. break
  528. }
  529. }
  530. fieldNum := int32(wire >> 3)
  531. wireType := int(wire & 0x7)
  532. switch fieldNum {
  533. case 1:
  534. if wireType != 0 {
  535. return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType)
  536. }
  537. for shift := uint(0); ; shift += 7 {
  538. if iNdEx >= l {
  539. return io.ErrUnexpectedEOF
  540. }
  541. b := data[iNdEx]
  542. iNdEx++
  543. m.Type |= (MessageType(b) & 0x7F) << shift
  544. if b < 0x80 {
  545. break
  546. }
  547. }
  548. case 2:
  549. if wireType != 0 {
  550. return fmt.Errorf("proto: wrong wireType = %d for field To", wireType)
  551. }
  552. for shift := uint(0); ; shift += 7 {
  553. if iNdEx >= l {
  554. return io.ErrUnexpectedEOF
  555. }
  556. b := data[iNdEx]
  557. iNdEx++
  558. m.To |= (uint64(b) & 0x7F) << shift
  559. if b < 0x80 {
  560. break
  561. }
  562. }
  563. case 3:
  564. if wireType != 0 {
  565. return fmt.Errorf("proto: wrong wireType = %d for field From", wireType)
  566. }
  567. for shift := uint(0); ; shift += 7 {
  568. if iNdEx >= l {
  569. return io.ErrUnexpectedEOF
  570. }
  571. b := data[iNdEx]
  572. iNdEx++
  573. m.From |= (uint64(b) & 0x7F) << shift
  574. if b < 0x80 {
  575. break
  576. }
  577. }
  578. case 4:
  579. if wireType != 0 {
  580. return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType)
  581. }
  582. for shift := uint(0); ; shift += 7 {
  583. if iNdEx >= l {
  584. return io.ErrUnexpectedEOF
  585. }
  586. b := data[iNdEx]
  587. iNdEx++
  588. m.Term |= (uint64(b) & 0x7F) << shift
  589. if b < 0x80 {
  590. break
  591. }
  592. }
  593. case 5:
  594. if wireType != 0 {
  595. return fmt.Errorf("proto: wrong wireType = %d for field LogTerm", wireType)
  596. }
  597. for shift := uint(0); ; shift += 7 {
  598. if iNdEx >= l {
  599. return io.ErrUnexpectedEOF
  600. }
  601. b := data[iNdEx]
  602. iNdEx++
  603. m.LogTerm |= (uint64(b) & 0x7F) << shift
  604. if b < 0x80 {
  605. break
  606. }
  607. }
  608. case 6:
  609. if wireType != 0 {
  610. return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType)
  611. }
  612. for shift := uint(0); ; shift += 7 {
  613. if iNdEx >= l {
  614. return io.ErrUnexpectedEOF
  615. }
  616. b := data[iNdEx]
  617. iNdEx++
  618. m.Index |= (uint64(b) & 0x7F) << shift
  619. if b < 0x80 {
  620. break
  621. }
  622. }
  623. case 7:
  624. if wireType != 2 {
  625. return fmt.Errorf("proto: wrong wireType = %d for field Entries", wireType)
  626. }
  627. var msglen int
  628. for shift := uint(0); ; shift += 7 {
  629. if iNdEx >= l {
  630. return io.ErrUnexpectedEOF
  631. }
  632. b := data[iNdEx]
  633. iNdEx++
  634. msglen |= (int(b) & 0x7F) << shift
  635. if b < 0x80 {
  636. break
  637. }
  638. }
  639. postIndex := iNdEx + msglen
  640. if postIndex > l {
  641. return io.ErrUnexpectedEOF
  642. }
  643. m.Entries = append(m.Entries, Entry{})
  644. if err := m.Entries[len(m.Entries)-1].Unmarshal(data[iNdEx:postIndex]); err != nil {
  645. return err
  646. }
  647. iNdEx = postIndex
  648. case 8:
  649. if wireType != 0 {
  650. return fmt.Errorf("proto: wrong wireType = %d for field Commit", wireType)
  651. }
  652. for shift := uint(0); ; shift += 7 {
  653. if iNdEx >= l {
  654. return io.ErrUnexpectedEOF
  655. }
  656. b := data[iNdEx]
  657. iNdEx++
  658. m.Commit |= (uint64(b) & 0x7F) << shift
  659. if b < 0x80 {
  660. break
  661. }
  662. }
  663. case 9:
  664. if wireType != 2 {
  665. return fmt.Errorf("proto: wrong wireType = %d for field Snapshot", wireType)
  666. }
  667. var msglen int
  668. for shift := uint(0); ; shift += 7 {
  669. if iNdEx >= l {
  670. return io.ErrUnexpectedEOF
  671. }
  672. b := data[iNdEx]
  673. iNdEx++
  674. msglen |= (int(b) & 0x7F) << shift
  675. if b < 0x80 {
  676. break
  677. }
  678. }
  679. postIndex := iNdEx + msglen
  680. if postIndex > l {
  681. return io.ErrUnexpectedEOF
  682. }
  683. if err := m.Snapshot.Unmarshal(data[iNdEx:postIndex]); err != nil {
  684. return err
  685. }
  686. iNdEx = postIndex
  687. case 10:
  688. if wireType != 0 {
  689. return fmt.Errorf("proto: wrong wireType = %d for field Reject", wireType)
  690. }
  691. var v int
  692. for shift := uint(0); ; shift += 7 {
  693. if iNdEx >= l {
  694. return io.ErrUnexpectedEOF
  695. }
  696. b := data[iNdEx]
  697. iNdEx++
  698. v |= (int(b) & 0x7F) << shift
  699. if b < 0x80 {
  700. break
  701. }
  702. }
  703. m.Reject = bool(v != 0)
  704. case 11:
  705. if wireType != 0 {
  706. return fmt.Errorf("proto: wrong wireType = %d for field RejectHint", wireType)
  707. }
  708. for shift := uint(0); ; shift += 7 {
  709. if iNdEx >= l {
  710. return io.ErrUnexpectedEOF
  711. }
  712. b := data[iNdEx]
  713. iNdEx++
  714. m.RejectHint |= (uint64(b) & 0x7F) << shift
  715. if b < 0x80 {
  716. break
  717. }
  718. }
  719. default:
  720. var sizeOfWire int
  721. for {
  722. sizeOfWire++
  723. wire >>= 7
  724. if wire == 0 {
  725. break
  726. }
  727. }
  728. iNdEx -= sizeOfWire
  729. skippy, err := skipRaft(data[iNdEx:])
  730. if err != nil {
  731. return err
  732. }
  733. if (iNdEx + skippy) > l {
  734. return io.ErrUnexpectedEOF
  735. }
  736. m.XXX_unrecognized = append(m.XXX_unrecognized, data[iNdEx:iNdEx+skippy]...)
  737. iNdEx += skippy
  738. }
  739. }
  740. return nil
  741. }
  742. func (m *HardState) Unmarshal(data []byte) error {
  743. l := len(data)
  744. iNdEx := 0
  745. for iNdEx < l {
  746. var wire uint64
  747. for shift := uint(0); ; shift += 7 {
  748. if iNdEx >= l {
  749. return io.ErrUnexpectedEOF
  750. }
  751. b := data[iNdEx]
  752. iNdEx++
  753. wire |= (uint64(b) & 0x7F) << shift
  754. if b < 0x80 {
  755. break
  756. }
  757. }
  758. fieldNum := int32(wire >> 3)
  759. wireType := int(wire & 0x7)
  760. switch fieldNum {
  761. case 1:
  762. if wireType != 0 {
  763. return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType)
  764. }
  765. for shift := uint(0); ; shift += 7 {
  766. if iNdEx >= l {
  767. return io.ErrUnexpectedEOF
  768. }
  769. b := data[iNdEx]
  770. iNdEx++
  771. m.Term |= (uint64(b) & 0x7F) << shift
  772. if b < 0x80 {
  773. break
  774. }
  775. }
  776. case 2:
  777. if wireType != 0 {
  778. return fmt.Errorf("proto: wrong wireType = %d for field Vote", wireType)
  779. }
  780. for shift := uint(0); ; shift += 7 {
  781. if iNdEx >= l {
  782. return io.ErrUnexpectedEOF
  783. }
  784. b := data[iNdEx]
  785. iNdEx++
  786. m.Vote |= (uint64(b) & 0x7F) << shift
  787. if b < 0x80 {
  788. break
  789. }
  790. }
  791. case 3:
  792. if wireType != 0 {
  793. return fmt.Errorf("proto: wrong wireType = %d for field Commit", wireType)
  794. }
  795. for shift := uint(0); ; shift += 7 {
  796. if iNdEx >= l {
  797. return io.ErrUnexpectedEOF
  798. }
  799. b := data[iNdEx]
  800. iNdEx++
  801. m.Commit |= (uint64(b) & 0x7F) << shift
  802. if b < 0x80 {
  803. break
  804. }
  805. }
  806. default:
  807. var sizeOfWire int
  808. for {
  809. sizeOfWire++
  810. wire >>= 7
  811. if wire == 0 {
  812. break
  813. }
  814. }
  815. iNdEx -= sizeOfWire
  816. skippy, err := skipRaft(data[iNdEx:])
  817. if err != nil {
  818. return err
  819. }
  820. if (iNdEx + skippy) > l {
  821. return io.ErrUnexpectedEOF
  822. }
  823. m.XXX_unrecognized = append(m.XXX_unrecognized, data[iNdEx:iNdEx+skippy]...)
  824. iNdEx += skippy
  825. }
  826. }
  827. return nil
  828. }
  829. func (m *ConfState) Unmarshal(data []byte) error {
  830. l := len(data)
  831. iNdEx := 0
  832. for iNdEx < l {
  833. var wire uint64
  834. for shift := uint(0); ; shift += 7 {
  835. if iNdEx >= l {
  836. return io.ErrUnexpectedEOF
  837. }
  838. b := data[iNdEx]
  839. iNdEx++
  840. wire |= (uint64(b) & 0x7F) << shift
  841. if b < 0x80 {
  842. break
  843. }
  844. }
  845. fieldNum := int32(wire >> 3)
  846. wireType := int(wire & 0x7)
  847. switch fieldNum {
  848. case 1:
  849. if wireType != 0 {
  850. return fmt.Errorf("proto: wrong wireType = %d for field Nodes", wireType)
  851. }
  852. var v uint64
  853. for shift := uint(0); ; shift += 7 {
  854. if iNdEx >= l {
  855. return io.ErrUnexpectedEOF
  856. }
  857. b := data[iNdEx]
  858. iNdEx++
  859. v |= (uint64(b) & 0x7F) << shift
  860. if b < 0x80 {
  861. break
  862. }
  863. }
  864. m.Nodes = append(m.Nodes, v)
  865. default:
  866. var sizeOfWire int
  867. for {
  868. sizeOfWire++
  869. wire >>= 7
  870. if wire == 0 {
  871. break
  872. }
  873. }
  874. iNdEx -= sizeOfWire
  875. skippy, err := skipRaft(data[iNdEx:])
  876. if err != nil {
  877. return err
  878. }
  879. if (iNdEx + skippy) > l {
  880. return io.ErrUnexpectedEOF
  881. }
  882. m.XXX_unrecognized = append(m.XXX_unrecognized, data[iNdEx:iNdEx+skippy]...)
  883. iNdEx += skippy
  884. }
  885. }
  886. return nil
  887. }
  888. func (m *ConfChange) Unmarshal(data []byte) error {
  889. l := len(data)
  890. iNdEx := 0
  891. for iNdEx < l {
  892. var wire uint64
  893. for shift := uint(0); ; shift += 7 {
  894. if iNdEx >= l {
  895. return io.ErrUnexpectedEOF
  896. }
  897. b := data[iNdEx]
  898. iNdEx++
  899. wire |= (uint64(b) & 0x7F) << shift
  900. if b < 0x80 {
  901. break
  902. }
  903. }
  904. fieldNum := int32(wire >> 3)
  905. wireType := int(wire & 0x7)
  906. switch fieldNum {
  907. case 1:
  908. if wireType != 0 {
  909. return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType)
  910. }
  911. for shift := uint(0); ; shift += 7 {
  912. if iNdEx >= l {
  913. return io.ErrUnexpectedEOF
  914. }
  915. b := data[iNdEx]
  916. iNdEx++
  917. m.ID |= (uint64(b) & 0x7F) << shift
  918. if b < 0x80 {
  919. break
  920. }
  921. }
  922. case 2:
  923. if wireType != 0 {
  924. return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType)
  925. }
  926. for shift := uint(0); ; shift += 7 {
  927. if iNdEx >= l {
  928. return io.ErrUnexpectedEOF
  929. }
  930. b := data[iNdEx]
  931. iNdEx++
  932. m.Type |= (ConfChangeType(b) & 0x7F) << shift
  933. if b < 0x80 {
  934. break
  935. }
  936. }
  937. case 3:
  938. if wireType != 0 {
  939. return fmt.Errorf("proto: wrong wireType = %d for field NodeID", wireType)
  940. }
  941. for shift := uint(0); ; shift += 7 {
  942. if iNdEx >= l {
  943. return io.ErrUnexpectedEOF
  944. }
  945. b := data[iNdEx]
  946. iNdEx++
  947. m.NodeID |= (uint64(b) & 0x7F) << shift
  948. if b < 0x80 {
  949. break
  950. }
  951. }
  952. case 4:
  953. if wireType != 2 {
  954. return fmt.Errorf("proto: wrong wireType = %d for field Context", wireType)
  955. }
  956. var byteLen int
  957. for shift := uint(0); ; shift += 7 {
  958. if iNdEx >= l {
  959. return io.ErrUnexpectedEOF
  960. }
  961. b := data[iNdEx]
  962. iNdEx++
  963. byteLen |= (int(b) & 0x7F) << shift
  964. if b < 0x80 {
  965. break
  966. }
  967. }
  968. postIndex := iNdEx + byteLen
  969. if postIndex > l {
  970. return io.ErrUnexpectedEOF
  971. }
  972. m.Context = append([]byte{}, data[iNdEx:postIndex]...)
  973. iNdEx = postIndex
  974. default:
  975. var sizeOfWire int
  976. for {
  977. sizeOfWire++
  978. wire >>= 7
  979. if wire == 0 {
  980. break
  981. }
  982. }
  983. iNdEx -= sizeOfWire
  984. skippy, err := skipRaft(data[iNdEx:])
  985. if err != nil {
  986. return err
  987. }
  988. if (iNdEx + skippy) > l {
  989. return io.ErrUnexpectedEOF
  990. }
  991. m.XXX_unrecognized = append(m.XXX_unrecognized, data[iNdEx:iNdEx+skippy]...)
  992. iNdEx += skippy
  993. }
  994. }
  995. return nil
  996. }
  997. func skipRaft(data []byte) (n int, err error) {
  998. l := len(data)
  999. iNdEx := 0
  1000. for iNdEx < l {
  1001. var wire uint64
  1002. for shift := uint(0); ; shift += 7 {
  1003. if iNdEx >= l {
  1004. return 0, io.ErrUnexpectedEOF
  1005. }
  1006. b := data[iNdEx]
  1007. iNdEx++
  1008. wire |= (uint64(b) & 0x7F) << shift
  1009. if b < 0x80 {
  1010. break
  1011. }
  1012. }
  1013. wireType := int(wire & 0x7)
  1014. switch wireType {
  1015. case 0:
  1016. for {
  1017. if iNdEx >= l {
  1018. return 0, io.ErrUnexpectedEOF
  1019. }
  1020. iNdEx++
  1021. if data[iNdEx-1] < 0x80 {
  1022. break
  1023. }
  1024. }
  1025. return iNdEx, nil
  1026. case 1:
  1027. iNdEx += 8
  1028. return iNdEx, nil
  1029. case 2:
  1030. var length int
  1031. for shift := uint(0); ; shift += 7 {
  1032. if iNdEx >= l {
  1033. return 0, io.ErrUnexpectedEOF
  1034. }
  1035. b := data[iNdEx]
  1036. iNdEx++
  1037. length |= (int(b) & 0x7F) << shift
  1038. if b < 0x80 {
  1039. break
  1040. }
  1041. }
  1042. iNdEx += length
  1043. return iNdEx, nil
  1044. case 3:
  1045. for {
  1046. var innerWire uint64
  1047. var start int = iNdEx
  1048. for shift := uint(0); ; shift += 7 {
  1049. if iNdEx >= l {
  1050. return 0, io.ErrUnexpectedEOF
  1051. }
  1052. b := data[iNdEx]
  1053. iNdEx++
  1054. innerWire |= (uint64(b) & 0x7F) << shift
  1055. if b < 0x80 {
  1056. break
  1057. }
  1058. }
  1059. innerWireType := int(innerWire & 0x7)
  1060. if innerWireType == 4 {
  1061. break
  1062. }
  1063. next, err := skipRaft(data[start:])
  1064. if err != nil {
  1065. return 0, err
  1066. }
  1067. iNdEx = start + next
  1068. }
  1069. return iNdEx, nil
  1070. case 4:
  1071. return iNdEx, nil
  1072. case 5:
  1073. iNdEx += 4
  1074. return iNdEx, nil
  1075. default:
  1076. return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
  1077. }
  1078. }
  1079. panic("unreachable")
  1080. }
  1081. func (m *Entry) Size() (n int) {
  1082. var l int
  1083. _ = l
  1084. n += 1 + sovRaft(uint64(m.Type))
  1085. n += 1 + sovRaft(uint64(m.Term))
  1086. n += 1 + sovRaft(uint64(m.Index))
  1087. if m.Data != nil {
  1088. l = len(m.Data)
  1089. n += 1 + l + sovRaft(uint64(l))
  1090. }
  1091. if m.XXX_unrecognized != nil {
  1092. n += len(m.XXX_unrecognized)
  1093. }
  1094. return n
  1095. }
  1096. func (m *SnapshotMetadata) Size() (n int) {
  1097. var l int
  1098. _ = l
  1099. l = m.ConfState.Size()
  1100. n += 1 + l + sovRaft(uint64(l))
  1101. n += 1 + sovRaft(uint64(m.Index))
  1102. n += 1 + sovRaft(uint64(m.Term))
  1103. if m.XXX_unrecognized != nil {
  1104. n += len(m.XXX_unrecognized)
  1105. }
  1106. return n
  1107. }
  1108. func (m *Snapshot) Size() (n int) {
  1109. var l int
  1110. _ = l
  1111. if m.Data != nil {
  1112. l = len(m.Data)
  1113. n += 1 + l + sovRaft(uint64(l))
  1114. }
  1115. l = m.Metadata.Size()
  1116. n += 1 + l + sovRaft(uint64(l))
  1117. if m.XXX_unrecognized != nil {
  1118. n += len(m.XXX_unrecognized)
  1119. }
  1120. return n
  1121. }
  1122. func (m *Message) Size() (n int) {
  1123. var l int
  1124. _ = l
  1125. n += 1 + sovRaft(uint64(m.Type))
  1126. n += 1 + sovRaft(uint64(m.To))
  1127. n += 1 + sovRaft(uint64(m.From))
  1128. n += 1 + sovRaft(uint64(m.Term))
  1129. n += 1 + sovRaft(uint64(m.LogTerm))
  1130. n += 1 + sovRaft(uint64(m.Index))
  1131. if len(m.Entries) > 0 {
  1132. for _, e := range m.Entries {
  1133. l = e.Size()
  1134. n += 1 + l + sovRaft(uint64(l))
  1135. }
  1136. }
  1137. n += 1 + sovRaft(uint64(m.Commit))
  1138. l = m.Snapshot.Size()
  1139. n += 1 + l + sovRaft(uint64(l))
  1140. n += 2
  1141. n += 1 + sovRaft(uint64(m.RejectHint))
  1142. if m.XXX_unrecognized != nil {
  1143. n += len(m.XXX_unrecognized)
  1144. }
  1145. return n
  1146. }
  1147. func (m *HardState) Size() (n int) {
  1148. var l int
  1149. _ = l
  1150. n += 1 + sovRaft(uint64(m.Term))
  1151. n += 1 + sovRaft(uint64(m.Vote))
  1152. n += 1 + sovRaft(uint64(m.Commit))
  1153. if m.XXX_unrecognized != nil {
  1154. n += len(m.XXX_unrecognized)
  1155. }
  1156. return n
  1157. }
  1158. func (m *ConfState) Size() (n int) {
  1159. var l int
  1160. _ = l
  1161. if len(m.Nodes) > 0 {
  1162. for _, e := range m.Nodes {
  1163. n += 1 + sovRaft(uint64(e))
  1164. }
  1165. }
  1166. if m.XXX_unrecognized != nil {
  1167. n += len(m.XXX_unrecognized)
  1168. }
  1169. return n
  1170. }
  1171. func (m *ConfChange) Size() (n int) {
  1172. var l int
  1173. _ = l
  1174. n += 1 + sovRaft(uint64(m.ID))
  1175. n += 1 + sovRaft(uint64(m.Type))
  1176. n += 1 + sovRaft(uint64(m.NodeID))
  1177. if m.Context != nil {
  1178. l = len(m.Context)
  1179. n += 1 + l + sovRaft(uint64(l))
  1180. }
  1181. if m.XXX_unrecognized != nil {
  1182. n += len(m.XXX_unrecognized)
  1183. }
  1184. return n
  1185. }
  1186. func sovRaft(x uint64) (n int) {
  1187. for {
  1188. n++
  1189. x >>= 7
  1190. if x == 0 {
  1191. break
  1192. }
  1193. }
  1194. return n
  1195. }
  1196. func sozRaft(x uint64) (n int) {
  1197. return sovRaft(uint64((x << 1) ^ uint64((int64(x) >> 63))))
  1198. }
  1199. func (m *Entry) Marshal() (data []byte, err error) {
  1200. size := m.Size()
  1201. data = make([]byte, size)
  1202. n, err := m.MarshalTo(data)
  1203. if err != nil {
  1204. return nil, err
  1205. }
  1206. return data[:n], nil
  1207. }
  1208. func (m *Entry) MarshalTo(data []byte) (n int, err error) {
  1209. var i int
  1210. _ = i
  1211. var l int
  1212. _ = l
  1213. data[i] = 0x8
  1214. i++
  1215. i = encodeVarintRaft(data, i, uint64(m.Type))
  1216. data[i] = 0x10
  1217. i++
  1218. i = encodeVarintRaft(data, i, uint64(m.Term))
  1219. data[i] = 0x18
  1220. i++
  1221. i = encodeVarintRaft(data, i, uint64(m.Index))
  1222. if m.Data != nil {
  1223. data[i] = 0x22
  1224. i++
  1225. i = encodeVarintRaft(data, i, uint64(len(m.Data)))
  1226. i += copy(data[i:], m.Data)
  1227. }
  1228. if m.XXX_unrecognized != nil {
  1229. i += copy(data[i:], m.XXX_unrecognized)
  1230. }
  1231. return i, nil
  1232. }
  1233. func (m *SnapshotMetadata) Marshal() (data []byte, err error) {
  1234. size := m.Size()
  1235. data = make([]byte, size)
  1236. n, err := m.MarshalTo(data)
  1237. if err != nil {
  1238. return nil, err
  1239. }
  1240. return data[:n], nil
  1241. }
  1242. func (m *SnapshotMetadata) MarshalTo(data []byte) (n int, err error) {
  1243. var i int
  1244. _ = i
  1245. var l int
  1246. _ = l
  1247. data[i] = 0xa
  1248. i++
  1249. i = encodeVarintRaft(data, i, uint64(m.ConfState.Size()))
  1250. n1, err := m.ConfState.MarshalTo(data[i:])
  1251. if err != nil {
  1252. return 0, err
  1253. }
  1254. i += n1
  1255. data[i] = 0x10
  1256. i++
  1257. i = encodeVarintRaft(data, i, uint64(m.Index))
  1258. data[i] = 0x18
  1259. i++
  1260. i = encodeVarintRaft(data, i, uint64(m.Term))
  1261. if m.XXX_unrecognized != nil {
  1262. i += copy(data[i:], m.XXX_unrecognized)
  1263. }
  1264. return i, nil
  1265. }
  1266. func (m *Snapshot) Marshal() (data []byte, err error) {
  1267. size := m.Size()
  1268. data = make([]byte, size)
  1269. n, err := m.MarshalTo(data)
  1270. if err != nil {
  1271. return nil, err
  1272. }
  1273. return data[:n], nil
  1274. }
  1275. func (m *Snapshot) MarshalTo(data []byte) (n int, err error) {
  1276. var i int
  1277. _ = i
  1278. var l int
  1279. _ = l
  1280. if m.Data != nil {
  1281. data[i] = 0xa
  1282. i++
  1283. i = encodeVarintRaft(data, i, uint64(len(m.Data)))
  1284. i += copy(data[i:], m.Data)
  1285. }
  1286. data[i] = 0x12
  1287. i++
  1288. i = encodeVarintRaft(data, i, uint64(m.Metadata.Size()))
  1289. n2, err := m.Metadata.MarshalTo(data[i:])
  1290. if err != nil {
  1291. return 0, err
  1292. }
  1293. i += n2
  1294. if m.XXX_unrecognized != nil {
  1295. i += copy(data[i:], m.XXX_unrecognized)
  1296. }
  1297. return i, nil
  1298. }
  1299. func (m *Message) Marshal() (data []byte, err error) {
  1300. size := m.Size()
  1301. data = make([]byte, size)
  1302. n, err := m.MarshalTo(data)
  1303. if err != nil {
  1304. return nil, err
  1305. }
  1306. return data[:n], nil
  1307. }
  1308. func (m *Message) MarshalTo(data []byte) (n int, err error) {
  1309. var i int
  1310. _ = i
  1311. var l int
  1312. _ = l
  1313. data[i] = 0x8
  1314. i++
  1315. i = encodeVarintRaft(data, i, uint64(m.Type))
  1316. data[i] = 0x10
  1317. i++
  1318. i = encodeVarintRaft(data, i, uint64(m.To))
  1319. data[i] = 0x18
  1320. i++
  1321. i = encodeVarintRaft(data, i, uint64(m.From))
  1322. data[i] = 0x20
  1323. i++
  1324. i = encodeVarintRaft(data, i, uint64(m.Term))
  1325. data[i] = 0x28
  1326. i++
  1327. i = encodeVarintRaft(data, i, uint64(m.LogTerm))
  1328. data[i] = 0x30
  1329. i++
  1330. i = encodeVarintRaft(data, i, uint64(m.Index))
  1331. if len(m.Entries) > 0 {
  1332. for _, msg := range m.Entries {
  1333. data[i] = 0x3a
  1334. i++
  1335. i = encodeVarintRaft(data, i, uint64(msg.Size()))
  1336. n, err := msg.MarshalTo(data[i:])
  1337. if err != nil {
  1338. return 0, err
  1339. }
  1340. i += n
  1341. }
  1342. }
  1343. data[i] = 0x40
  1344. i++
  1345. i = encodeVarintRaft(data, i, uint64(m.Commit))
  1346. data[i] = 0x4a
  1347. i++
  1348. i = encodeVarintRaft(data, i, uint64(m.Snapshot.Size()))
  1349. n3, err := m.Snapshot.MarshalTo(data[i:])
  1350. if err != nil {
  1351. return 0, err
  1352. }
  1353. i += n3
  1354. data[i] = 0x50
  1355. i++
  1356. if m.Reject {
  1357. data[i] = 1
  1358. } else {
  1359. data[i] = 0
  1360. }
  1361. i++
  1362. data[i] = 0x58
  1363. i++
  1364. i = encodeVarintRaft(data, i, uint64(m.RejectHint))
  1365. if m.XXX_unrecognized != nil {
  1366. i += copy(data[i:], m.XXX_unrecognized)
  1367. }
  1368. return i, nil
  1369. }
  1370. func (m *HardState) Marshal() (data []byte, err error) {
  1371. size := m.Size()
  1372. data = make([]byte, size)
  1373. n, err := m.MarshalTo(data)
  1374. if err != nil {
  1375. return nil, err
  1376. }
  1377. return data[:n], nil
  1378. }
  1379. func (m *HardState) MarshalTo(data []byte) (n int, err error) {
  1380. var i int
  1381. _ = i
  1382. var l int
  1383. _ = l
  1384. data[i] = 0x8
  1385. i++
  1386. i = encodeVarintRaft(data, i, uint64(m.Term))
  1387. data[i] = 0x10
  1388. i++
  1389. i = encodeVarintRaft(data, i, uint64(m.Vote))
  1390. data[i] = 0x18
  1391. i++
  1392. i = encodeVarintRaft(data, i, uint64(m.Commit))
  1393. if m.XXX_unrecognized != nil {
  1394. i += copy(data[i:], m.XXX_unrecognized)
  1395. }
  1396. return i, nil
  1397. }
  1398. func (m *ConfState) Marshal() (data []byte, err error) {
  1399. size := m.Size()
  1400. data = make([]byte, size)
  1401. n, err := m.MarshalTo(data)
  1402. if err != nil {
  1403. return nil, err
  1404. }
  1405. return data[:n], nil
  1406. }
  1407. func (m *ConfState) MarshalTo(data []byte) (n int, err error) {
  1408. var i int
  1409. _ = i
  1410. var l int
  1411. _ = l
  1412. if len(m.Nodes) > 0 {
  1413. for _, num := range m.Nodes {
  1414. data[i] = 0x8
  1415. i++
  1416. i = encodeVarintRaft(data, i, uint64(num))
  1417. }
  1418. }
  1419. if m.XXX_unrecognized != nil {
  1420. i += copy(data[i:], m.XXX_unrecognized)
  1421. }
  1422. return i, nil
  1423. }
  1424. func (m *ConfChange) Marshal() (data []byte, err error) {
  1425. size := m.Size()
  1426. data = make([]byte, size)
  1427. n, err := m.MarshalTo(data)
  1428. if err != nil {
  1429. return nil, err
  1430. }
  1431. return data[:n], nil
  1432. }
  1433. func (m *ConfChange) MarshalTo(data []byte) (n int, err error) {
  1434. var i int
  1435. _ = i
  1436. var l int
  1437. _ = l
  1438. data[i] = 0x8
  1439. i++
  1440. i = encodeVarintRaft(data, i, uint64(m.ID))
  1441. data[i] = 0x10
  1442. i++
  1443. i = encodeVarintRaft(data, i, uint64(m.Type))
  1444. data[i] = 0x18
  1445. i++
  1446. i = encodeVarintRaft(data, i, uint64(m.NodeID))
  1447. if m.Context != nil {
  1448. data[i] = 0x22
  1449. i++
  1450. i = encodeVarintRaft(data, i, uint64(len(m.Context)))
  1451. i += copy(data[i:], m.Context)
  1452. }
  1453. if m.XXX_unrecognized != nil {
  1454. i += copy(data[i:], m.XXX_unrecognized)
  1455. }
  1456. return i, nil
  1457. }
  1458. func encodeFixed64Raft(data []byte, offset int, v uint64) int {
  1459. data[offset] = uint8(v)
  1460. data[offset+1] = uint8(v >> 8)
  1461. data[offset+2] = uint8(v >> 16)
  1462. data[offset+3] = uint8(v >> 24)
  1463. data[offset+4] = uint8(v >> 32)
  1464. data[offset+5] = uint8(v >> 40)
  1465. data[offset+6] = uint8(v >> 48)
  1466. data[offset+7] = uint8(v >> 56)
  1467. return offset + 8
  1468. }
  1469. func encodeFixed32Raft(data []byte, offset int, v uint32) int {
  1470. data[offset] = uint8(v)
  1471. data[offset+1] = uint8(v >> 8)
  1472. data[offset+2] = uint8(v >> 16)
  1473. data[offset+3] = uint8(v >> 24)
  1474. return offset + 4
  1475. }
  1476. func encodeVarintRaft(data []byte, offset int, v uint64) int {
  1477. for v >= 1<<7 {
  1478. data[offset] = uint8(v&0x7f | 0x80)
  1479. v >>= 7
  1480. offset++
  1481. }
  1482. data[offset] = uint8(v)
  1483. return offset + 1
  1484. }