diff --git a/corim/entity_extension.go b/corim/entity_extension.go index 8afbd290..9966b046 100644 --- a/corim/entity_extension.go +++ b/corim/entity_extension.go @@ -13,35 +13,45 @@ type EntityExtension struct { Param2 byte `cbor:"1,keyasint,omitempty" json:"param2,omitempty"` } -func (e *EntityExtension) FromCBOR(data []byte) error { +type ProfileXEntity struct { + Entity + Extension EntityExtension `cbor:"8,keyasint" json:"extension"` +} - if err := dm.Unmarshal(data, e); err != nil { - return fmt.Errorf("Failed to unMarshal extension") - } - return nil +func NewProfileXEntity() *ProfileXEntity { + return &ProfileXEntity{} } -func (e *EntityExtension) ToCBOR() ([]byte, error) { - data, err := em.Marshal(e) - if err != nil { - return nil, fmt.Errorf("unable to CBOR Marshal extension") +func (e *ProfileXEntity) SetEntityExtension(p1 string, p2 byte) { + + e.Extension.Param1 = p1 + e.Extension.Param2 = p2 +} + +func (o *ProfileXEntity) FromCBOR(data []byte) error { + if err := o.Valid(); err != nil { + return fmt.Errorf("invalid Profile XEntity %w", err) } - fmt.Printf("ToCBOR a success") - return data, nil + return dm.Unmarshal(data, o) } -func (e *EntityExtension) ExtensionToJSON() ([]byte, error) { - data, err := json.Marshal(e) - if err != nil { - return nil, fmt.Errorf("unable to JSON Marshal extension") +func (o *ProfileXEntity) ToCBOR() ([]byte, error) { + if err := o.Valid(); err != nil { + return nil, fmt.Errorf("invalid Profile XEntity %w", err) } - return data, nil + return em.Marshal(o) } -func (e *EntityExtension) ExtensionFromJSON(data []byte) (interface{}, error) { +func (o *ProfileXEntity) FromJSON(data []byte) error { + if err := o.Valid(); err != nil { + return err + } + return json.Unmarshal(data, o) +} - if err := json.Unmarshal(data, e); err != nil { - return nil, fmt.Errorf("Failed to JSON UnMarshal extension") +func (o *ProfileXEntity) ToJSON() ([]byte, error) { + if err := o.Valid(); err != nil { + return nil, err } - return e, nil + return json.Marshal(o) }