Added codec.MustMarshalToBytes/MustUnmarshalToBytes method.
@@ -30,6 +30,14 @@ func UnmarshalFromBytes(b []byte, v interface{}) ([]byte, error) {
return codec.UnmarshalFromBytes(b, v)
}
+func MustMarshalToBytes(v interface{}) []byte {
+ return codec.MustMarshalToBytes(v)
+}
+
+func MustUnmarshalFromBytes(b []byte, v interface{}) []byte {
+ return codec.MustUnmarshalFromBytes(b, v)
+}
+
type bytesWrapper struct {
Codec
}
@@ -49,3 +57,23 @@ func (c *bytesWrapper) UnmarshalFromBytes(b []byte, v interface{}) ([]byte, erro
}
return buf.Bytes(), nil
}
+
+func (c *bytesWrapper) MustMarshalToBytes(v interface{}) []byte {
+ bs, err := MarshalToBytes(v)
+ if err != nil {
+ panic(err)
+ return nil
+ } else {
+ return bs
+ }
+}
+
+func (c *bytesWrapper) MustUnmarshalFromBytes(b []byte, v interface{}) []byte {
+ bs, err := UnmarshalFromBytes(b, v)
+ if err != nil {
+ panic(err)
+ return nil
+ } else {
+ return bs
+ }
+}
