unsafeheader.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2020 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 unsafeheader contains header declarations for the Go runtime's slice
  5. // and string implementations.
  6. //
  7. // This package allows packages that cannot import "reflect" to use types that
  8. // are tested to be equivalent to reflect.SliceHeader and reflect.StringHeader.
  9. package unsafeheader
  10. import (
  11. "unsafe"
  12. )
  13. // Slice is the runtime representation of a slice.
  14. // It cannot be used safely or portably and its representation may
  15. // change in a later release.
  16. //
  17. // Unlike reflect.SliceHeader, its Data field is sufficient to guarantee the
  18. // data it references will not be garbage collected.
  19. type Slice struct {
  20. Data unsafe.Pointer
  21. Len int
  22. Cap int
  23. }
  24. // String is the runtime representation of a string.
  25. // It cannot be used safely or portably and its representation may
  26. // change in a later release.
  27. //
  28. // Unlike reflect.StringHeader, its Data field is sufficient to guarantee the
  29. // data it references will not be garbage collected.
  30. type String struct {
  31. Data unsafe.Pointer
  32. Len int
  33. }