@@ -75,7 +75,7 @@ func setPath(options Options, optionID OptionID, buf []byte, path string) (Optio
75
75
76
76
// SetPath splits path by '/' to URIPath options and copies it to buffer.
77
77
//
78
- // Return's modified options, number of used buf bytes and error if occurs.
78
+ // Returns modified options, number of used buf bytes and error if occurs.
79
79
//
80
80
// @note the url encoded into URIHost, URIPort, URIPath is expected to be
81
81
// absolute (https://www.rfc-editor.org/rfc/rfc7252.txt)
@@ -85,7 +85,7 @@ func (options Options) SetPath(buf []byte, path string) (Options, int, error) {
85
85
86
86
// SetLocationPath splits path by '/' to LocationPath options and copies it to buffer.
87
87
//
88
- // Return's modified options, number of used buf bytes and error if occurs.
88
+ // Returns modified options, number of used buf bytes and error if occurs.
89
89
//
90
90
// @note the url encoded into LocationPath is expected to be
91
91
// absolute (https://www.rfc-editor.org/rfc/rfc7252.txt)
@@ -119,7 +119,7 @@ func (options Options) path(buf []byte, id OptionID) (int, error) {
119
119
120
120
// Path joins URIPath options by '/' to the buf.
121
121
//
122
- // Return's number of used buf bytes or error when occurs.
122
+ // Returns number of used buf bytes or error when occurs.
123
123
func (options Options ) Path () (string , error ) {
124
124
buf := make ([]byte , 32 )
125
125
m , err := options .path (buf , URIPath )
@@ -136,7 +136,7 @@ func (options Options) Path() (string, error) {
136
136
137
137
// LocationPath joins Location-Path options by '/' to the buf.
138
138
//
139
- // Return's number of used buf bytes or error when occurs.
139
+ // Returns number of used buf bytes or error when occurs.
140
140
func (options Options ) LocationPath () (string , error ) {
141
141
buf := make ([]byte , 32 )
142
142
m , err := options .path (buf , LocationPath )
@@ -151,29 +151,29 @@ func (options Options) LocationPath() (string, error) {
151
151
return string (buf ), nil
152
152
}
153
153
154
- // SetString replace's/store's string option to options.
154
+ // SetString replaces/stores string option to options.
155
155
//
156
- // Return's modified options, number of used buf bytes and error if occurs.
156
+ // Returns modified options, number of used buf bytes and error if occurs.
157
157
func (options Options ) SetString (buf []byte , id OptionID , str string ) (Options , int , error ) {
158
158
data := []byte (str )
159
159
return options .SetBytes (buf , id , data )
160
160
}
161
161
162
- // AddString append's string option to options.
162
+ // AddString appends string option to options.
163
163
//
164
- // Return's modified options, number of used buf bytes and error if occurs.
164
+ // Returns modified options, number of used buf bytes and error if occurs.
165
165
func (options Options ) AddString (buf []byte , id OptionID , str string ) (Options , int , error ) {
166
166
data := []byte (str )
167
167
return options .AddBytes (buf , id , data )
168
168
}
169
169
170
- // HasOption return's true is option exist in options.
170
+ // HasOption returns true is option exist in options.
171
171
func (options Options ) HasOption (id OptionID ) bool {
172
172
_ , _ , err := options .Find (id )
173
173
return err == nil
174
174
}
175
175
176
- // GetUint32s get's all options with same id.
176
+ // GetUint32s gets all options with same id.
177
177
func (options Options ) GetUint32s (id OptionID , r []uint32 ) (int , error ) {
178
178
firstIdx , lastIdx , err := options .Find (id )
179
179
if err != nil {
@@ -194,7 +194,7 @@ func (options Options) GetUint32s(id OptionID, r []uint32) (int, error) {
194
194
return idx , nil
195
195
}
196
196
197
- // GetUint32 get's first option with id of type uint32 .
197
+ // GetUint32 gets the uin32 value of the first option with the given ID .
198
198
func (options Options ) GetUint32 (id OptionID ) (uint32 , error ) {
199
199
firstIdx , _ , err := options .Find (id )
200
200
if err != nil {
@@ -204,13 +204,13 @@ func (options Options) GetUint32(id OptionID) (uint32, error) {
204
204
return val , err
205
205
}
206
206
207
- // ContentFormat get's content format of body.
207
+ // ContentFormat gets the content format of body.
208
208
func (options Options ) ContentFormat () (MediaType , error ) {
209
209
v , err := options .GetUint32 (ContentFormat )
210
210
return MediaType (v ), err
211
211
}
212
212
213
- // GetString get's first option with id of type string .
213
+ // GetString gets the string value of the first option with the given ID .
214
214
func (options Options ) GetString (id OptionID ) (string , error ) {
215
215
firstIdx , _ , err := options .Find (id )
216
216
if err != nil {
@@ -219,9 +219,41 @@ func (options Options) GetString(id OptionID) (string, error) {
219
219
return string (options [firstIdx ].Value ), nil
220
220
}
221
221
222
- // SetBytes replace's/store's byte's option to options.
222
+ // GetStrings gets string array of all options with the given id.
223
+ func (options Options ) GetStrings (id OptionID , r []string ) (int , error ) {
224
+ firstIdx , lastIdx , err := options .Find (id )
225
+ if err != nil {
226
+ return 0 , err
227
+ }
228
+ if len (r ) < lastIdx - firstIdx {
229
+ return lastIdx - firstIdx , ErrTooSmall
230
+ }
231
+ var idx int
232
+ for i := firstIdx ; i < lastIdx ; i ++ {
233
+ r [idx ] = string (options [i ].Value )
234
+ idx ++
235
+ }
236
+
237
+ return idx , nil
238
+ }
239
+
240
+ // Queries gets URIQuery parameters.
241
+ func (options Options ) Queries () ([]string , error ) {
242
+ q := make ([]string , 4 )
243
+ n , err := options .GetStrings (URIQuery , q )
244
+ if errors .Is (err , ErrTooSmall ) {
245
+ q = append (q , make ([]string , n - len (q ))... )
246
+ n , err = options .GetStrings (URIQuery , q )
247
+ }
248
+ if err != nil {
249
+ return nil , err
250
+ }
251
+ return q [:n ], nil
252
+ }
253
+
254
+ // SetBytes replaces/stores bytes of a option to options.
223
255
//
224
- // Return's modified options, number of used buf bytes and error if occurs.
256
+ // Returns modified options, number of used buf bytes and error if occurs.
225
257
func (options Options ) SetBytes (buf []byte , id OptionID , data []byte ) (Options , int , error ) {
226
258
if len (buf ) < len (data ) {
227
259
return options , len (data ), ErrTooSmall
@@ -233,9 +265,9 @@ func (options Options) SetBytes(buf []byte, id OptionID, data []byte) (Options,
233
265
return options .Set (Option {ID : id , Value : buf [:len (data )]}), len (data ), nil
234
266
}
235
267
236
- // AddBytes append's byte's option to options.
268
+ // AddBytes appends bytes of a option option to options.
237
269
//
238
- // Return's modified options, number of used buf bytes and error if occurs.
270
+ // Returns modified options, number of used buf bytes and error if occurs.
239
271
func (options Options ) AddBytes (buf []byte , id OptionID , data []byte ) (Options , int , error ) {
240
272
if len (buf ) < len (data ) {
241
273
return options , len (data ), ErrTooSmall
@@ -247,7 +279,7 @@ func (options Options) AddBytes(buf []byte, id OptionID, data []byte) (Options,
247
279
return options .Add (Option {ID : id , Value : buf [:len (data )]}), len (data ), nil
248
280
}
249
281
250
- // GetBytes get's first option with id of type byte's .
282
+ // GetBytes gets bytes of the first option with given id .
251
283
func (options Options ) GetBytes (id OptionID ) ([]byte , error ) {
252
284
firstIdx , _ , err := options .Find (id )
253
285
if err != nil {
@@ -256,39 +288,7 @@ func (options Options) GetBytes(id OptionID) ([]byte, error) {
256
288
return options [firstIdx ].Value , nil
257
289
}
258
290
259
- // GetStrings get's all options with same id.
260
- func (options Options ) GetStrings (id OptionID , r []string ) (int , error ) {
261
- firstIdx , lastIdx , err := options .Find (id )
262
- if err != nil {
263
- return 0 , err
264
- }
265
- if len (r ) < lastIdx - firstIdx {
266
- return lastIdx - firstIdx , ErrTooSmall
267
- }
268
- var idx int
269
- for i := firstIdx ; i < lastIdx ; i ++ {
270
- r [idx ] = string (options [i ].Value )
271
- idx ++
272
- }
273
-
274
- return idx , nil
275
- }
276
-
277
- // Queries get's URIQuery parameters.
278
- func (options Options ) Queries () ([]string , error ) {
279
- q := make ([]string , 4 )
280
- n , err := options .GetStrings (URIQuery , q )
281
- if errors .Is (err , ErrTooSmall ) {
282
- q = append (q , make ([]string , n - len (q ))... )
283
- n , err = options .GetStrings (URIQuery , q )
284
- }
285
- if err != nil {
286
- return nil , err
287
- }
288
- return q [:n ], nil
289
- }
290
-
291
- // GetBytess get's all options with same id.
291
+ // GetBytess gets array of bytes of all options with the same id.
292
292
func (options Options ) GetBytess (id OptionID , r [][]byte ) (int , error ) {
293
293
firstIdx , lastIdx , err := options .Find (id )
294
294
if err != nil {
@@ -306,9 +306,9 @@ func (options Options) GetBytess(id OptionID, r [][]byte) (int, error) {
306
306
return idx , nil
307
307
}
308
308
309
- // AddUint32 append's uint32 option to options.
309
+ // AddUint32 appends uint32 option to options.
310
310
//
311
- // Return's modified options, number of used buf bytes and error if occurs.
311
+ // Returns modified options, number of used buf bytes and error if occurs.
312
312
func (options Options ) AddUint32 (buf []byte , id OptionID , value uint32 ) (Options , int , error ) {
313
313
enc , err := EncodeUint32 (buf , value )
314
314
if err != nil {
@@ -318,9 +318,9 @@ func (options Options) AddUint32(buf []byte, id OptionID, value uint32) (Options
318
318
return o , enc , err
319
319
}
320
320
321
- // SetUint32 replace's/store's uint32 option to options.
321
+ // SetUint32 replaces/stores uint32 option to options.
322
322
//
323
- // Return's modified options, number of used buf bytes and error if occurs.
323
+ // Returns modified options, number of used buf bytes and error if occurs.
324
324
func (options Options ) SetUint32 (buf []byte , id OptionID , value uint32 ) (Options , int , error ) {
325
325
enc , err := EncodeUint32 (buf , value )
326
326
if err != nil {
@@ -330,33 +330,33 @@ func (options Options) SetUint32(buf []byte, id OptionID, value uint32) (Options
330
330
return o , enc , err
331
331
}
332
332
333
- // SetContentFormat set's ContentFormat option.
333
+ // SetContentFormat sets ContentFormat option.
334
334
func (options Options ) SetContentFormat (buf []byte , contentFormat MediaType ) (Options , int , error ) {
335
335
return options .SetUint32 (buf , ContentFormat , uint32 (contentFormat ))
336
336
}
337
337
338
- // SetObserve set's ContentFormat option.
338
+ // SetObserve sets ContentFormat option.
339
339
func (options Options ) SetObserve (buf []byte , observe uint32 ) (Options , int , error ) {
340
340
return options .SetUint32 (buf , Observe , observe )
341
341
}
342
342
343
- // Observe get's observe option.
343
+ // Observe gets observe option.
344
344
func (options Options ) Observe () (uint32 , error ) {
345
345
return options .GetUint32 (Observe )
346
346
}
347
347
348
- // SetAccept set's accept option.
348
+ // SetAccept sets accept option.
349
349
func (options Options ) SetAccept (buf []byte , contentFormat MediaType ) (Options , int , error ) {
350
350
return options .SetUint32 (buf , Accept , uint32 (contentFormat ))
351
351
}
352
352
353
- // Accept get's accept option.
353
+ // Accept gets accept option.
354
354
func (options Options ) Accept () (MediaType , error ) {
355
355
v , err := options .GetUint32 (Accept )
356
356
return MediaType (v ), err
357
357
}
358
358
359
- // Find return's range of type options. First number is index and second number is index of next option type.
359
+ // Find returns range of type options. First number is index and second number is index of next option type.
360
360
func (options Options ) Find (ID OptionID ) (int , int , error ) {
361
361
idxPre , idxPost := options .findPosition (ID )
362
362
if idxPre == - 1 && idxPost == 0 {
@@ -404,9 +404,9 @@ func (options Options) findPosition(ID OptionID) (minIdx int, maxIdx int) {
404
404
}
405
405
}
406
406
407
- // Set replace's/store's option at options.
407
+ // Set replaces/stores option at options.
408
408
//
409
- // Return's modified options.
409
+ // Returns modified options.
410
410
func (options Options ) Set (opt Option ) Options {
411
411
idxPre , idxPost := options .findPosition (opt .ID )
412
412
if idxPre == - 1 && idxPost == - 1 {
@@ -463,7 +463,7 @@ func (options Options) Set(opt Option) Options {
463
463
return options
464
464
}
465
465
466
- // Add append's option to options.
466
+ // Add appends option to options.
467
467
func (options Options ) Add (opt Option ) Options {
468
468
_ , idxPost := options .findPosition (opt .ID )
469
469
if idxPost == - 1 {
@@ -481,7 +481,7 @@ func (options Options) Add(opt Option) Options {
481
481
return options
482
482
}
483
483
484
- // Remove remove's all options with ID.
484
+ // Remove removes all options with ID.
485
485
func (options Options ) Remove (ID OptionID ) Options {
486
486
idxPre , idxPost , err := options .Find (ID )
487
487
if err != nil {
@@ -498,9 +498,9 @@ func (options Options) Remove(ID OptionID) Options {
498
498
return options
499
499
}
500
500
501
- // Marshal marshal's options to buf.
501
+ // Marshal marshals options to buf.
502
502
//
503
- // Return's number of used buf byte's .
503
+ // Returns the number of used buf bytes .
504
504
func (options Options ) Marshal (buf []byte ) (int , error ) {
505
505
previousID := OptionID (0 )
506
506
length := 0
@@ -536,7 +536,7 @@ func (options Options) Marshal(buf []byte) (int, error) {
536
536
return length , nil
537
537
}
538
538
539
- // Unmarshal unmarshal's data bytes to options and returns number of consumned byte's .
539
+ // Unmarshal unmarshals data bytes to options and returns the number of consumed bytes .
540
540
func (options * Options ) Unmarshal (data []byte , optionDefs map [OptionID ]OptionDef ) (int , error ) {
541
541
prev := 0
542
542
processed := 0
@@ -595,9 +595,9 @@ func (options *Options) Unmarshal(data []byte, optionDefs map[OptionID]OptionDef
595
595
return processed , nil
596
596
}
597
597
598
- // ResetOptionsTo reset's options to in options.
598
+ // ResetOptionsTo resets options to in options.
599
599
//
600
- // Return's modified options, number of used buf bytes and error if occurs.
600
+ // Returns modified options, number of used buf bytes and error if occurs.
601
601
func (options Options ) ResetOptionsTo (buf []byte , in Options ) (Options , int , error ) {
602
602
opts := options [:0 ]
603
603
used := 0
0 commit comments