PushObject is a helper function for Push that accepts any value type, which is then encoded into a byte slice using encoding/gob. Objects containing pointers with zero values will decode to nil when using this function. This is due to how the encoding/gob package works. Because of this, you should
(value interface{})
| 97 | // package works. Because of this, you should only use this function |
| 98 | // to encode simple types. |
| 99 | func (s *Stack) PushObject(value interface{}) (*Item, error) { |
| 100 | var buffer bytes.Buffer |
| 101 | enc := gob.NewEncoder(&buffer) |
| 102 | if err := enc.Encode(value); err != nil { |
| 103 | return nil, err |
| 104 | } |
| 105 | |
| 106 | return s.Push(buffer.Bytes()) |
| 107 | } |
| 108 | |
| 109 | // PushObjectAsJSON is a helper function for Push that accepts any |
| 110 | // value type, which is then encoded into a JSON byte slice using |