github.com/kayoticsully/syncthing@v0.8.9-0.20140724133906-c45a2fdc03f8/discover/packets_xdr.go (about)

     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  // ************************************************************
     6  // This file is automatically generated by genxdr. Do not edit.
     7  // ************************************************************
     8  
     9  package discover
    10  
    11  import (
    12  	"bytes"
    13  	"io"
    14  
    15  	"github.com/calmh/syncthing/xdr"
    16  )
    17  
    18  /*
    19  
    20  Query Structure:
    21  
    22   0                   1                   2                   3
    23   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
    24  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    25  |                             Magic                             |
    26  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    27  |                       Length of Node ID                       |
    28  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    29  /                                                               /
    30  \                   Node ID (variable length)                   \
    31  /                                                               /
    32  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    33  
    34  
    35  struct Query {
    36  	unsigned int Magic;
    37  	opaque NodeID<32>;
    38  }
    39  
    40  */
    41  
    42  func (o Query) EncodeXDR(w io.Writer) (int, error) {
    43  	var xw = xdr.NewWriter(w)
    44  	return o.encodeXDR(xw)
    45  }
    46  
    47  func (o Query) MarshalXDR() []byte {
    48  	return o.AppendXDR(make([]byte, 0, 128))
    49  }
    50  
    51  func (o Query) AppendXDR(bs []byte) []byte {
    52  	var aw = xdr.AppendWriter(bs)
    53  	var xw = xdr.NewWriter(&aw)
    54  	o.encodeXDR(xw)
    55  	return []byte(aw)
    56  }
    57  
    58  func (o Query) encodeXDR(xw *xdr.Writer) (int, error) {
    59  	xw.WriteUint32(o.Magic)
    60  	if len(o.NodeID) > 32 {
    61  		return xw.Tot(), xdr.ErrElementSizeExceeded
    62  	}
    63  	xw.WriteBytes(o.NodeID)
    64  	return xw.Tot(), xw.Error()
    65  }
    66  
    67  func (o *Query) DecodeXDR(r io.Reader) error {
    68  	xr := xdr.NewReader(r)
    69  	return o.decodeXDR(xr)
    70  }
    71  
    72  func (o *Query) UnmarshalXDR(bs []byte) error {
    73  	var br = bytes.NewReader(bs)
    74  	var xr = xdr.NewReader(br)
    75  	return o.decodeXDR(xr)
    76  }
    77  
    78  func (o *Query) decodeXDR(xr *xdr.Reader) error {
    79  	o.Magic = xr.ReadUint32()
    80  	o.NodeID = xr.ReadBytesMax(32)
    81  	return xr.Error()
    82  }
    83  
    84  /*
    85  
    86  Announce Structure:
    87  
    88   0                   1                   2                   3
    89   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
    90  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    91  |                             Magic                             |
    92  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    93  |                             Node                              |
    94  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    95  |                        Number of Extra                        |
    96  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    97  /                                                               /
    98  \                 Zero or more Node Structures                  \
    99  /                                                               /
   100  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   101  
   102  
   103  struct Announce {
   104  	unsigned int Magic;
   105  	Node This;
   106  	Node Extra<16>;
   107  }
   108  
   109  */
   110  
   111  func (o Announce) EncodeXDR(w io.Writer) (int, error) {
   112  	var xw = xdr.NewWriter(w)
   113  	return o.encodeXDR(xw)
   114  }
   115  
   116  func (o Announce) MarshalXDR() []byte {
   117  	return o.AppendXDR(make([]byte, 0, 128))
   118  }
   119  
   120  func (o Announce) AppendXDR(bs []byte) []byte {
   121  	var aw = xdr.AppendWriter(bs)
   122  	var xw = xdr.NewWriter(&aw)
   123  	o.encodeXDR(xw)
   124  	return []byte(aw)
   125  }
   126  
   127  func (o Announce) encodeXDR(xw *xdr.Writer) (int, error) {
   128  	xw.WriteUint32(o.Magic)
   129  	o.This.encodeXDR(xw)
   130  	if len(o.Extra) > 16 {
   131  		return xw.Tot(), xdr.ErrElementSizeExceeded
   132  	}
   133  	xw.WriteUint32(uint32(len(o.Extra)))
   134  	for i := range o.Extra {
   135  		o.Extra[i].encodeXDR(xw)
   136  	}
   137  	return xw.Tot(), xw.Error()
   138  }
   139  
   140  func (o *Announce) DecodeXDR(r io.Reader) error {
   141  	xr := xdr.NewReader(r)
   142  	return o.decodeXDR(xr)
   143  }
   144  
   145  func (o *Announce) UnmarshalXDR(bs []byte) error {
   146  	var br = bytes.NewReader(bs)
   147  	var xr = xdr.NewReader(br)
   148  	return o.decodeXDR(xr)
   149  }
   150  
   151  func (o *Announce) decodeXDR(xr *xdr.Reader) error {
   152  	o.Magic = xr.ReadUint32()
   153  	(&o.This).decodeXDR(xr)
   154  	_ExtraSize := int(xr.ReadUint32())
   155  	if _ExtraSize > 16 {
   156  		return xdr.ErrElementSizeExceeded
   157  	}
   158  	o.Extra = make([]Node, _ExtraSize)
   159  	for i := range o.Extra {
   160  		(&o.Extra[i]).decodeXDR(xr)
   161  	}
   162  	return xr.Error()
   163  }
   164  
   165  /*
   166  
   167  Node Structure:
   168  
   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  |                         Length of ID                          |
   173  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   174  /                                                               /
   175  \                     ID (variable length)                      \
   176  /                                                               /
   177  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   178  |                      Number of Addresses                      |
   179  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   180  /                                                               /
   181  \                Zero or more Address Structures                \
   182  /                                                               /
   183  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   184  
   185  
   186  struct Node {
   187  	opaque ID<32>;
   188  	Address Addresses<16>;
   189  }
   190  
   191  */
   192  
   193  func (o Node) EncodeXDR(w io.Writer) (int, error) {
   194  	var xw = xdr.NewWriter(w)
   195  	return o.encodeXDR(xw)
   196  }
   197  
   198  func (o Node) MarshalXDR() []byte {
   199  	return o.AppendXDR(make([]byte, 0, 128))
   200  }
   201  
   202  func (o Node) AppendXDR(bs []byte) []byte {
   203  	var aw = xdr.AppendWriter(bs)
   204  	var xw = xdr.NewWriter(&aw)
   205  	o.encodeXDR(xw)
   206  	return []byte(aw)
   207  }
   208  
   209  func (o Node) encodeXDR(xw *xdr.Writer) (int, error) {
   210  	if len(o.ID) > 32 {
   211  		return xw.Tot(), xdr.ErrElementSizeExceeded
   212  	}
   213  	xw.WriteBytes(o.ID)
   214  	if len(o.Addresses) > 16 {
   215  		return xw.Tot(), xdr.ErrElementSizeExceeded
   216  	}
   217  	xw.WriteUint32(uint32(len(o.Addresses)))
   218  	for i := range o.Addresses {
   219  		o.Addresses[i].encodeXDR(xw)
   220  	}
   221  	return xw.Tot(), xw.Error()
   222  }
   223  
   224  func (o *Node) DecodeXDR(r io.Reader) error {
   225  	xr := xdr.NewReader(r)
   226  	return o.decodeXDR(xr)
   227  }
   228  
   229  func (o *Node) UnmarshalXDR(bs []byte) error {
   230  	var br = bytes.NewReader(bs)
   231  	var xr = xdr.NewReader(br)
   232  	return o.decodeXDR(xr)
   233  }
   234  
   235  func (o *Node) decodeXDR(xr *xdr.Reader) error {
   236  	o.ID = xr.ReadBytesMax(32)
   237  	_AddressesSize := int(xr.ReadUint32())
   238  	if _AddressesSize > 16 {
   239  		return xdr.ErrElementSizeExceeded
   240  	}
   241  	o.Addresses = make([]Address, _AddressesSize)
   242  	for i := range o.Addresses {
   243  		(&o.Addresses[i]).decodeXDR(xr)
   244  	}
   245  	return xr.Error()
   246  }
   247  
   248  /*
   249  
   250  Address Structure:
   251  
   252   0                   1                   2                   3
   253   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
   254  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   255  |                         Length of IP                          |
   256  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   257  /                                                               /
   258  \                     IP (variable length)                      \
   259  /                                                               /
   260  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   261  |            0x0000             |             Port              |
   262  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   263  
   264  
   265  struct Address {
   266  	opaque IP<16>;
   267  	unsigned int Port;
   268  }
   269  
   270  */
   271  
   272  func (o Address) EncodeXDR(w io.Writer) (int, error) {
   273  	var xw = xdr.NewWriter(w)
   274  	return o.encodeXDR(xw)
   275  }
   276  
   277  func (o Address) MarshalXDR() []byte {
   278  	return o.AppendXDR(make([]byte, 0, 128))
   279  }
   280  
   281  func (o Address) AppendXDR(bs []byte) []byte {
   282  	var aw = xdr.AppendWriter(bs)
   283  	var xw = xdr.NewWriter(&aw)
   284  	o.encodeXDR(xw)
   285  	return []byte(aw)
   286  }
   287  
   288  func (o Address) encodeXDR(xw *xdr.Writer) (int, error) {
   289  	if len(o.IP) > 16 {
   290  		return xw.Tot(), xdr.ErrElementSizeExceeded
   291  	}
   292  	xw.WriteBytes(o.IP)
   293  	xw.WriteUint16(o.Port)
   294  	return xw.Tot(), xw.Error()
   295  }
   296  
   297  func (o *Address) DecodeXDR(r io.Reader) error {
   298  	xr := xdr.NewReader(r)
   299  	return o.decodeXDR(xr)
   300  }
   301  
   302  func (o *Address) UnmarshalXDR(bs []byte) error {
   303  	var br = bytes.NewReader(bs)
   304  	var xr = xdr.NewReader(br)
   305  	return o.decodeXDR(xr)
   306  }
   307  
   308  func (o *Address) decodeXDR(xr *xdr.Reader) error {
   309  	o.IP = xr.ReadBytesMax(16)
   310  	o.Port = xr.ReadUint16()
   311  	return xr.Error()
   312  }