options.go 366 B

123456789101112131415161718192021222324
  1. package udp
  2. import (
  3. "math"
  4. )
  5. type Options struct {
  6. RequestUri string
  7. }
  8. func (opts Options) Encode() (ret []byte) {
  9. for {
  10. l := len(opts.RequestUri)
  11. if l == 0 {
  12. break
  13. }
  14. if l > math.MaxUint8 {
  15. l = math.MaxUint8
  16. }
  17. ret = append(append(ret, optionTypeURLData, byte(l)), opts.RequestUri[:l]...)
  18. opts.RequestUri = opts.RequestUri[l:]
  19. }
  20. return
  21. }