Refactoring ber encoding/decoding to simplify the interface