@@ -54,37 +54,30 @@ func (e ExtensionTypeError) Error() string {
5454 return fmt .Sprintf ("msgp: error decoding extension: wanted type %d; got type %d" , e .Want , e .Got )
5555}
5656
57- // Resumable returns ' true' for ExtensionTypeErrors
57+ // Resumable returns true for ExtensionTypeErrors.
5858func (e ExtensionTypeError ) Resumable () bool { return true }
5959
6060func errExt (got int8 , wanted int8 ) error {
6161 return ExtensionTypeError {Got : got , Want : wanted }
6262}
6363
64- // Extension is the interface fulfilled
65- // by types that want to define their
66- // own binary encoding.
64+ // Extension is the interface implemented by types that want to define their own binary encoding.
6765type Extension interface {
68- // ExtensionType should return
69- // a int8 that identifies the concrete
70- // type of the extension. (Types <0 are
71- // officially reserved by the MessagePack
72- // specifications.)
66+ // ExtensionType returns an int8 that identifies the extension's concrete type.
67+ // (Types <0 are reserved by the MessagePack specification.)
7368 ExtensionType () int8
7469
75- // Len should return the length
76- // of the data to be encoded
70+ // Len returns the length of the data to be encoded.
7771 Len () int
7872
79- // MarshalBinaryTo should copy
80- // the data into the supplied slice,
81- // assuming that the slice has length Len()
73+ // MarshalBinaryTo copies the data into the supplied slice, assuming that the
74+ // slice has length Len().
8275 MarshalBinaryTo ([]byte ) error
8376
8477 UnmarshalBinary ([]byte ) error
8578}
8679
87- // RawExtension implements the Extension interface
80+ // RawExtension implements the Extension interface.
8881type RawExtension struct {
8982 Data []byte
9083 Type int8
@@ -93,18 +86,17 @@ type RawExtension struct {
9386// ExtensionType implements Extension.ExtensionType, and returns r.Type
9487func (r * RawExtension ) ExtensionType () int8 { return r .Type }
9588
96- // Len implements Extension.Len, and returns len(r.Data)
89+ // Len implements Extension.Len.
9790func (r * RawExtension ) Len () int { return len (r .Data ) }
9891
99- // MarshalBinaryTo implements Extension.MarshalBinaryTo,
100- // and returns a copy of r.Data
92+ // MarshalBinaryTo implements Extension.MarshalBinaryTo and returns a copy of r.Data.
10193func (r * RawExtension ) MarshalBinaryTo (d []byte ) error {
10294 copy (d , r .Data )
10395 return nil
10496}
10597
106- // UnmarshalBinary implements Extension.UnmarshalBinary,
107- // and sets r.Data to the contents of the provided slice
98+ // UnmarshalBinary implements Extension.UnmarshalBinary and sets r.Data to the contents
99+ // of the provided slice.
108100func (r * RawExtension ) UnmarshalBinary (b []byte ) error {
109101 if cap (r .Data ) >= len (b ) {
110102 r .Data = r .Data [0 :len (b )]
@@ -115,7 +107,7 @@ func (r *RawExtension) UnmarshalBinary(b []byte) error {
115107 return nil
116108}
117109
118- // WriteExtension writes an extension type to the writer
110+ // WriteExtension writes an extension type to the writer.
119111func (mw * Writer ) WriteExtension (e Extension ) error {
120112 l := e .Len ()
121113 var err error
@@ -218,8 +210,7 @@ func (mw *Writer) WriteExtension(e Extension) error {
218210 return nil
219211}
220212
221- // peek at the extension type, assuming the next
222- // kind to be read is Extension
213+ // peek at the extension type, assuming the next kind to be read is Extension.
223214func (m * Reader ) peekExtensionType () (int8 , error ) {
224215 p , err := m .R .Peek (2 )
225216 if err != nil {
@@ -262,19 +253,16 @@ func peekExtension(b []byte) (int8, error) {
262253 return int8 (b [size - 1 ]), nil
263254}
264255
265- // ReadExtension reads the next object from the reader
266- // as an extension. ReadExtension will fail if the next
267- // object in the stream is not an extension, or if
268- // e.Type() is not the same as the wire type.
256+ // ReadExtension reads the next object from the reader as an extension. ReadExtension will fail if
257+ // the next object in the stream is not an extension, or if e.Type() is not the same as the wire type.
269258func (m * Reader ) ReadExtension (e Extension ) (err error ) {
270- var p [] byte
271- p , err = m .R .Peek (2 )
259+
260+ p , err : = m .R .Peek (2 )
272261 if err != nil {
273262 return
274263 }
275264 lead := p [0 ]
276- var read int
277- var off int
265+ var read , off int
278266 switch lead {
279267 case mfixext1 :
280268 if int8 (p [1 ]) != e .ExtensionType () {
0 commit comments