lorenzodonini / ocpp-go

Open Charge Point Protocol implementation in Go
MIT License
277 stars 126 forks source link

StopReason should be a pointer since its optional #183

Closed yajan-singh closed 1 year ago

yajan-singh commented 1 year ago
image image
lorenzodonini commented 1 year ago

Reason is a string under the hood. Compared to integers and floats, empty strings aren't valid enum values and this allows to use a value type instead of a pointer type for achieving the same "optional" behavior.

When using the library and checking whether this field is set, it makes no difference whether you do:

However, having enum fields as value types has the following advantages:

  1. it's more efficient (every additional pointer needs to be gargabe-collected)
  2. no dereferencing is needed when accessing the value

The entire library is built on this foundation and changing it would mean changing many other enum fields across the codebase (see ChargingState in the same struct for example). I honestly don't plan on changing every single enum field to a pointer, unless this gets heavily upvoted and there is a good motivation.

lorenzodonini commented 1 year ago

Closing due to inactivity.