mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-10 07:11:08 +00:00
e522811a52
The XDR encoder doesn't understart slices of strings very well. It can encode and decode them, but there's no way to set limits on the length of the strings themselves (only on the length of the slice), and the generated diagrams are incorrect. This trivially works around this, while also documenting what the string actually is (a URL).
381 lines
10 KiB
Go
381 lines
10 KiB
Go
// ************************************************************
|
|
// This file is automatically generated by genxdr. Do not edit.
|
|
// ************************************************************
|
|
|
|
package discover
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
|
|
"github.com/calmh/xdr"
|
|
)
|
|
|
|
/*
|
|
|
|
Announce Structure:
|
|
|
|
0 1 2 3
|
|
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
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
| Magic |
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
/ /
|
|
\ Device Structure \
|
|
/ /
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
| Number of Extra |
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
/ /
|
|
\ Zero or more Device Structures \
|
|
/ /
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
|
struct Announce {
|
|
unsigned int Magic;
|
|
Device This;
|
|
Device Extra<16>;
|
|
}
|
|
|
|
*/
|
|
|
|
func (o Announce) EncodeXDR(w io.Writer) (int, error) {
|
|
var xw = xdr.NewWriter(w)
|
|
return o.EncodeXDRInto(xw)
|
|
}
|
|
|
|
func (o Announce) MarshalXDR() ([]byte, error) {
|
|
return o.AppendXDR(make([]byte, 0, 128))
|
|
}
|
|
|
|
func (o Announce) MustMarshalXDR() []byte {
|
|
bs, err := o.MarshalXDR()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return bs
|
|
}
|
|
|
|
func (o Announce) AppendXDR(bs []byte) ([]byte, error) {
|
|
var aw = xdr.AppendWriter(bs)
|
|
var xw = xdr.NewWriter(&aw)
|
|
_, err := o.EncodeXDRInto(xw)
|
|
return []byte(aw), err
|
|
}
|
|
|
|
func (o Announce) EncodeXDRInto(xw *xdr.Writer) (int, error) {
|
|
xw.WriteUint32(o.Magic)
|
|
_, err := o.This.EncodeXDRInto(xw)
|
|
if err != nil {
|
|
return xw.Tot(), err
|
|
}
|
|
if l := len(o.Extra); l > 16 {
|
|
return xw.Tot(), xdr.ElementSizeExceeded("Extra", l, 16)
|
|
}
|
|
xw.WriteUint32(uint32(len(o.Extra)))
|
|
for i := range o.Extra {
|
|
_, err := o.Extra[i].EncodeXDRInto(xw)
|
|
if err != nil {
|
|
return xw.Tot(), err
|
|
}
|
|
}
|
|
return xw.Tot(), xw.Error()
|
|
}
|
|
|
|
func (o *Announce) DecodeXDR(r io.Reader) error {
|
|
xr := xdr.NewReader(r)
|
|
return o.DecodeXDRFrom(xr)
|
|
}
|
|
|
|
func (o *Announce) UnmarshalXDR(bs []byte) error {
|
|
var br = bytes.NewReader(bs)
|
|
var xr = xdr.NewReader(br)
|
|
return o.DecodeXDRFrom(xr)
|
|
}
|
|
|
|
func (o *Announce) DecodeXDRFrom(xr *xdr.Reader) error {
|
|
o.Magic = xr.ReadUint32()
|
|
(&o.This).DecodeXDRFrom(xr)
|
|
_ExtraSize := int(xr.ReadUint32())
|
|
if _ExtraSize < 0 {
|
|
return xdr.ElementSizeExceeded("Extra", _ExtraSize, 16)
|
|
}
|
|
if _ExtraSize > 16 {
|
|
return xdr.ElementSizeExceeded("Extra", _ExtraSize, 16)
|
|
}
|
|
o.Extra = make([]Device, _ExtraSize)
|
|
for i := range o.Extra {
|
|
(&o.Extra[i]).DecodeXDRFrom(xr)
|
|
}
|
|
return xr.Error()
|
|
}
|
|
|
|
/*
|
|
|
|
Device Structure:
|
|
|
|
0 1 2 3
|
|
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
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
| Length of ID |
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
/ /
|
|
\ ID (variable length) \
|
|
/ /
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
| Number of Addresses |
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
/ /
|
|
\ Zero or more Address Structures \
|
|
/ /
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
| Number of Relays |
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
/ /
|
|
\ Zero or more Relay Structures \
|
|
/ /
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
|
struct Device {
|
|
opaque ID<32>;
|
|
Address Addresses<16>;
|
|
Relay Relays<16>;
|
|
}
|
|
|
|
*/
|
|
|
|
func (o Device) EncodeXDR(w io.Writer) (int, error) {
|
|
var xw = xdr.NewWriter(w)
|
|
return o.EncodeXDRInto(xw)
|
|
}
|
|
|
|
func (o Device) MarshalXDR() ([]byte, error) {
|
|
return o.AppendXDR(make([]byte, 0, 128))
|
|
}
|
|
|
|
func (o Device) MustMarshalXDR() []byte {
|
|
bs, err := o.MarshalXDR()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return bs
|
|
}
|
|
|
|
func (o Device) AppendXDR(bs []byte) ([]byte, error) {
|
|
var aw = xdr.AppendWriter(bs)
|
|
var xw = xdr.NewWriter(&aw)
|
|
_, err := o.EncodeXDRInto(xw)
|
|
return []byte(aw), err
|
|
}
|
|
|
|
func (o Device) EncodeXDRInto(xw *xdr.Writer) (int, error) {
|
|
if l := len(o.ID); l > 32 {
|
|
return xw.Tot(), xdr.ElementSizeExceeded("ID", l, 32)
|
|
}
|
|
xw.WriteBytes(o.ID)
|
|
if l := len(o.Addresses); l > 16 {
|
|
return xw.Tot(), xdr.ElementSizeExceeded("Addresses", l, 16)
|
|
}
|
|
xw.WriteUint32(uint32(len(o.Addresses)))
|
|
for i := range o.Addresses {
|
|
_, err := o.Addresses[i].EncodeXDRInto(xw)
|
|
if err != nil {
|
|
return xw.Tot(), err
|
|
}
|
|
}
|
|
if l := len(o.Relays); l > 16 {
|
|
return xw.Tot(), xdr.ElementSizeExceeded("Relays", l, 16)
|
|
}
|
|
xw.WriteUint32(uint32(len(o.Relays)))
|
|
for i := range o.Relays {
|
|
_, err := o.Relays[i].EncodeXDRInto(xw)
|
|
if err != nil {
|
|
return xw.Tot(), err
|
|
}
|
|
}
|
|
return xw.Tot(), xw.Error()
|
|
}
|
|
|
|
func (o *Device) DecodeXDR(r io.Reader) error {
|
|
xr := xdr.NewReader(r)
|
|
return o.DecodeXDRFrom(xr)
|
|
}
|
|
|
|
func (o *Device) UnmarshalXDR(bs []byte) error {
|
|
var br = bytes.NewReader(bs)
|
|
var xr = xdr.NewReader(br)
|
|
return o.DecodeXDRFrom(xr)
|
|
}
|
|
|
|
func (o *Device) DecodeXDRFrom(xr *xdr.Reader) error {
|
|
o.ID = xr.ReadBytesMax(32)
|
|
_AddressesSize := int(xr.ReadUint32())
|
|
if _AddressesSize < 0 {
|
|
return xdr.ElementSizeExceeded("Addresses", _AddressesSize, 16)
|
|
}
|
|
if _AddressesSize > 16 {
|
|
return xdr.ElementSizeExceeded("Addresses", _AddressesSize, 16)
|
|
}
|
|
o.Addresses = make([]Address, _AddressesSize)
|
|
for i := range o.Addresses {
|
|
(&o.Addresses[i]).DecodeXDRFrom(xr)
|
|
}
|
|
_RelaysSize := int(xr.ReadUint32())
|
|
if _RelaysSize < 0 {
|
|
return xdr.ElementSizeExceeded("Relays", _RelaysSize, 16)
|
|
}
|
|
if _RelaysSize > 16 {
|
|
return xdr.ElementSizeExceeded("Relays", _RelaysSize, 16)
|
|
}
|
|
o.Relays = make([]Relay, _RelaysSize)
|
|
for i := range o.Relays {
|
|
(&o.Relays[i]).DecodeXDRFrom(xr)
|
|
}
|
|
return xr.Error()
|
|
}
|
|
|
|
/*
|
|
|
|
Address Structure:
|
|
|
|
0 1 2 3
|
|
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
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
| Length of URL |
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
/ /
|
|
\ URL (variable length) \
|
|
/ /
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
|
struct Address {
|
|
string URL<2083>;
|
|
}
|
|
|
|
*/
|
|
|
|
func (o Address) EncodeXDR(w io.Writer) (int, error) {
|
|
var xw = xdr.NewWriter(w)
|
|
return o.EncodeXDRInto(xw)
|
|
}
|
|
|
|
func (o Address) MarshalXDR() ([]byte, error) {
|
|
return o.AppendXDR(make([]byte, 0, 128))
|
|
}
|
|
|
|
func (o Address) MustMarshalXDR() []byte {
|
|
bs, err := o.MarshalXDR()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return bs
|
|
}
|
|
|
|
func (o Address) AppendXDR(bs []byte) ([]byte, error) {
|
|
var aw = xdr.AppendWriter(bs)
|
|
var xw = xdr.NewWriter(&aw)
|
|
_, err := o.EncodeXDRInto(xw)
|
|
return []byte(aw), err
|
|
}
|
|
|
|
func (o Address) EncodeXDRInto(xw *xdr.Writer) (int, error) {
|
|
if l := len(o.URL); l > 2083 {
|
|
return xw.Tot(), xdr.ElementSizeExceeded("URL", l, 2083)
|
|
}
|
|
xw.WriteString(o.URL)
|
|
return xw.Tot(), xw.Error()
|
|
}
|
|
|
|
func (o *Address) DecodeXDR(r io.Reader) error {
|
|
xr := xdr.NewReader(r)
|
|
return o.DecodeXDRFrom(xr)
|
|
}
|
|
|
|
func (o *Address) UnmarshalXDR(bs []byte) error {
|
|
var br = bytes.NewReader(bs)
|
|
var xr = xdr.NewReader(br)
|
|
return o.DecodeXDRFrom(xr)
|
|
}
|
|
|
|
func (o *Address) DecodeXDRFrom(xr *xdr.Reader) error {
|
|
o.URL = xr.ReadStringMax(2083)
|
|
return xr.Error()
|
|
}
|
|
|
|
/*
|
|
|
|
Relay Structure:
|
|
|
|
0 1 2 3
|
|
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
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
| Length of URL |
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
/ /
|
|
\ URL (variable length) \
|
|
/ /
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
| Latency |
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
|
struct Relay {
|
|
string URL<2083>;
|
|
int Latency;
|
|
}
|
|
|
|
*/
|
|
|
|
func (o Relay) EncodeXDR(w io.Writer) (int, error) {
|
|
var xw = xdr.NewWriter(w)
|
|
return o.EncodeXDRInto(xw)
|
|
}
|
|
|
|
func (o Relay) MarshalXDR() ([]byte, error) {
|
|
return o.AppendXDR(make([]byte, 0, 128))
|
|
}
|
|
|
|
func (o Relay) MustMarshalXDR() []byte {
|
|
bs, err := o.MarshalXDR()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return bs
|
|
}
|
|
|
|
func (o Relay) AppendXDR(bs []byte) ([]byte, error) {
|
|
var aw = xdr.AppendWriter(bs)
|
|
var xw = xdr.NewWriter(&aw)
|
|
_, err := o.EncodeXDRInto(xw)
|
|
return []byte(aw), err
|
|
}
|
|
|
|
func (o Relay) EncodeXDRInto(xw *xdr.Writer) (int, error) {
|
|
if l := len(o.URL); l > 2083 {
|
|
return xw.Tot(), xdr.ElementSizeExceeded("URL", l, 2083)
|
|
}
|
|
xw.WriteString(o.URL)
|
|
xw.WriteUint32(uint32(o.Latency))
|
|
return xw.Tot(), xw.Error()
|
|
}
|
|
|
|
func (o *Relay) DecodeXDR(r io.Reader) error {
|
|
xr := xdr.NewReader(r)
|
|
return o.DecodeXDRFrom(xr)
|
|
}
|
|
|
|
func (o *Relay) UnmarshalXDR(bs []byte) error {
|
|
var br = bytes.NewReader(bs)
|
|
var xr = xdr.NewReader(br)
|
|
return o.DecodeXDRFrom(xr)
|
|
}
|
|
|
|
func (o *Relay) DecodeXDRFrom(xr *xdr.Reader) error {
|
|
o.URL = xr.ReadStringMax(2083)
|
|
o.Latency = int32(xr.ReadUint32())
|
|
return xr.Error()
|
|
}
|