properties_gogo.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
  2. // http://github.com/gogo/protobuf/gogoproto
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. //
  15. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  18. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  19. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. package proto
  27. import (
  28. "fmt"
  29. "os"
  30. "reflect"
  31. )
  32. func (p *Properties) setCustomEncAndDec(typ reflect.Type) {
  33. p.ctype = typ
  34. if p.Repeated {
  35. p.enc = (*Buffer).enc_custom_slice_bytes
  36. p.dec = (*Buffer).dec_custom_slice_bytes
  37. p.size = size_custom_slice_bytes
  38. } else if typ.Kind() == reflect.Ptr {
  39. p.enc = (*Buffer).enc_custom_bytes
  40. p.dec = (*Buffer).dec_custom_bytes
  41. p.size = size_custom_bytes
  42. } else {
  43. p.enc = (*Buffer).enc_custom_ref_bytes
  44. p.dec = (*Buffer).dec_custom_ref_bytes
  45. p.size = size_custom_ref_bytes
  46. }
  47. }
  48. func (p *Properties) setSliceOfNonPointerStructs(typ reflect.Type) {
  49. t2 := typ.Elem()
  50. p.sstype = typ
  51. p.stype = t2
  52. p.isMarshaler = isMarshaler(t2)
  53. p.isUnmarshaler = isUnmarshaler(t2)
  54. p.enc = (*Buffer).enc_slice_ref_struct_message
  55. p.dec = (*Buffer).dec_slice_ref_struct_message
  56. p.size = size_slice_ref_struct_message
  57. if p.Wire != "bytes" {
  58. fmt.Fprintf(os.Stderr, "proto: no ptr oenc for %T -> %T \n", typ, t2)
  59. }
  60. }