messagebody.go 824 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2012 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package icmp
  5. // A MessageBody represents an ICMP message body.
  6. type MessageBody interface {
  7. // Len returns the length of ICMP message body.
  8. Len() int
  9. // Marshal returns the binary enconding of ICMP message body.
  10. Marshal() ([]byte, error)
  11. }
  12. // A DefaultMessageBody represents the default message body.
  13. type DefaultMessageBody struct {
  14. Data []byte // data
  15. }
  16. // Len implements the Len method of MessageBody interface.
  17. func (p *DefaultMessageBody) Len() int {
  18. if p == nil {
  19. return 0
  20. }
  21. return len(p.Data)
  22. }
  23. // Marshal implements the Marshal method of MessageBody interface.
  24. func (p *DefaultMessageBody) Marshal() ([]byte, error) {
  25. return p.Data, nil
  26. }