55package xdr_test
66
77import (
8- "github.com/imdario /xdr"
8+ "dario.cat /xdr"
99)
1010
1111/*
@@ -99,6 +99,7 @@ struct TestStruct {
9999
100100*/
101101
102+ // XDRSize returns the XDR encoded form's size.
102103func (o TestStruct ) XDRSize () int {
103104 return 4 + 8 + 4 + 4 + 4 + 4 + 4 + 4 + 8 + 8 +
104105 4 + len (o .BS ) + xdr .Padding (len (o .BS )) +
@@ -110,12 +111,15 @@ func (o TestStruct) XDRSize() int {
110111 4 + xdr .SizeOfSlice (o .OSs )
111112}
112113
114+ // MarshalXDR returns the XDR encoding.
113115func (o TestStruct ) MarshalXDR () ([]byte , error ) {
114116 buf := make ([]byte , o .XDRSize ())
115117 m := & xdr.Marshaller {Data : buf }
116118 return buf , o .MarshalXDRInto (m )
117119}
118120
121+ // MustMarshalXDR returns the XDR encoding. MustMarshalXDR
122+ // panics in case of error.
119123func (o TestStruct ) MustMarshalXDR () []byte {
120124 bs , err := o .MarshalXDR ()
121125 if err != nil {
@@ -124,6 +128,7 @@ func (o TestStruct) MustMarshalXDR() []byte {
124128 return bs
125129}
126130
131+ // MarshalXDRInto marshals the struct using the provided Marshaller.
127132func (o TestStruct ) MarshalXDRInto (m * xdr.Marshaller ) error {
128133 m .MarshalBool (o .B )
129134 m .MarshalUint64 (uint64 (o .I ))
@@ -168,10 +173,14 @@ func (o TestStruct) MarshalXDRInto(m *xdr.Marshaller) error {
168173 return m .Error
169174}
170175
176+ // UnmarshalXDR parses the XDR-encoded data and stores the result in the
177+ // struct.
171178func (o * TestStruct ) UnmarshalXDR (bs []byte ) error {
172179 u := & xdr.Unmarshaller {Data : bs }
173180 return o .UnmarshalXDRFrom (u )
174181}
182+
183+ // UnmarshalXDRFrom unmarshals the struct using the provided Unmarshaller.
175184func (o * TestStruct ) UnmarshalXDRFrom (u * xdr.Unmarshaller ) error {
176185 o .B = u .UnmarshalBool ()
177186 o .I = int (u .UnmarshalUint64 ())
@@ -238,25 +247,34 @@ struct EmptyStruct {
238247
239248*/
240249
250+ // XDRSize returns the XDR encoded form's size.
241251func (o EmptyStruct ) XDRSize () int {
242252 return 0
243253}
254+
255+ // MarshalXDR returns the XDR encoding.
244256func (o EmptyStruct ) MarshalXDR () ([]byte , error ) {
245257 return nil , nil
246258}
247259
260+ // MustMarshalXDR returns the XDR encoding. MustMarshalXDR
261+ // panics in case of error.
248262func (o EmptyStruct ) MustMarshalXDR () []byte {
249263 return nil
250264}
251265
266+ // MarshalXDRInto marshals the struct using the provided Marshaller.
252267func (o EmptyStruct ) MarshalXDRInto (m * xdr.Marshaller ) error {
253268 return nil
254269}
255270
271+ // UnmarshalXDR parses the XDR-encoded data and stores the result in the
272+ // struct.
256273func (o * EmptyStruct ) UnmarshalXDR (bs []byte ) error {
257274 return nil
258275}
259276
277+ // UnmarshalXDRFrom unmarshals the struct using the provided Unmarshaller.
260278func (o * EmptyStruct ) UnmarshalXDRFrom (u * xdr.Unmarshaller ) error {
261279 return nil
262280}
@@ -283,17 +301,21 @@ struct OtherStruct {
283301
284302*/
285303
304+ // XDRSize returns the XDR encoded form's size.
286305func (o OtherStruct ) XDRSize () int {
287306 return 4 +
288307 4 + len (o .F2 ) + xdr .Padding (len (o .F2 ))
289308}
290309
310+ // MarshalXDR returns the XDR encoding.
291311func (o OtherStruct ) MarshalXDR () ([]byte , error ) {
292312 buf := make ([]byte , o .XDRSize ())
293313 m := & xdr.Marshaller {Data : buf }
294314 return buf , o .MarshalXDRInto (m )
295315}
296316
317+ // MustMarshalXDR returns the XDR encoding. MustMarshalXDR
318+ // panics in case of error.
297319func (o OtherStruct ) MustMarshalXDR () []byte {
298320 bs , err := o .MarshalXDR ()
299321 if err != nil {
@@ -302,16 +324,21 @@ func (o OtherStruct) MustMarshalXDR() []byte {
302324 return bs
303325}
304326
327+ // MarshalXDRInto marshals the struct using the provided Marshaller.
305328func (o OtherStruct ) MarshalXDRInto (m * xdr.Marshaller ) error {
306329 m .MarshalUint32 (o .F1 )
307330 m .MarshalString (o .F2 )
308331 return m .Error
309332}
310333
334+ // UnmarshalXDR parses the XDR-encoded data and stores the result in the
335+ // struct.
311336func (o * OtherStruct ) UnmarshalXDR (bs []byte ) error {
312337 u := & xdr.Unmarshaller {Data : bs }
313338 return o .UnmarshalXDRFrom (u )
314339}
340+
341+ // UnmarshalXDRFrom unmarshals the struct using the provided Unmarshaller.
315342func (o * OtherStruct ) UnmarshalXDRFrom (u * xdr.Unmarshaller ) error {
316343 o .F1 = u .UnmarshalUint32 ()
317344 o .F2 = u .UnmarshalString ()
0 commit comments