Skip to content

Commit 5e342c0

Browse files
committed
Fixed linting warnings
1 parent 8bf7e85 commit 5e342c0

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

cmd/genxdr/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func (o {{.Name}}) MarshalXDRInto(m *xdr.Marshaller) error {
165165
}
166166
{{end}}
167167
168-
// Unmarshal parses the XDR-encoded data and stores the result in the
168+
// UnmarshalXDR parses the XDR-encoded data and stores the result in the
169169
// struct.
170170
func (o *{{.Name}}) UnmarshalXDR(bs []byte) error {
171171
u := &xdr.Unmarshaller{Data: bs}

common.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
var padBytes = []byte{0, 0, 0}
1313

14-
// Pad returns the number of bytes that should be added to an item of length l
14+
// Padding returns the number of bytes that should be added to an item of length l
1515
// bytes to conform to the XDR padding standard. This function is used by the
1616
// generated marshalling code.
1717
func Padding(l int) int {
@@ -28,12 +28,13 @@ func ElementSizeExceeded(field string, size, limit int) error {
2828
return fmt.Errorf("%s exceeds size limit; %d > %d", field, size, limit)
2929
}
3030

31-
type XDRSizer interface {
31+
// Sizer is a value that can return its XDR serialized size.
32+
type Sizer interface {
3233
XDRSize() int
3334
}
3435

3536
// SizeOfSlice returns the XDR encoded size of the given []T. Supported types
36-
// for T are string, []byte and types implementing XDRSizer. SizeOfSlice
37+
// for T are string, []byte and types implementing Sizer. SizeOfSlice
3738
// panics if the parameter is not a slice or if T is not one of the supported
3839
// types. This function is used by the generated marshalling code.
3940
func SizeOfSlice(ss interface{}) int {
@@ -52,7 +53,7 @@ func SizeOfSlice(ss interface{}) int {
5253
default:
5354
v := reflect.ValueOf(ss)
5455
for i := 0; i < v.Len(); i++ {
55-
l += v.Index(i).Interface().(XDRSizer).XDRSize()
56+
l += v.Index(i).Interface().(Sizer).XDRSize()
5657
}
5758
}
5859

marshaller.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package xdr
66

77
import "io"
88

9-
// The Marshaller is a thin wrapper around a byte buffer. The buffer must be
9+
// Marshaller is a thin wrapper around a byte buffer. The buffer must be
1010
// of sufficient size to hold the complete marshalled object, or an
1111
// io.ErrShortBuffer error will result. The Marshal... methods don't
1212
// individually return an error - the intention is that multiple fields are
@@ -50,7 +50,7 @@ func (m *Marshaller) MarshalString(s string) {
5050
m.offset += copy(m.Data[m.offset:], padBytes[:Padding(len(s))])
5151
}
5252

53-
// MarshalString appends the bytes to the buffer, with a size prefix and
53+
// MarshalBytes appends the bytes to the buffer, with a size prefix and
5454
// correct padding.
5555
func (m *Marshaller) MarshalBytes(bs []byte) {
5656
if m.Error != nil {
@@ -66,7 +66,7 @@ func (m *Marshaller) MarshalBytes(bs []byte) {
6666
m.offset += copy(m.Data[m.offset:], padBytes[:Padding(len(bs))])
6767
}
6868

69-
// MarshalString appends the bool to the buffer, as an uint32.
69+
// MarshalBool appends the bool to the buffer, as an uint32.
7070
func (m *Marshaller) MarshalBool(v bool) {
7171
if v {
7272
m.MarshalUint8(1)
@@ -75,17 +75,17 @@ func (m *Marshaller) MarshalBool(v bool) {
7575
}
7676
}
7777

78-
// MarshalString appends the uint8 to the buffer, as an uint32.
78+
// MarshalUint8 appends the uint8 to the buffer, as an uint32.
7979
func (m *Marshaller) MarshalUint8(v uint8) {
8080
m.MarshalUint32(uint32(v))
8181
}
8282

83-
// MarshalString appends the uint16 to the buffer, as an uint32.
83+
// MarshalUint16 appends the uint16 to the buffer, as an uint32.
8484
func (m *Marshaller) MarshalUint16(v uint16) {
8585
m.MarshalUint32(uint32(v))
8686
}
8787

88-
// MarshalString appends the uint32 to the buffer.
88+
// MarshalUint32 appends the uint32 to the buffer.
8989
func (m *Marshaller) MarshalUint32(v uint32) {
9090
if m.Error != nil {
9191
return
@@ -102,7 +102,7 @@ func (m *Marshaller) MarshalUint32(v uint32) {
102102
m.offset += 4
103103
}
104104

105-
// MarshalString appends the uint64 to the buffer.
105+
// MarshalUint64 appends the uint64 to the buffer.
106106
func (m *Marshaller) MarshalUint64(v uint64) {
107107
if m.Error != nil {
108108
return

unmarshal.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ package xdr
66

77
import "io"
88

9+
// Unmarshaller is a thin wrapper around a byte buffer. The Unmarshal... methods
10+
// don't individually return an error - the intention is that multiple fields are
11+
// unmarshalled in rapid succession, followed by a check of the Error field on
12+
// the Unmarshaller.
913
type Unmarshaller struct {
1014
Error error
1115
Data []byte
1216
}
1317

18+
// UnmarshalRaw returns a byte slice of length l from the buffer,
19+
// without a size prefix or padding. This is suitable for retrieving
20+
// data already in XDR format.
1421
func (u *Unmarshaller) UnmarshalRaw(l int) []byte {
1522
if u.Error != nil {
1623
return nil
@@ -26,10 +33,12 @@ func (u *Unmarshaller) UnmarshalRaw(l int) []byte {
2633
return v
2734
}
2835

36+
// UnmarshalString returns a string from the buffer.
2937
func (u *Unmarshaller) UnmarshalString() string {
3038
return u.UnmarshalStringMax(0)
3139
}
3240

41+
// UnmarshalStringMax returns a string up to a max length from the buffer.
3342
func (u *Unmarshaller) UnmarshalStringMax(max int) string {
3443
buf := u.UnmarshalBytesMax(max)
3544
if len(buf) == 0 || u.Error != nil {
@@ -39,10 +48,12 @@ func (u *Unmarshaller) UnmarshalStringMax(max int) string {
3948
return string(buf)
4049
}
4150

51+
// UnmarshalBytes returns a byte slice from the buffer.
4252
func (u *Unmarshaller) UnmarshalBytes() []byte {
4353
return u.UnmarshalBytesMax(0)
4454
}
4555

56+
// UnmarshalBytesMax returns a byte slice up to a max length from the buffer.
4657
func (u *Unmarshaller) UnmarshalBytesMax(max int) []byte {
4758
if u.Error != nil {
4859
return nil
@@ -73,10 +84,12 @@ func (u *Unmarshaller) UnmarshalBytesMax(max int) []byte {
7384
return v
7485
}
7586

87+
// UnmarshalBool returns a bool from the buffer.
7688
func (u *Unmarshaller) UnmarshalBool() bool {
7789
return u.UnmarshalUint8() != 0
7890
}
7991

92+
// UnmarshalUint8 returns a uint8 from the buffer.
8093
func (u *Unmarshaller) UnmarshalUint8() uint8 {
8194
if u.Error != nil {
8295
return 0
@@ -92,6 +105,7 @@ func (u *Unmarshaller) UnmarshalUint8() uint8 {
92105
return v
93106
}
94107

108+
// UnmarshalUint16 returns a uint16 from the buffer.
95109
func (u *Unmarshaller) UnmarshalUint16() uint16 {
96110
if u.Error != nil {
97111
return 0
@@ -107,6 +121,7 @@ func (u *Unmarshaller) UnmarshalUint16() uint16 {
107121
return v
108122
}
109123

124+
// UnmarshalUint32 returns a uint32 from the buffer.
110125
func (u *Unmarshaller) UnmarshalUint32() uint32 {
111126
if u.Error != nil {
112127
return 0
@@ -122,6 +137,7 @@ func (u *Unmarshaller) UnmarshalUint32() uint32 {
122137
return v
123138
}
124139

140+
// UnmarshalUint64 returns a uint64 from the buffer.
125141
func (u *Unmarshaller) UnmarshalUint64() uint64 {
126142
if u.Error != nil {
127143
return 0

0 commit comments

Comments
 (0)