-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
150ade6
commit 9012aa0
Showing
3 changed files
with
30 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package pb | ||
|
||
import ( | ||
"google.golang.org/protobuf/encoding/protojson" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
func (m *WakuMessage) MarshalJSON() ([]byte, error) { | ||
return (protojson.MarshalOptions{}).Marshal(m) | ||
} | ||
|
||
func Unmarshal(data []byte) (*WakuMessage, error) { | ||
msg := &WakuMessage{} | ||
err := proto.Unmarshal(data, msg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = msg.Validate() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return msg, nil | ||
} | ||
|
||
func (m *WakuMessage) UnmarshalJSON(data []byte) error { | ||
return (protojson.UnmarshalOptions{}).Unmarshal(data, m) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters