| 1 | // Copyright 2018 fatedier, fatedier@gmail.com |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package msg |
| 16 | |
| 17 | import ( |
| 18 | "io" |
| 19 | |
| 20 | jsonMsg "github.com/fatedier/golib/msg/json" |
| 21 | ) |
| 22 | |
| 23 | type Message = jsonMsg.Message |
| 24 | |
| 25 | var msgCtl *jsonMsg.MsgCtl |
| 26 | |
| 27 | func init() { |
| 28 | msgCtl = jsonMsg.NewMsgCtl() |
| 29 | for typeByte, msg := range msgTypeMap { |
| 30 | msgCtl.RegisterMsg(typeByte, msg) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | func ReadMsg(c io.Reader) (msg Message, err error) { |
| 35 | return msgCtl.ReadMsg(c) |
| 36 | } |
| 37 | |
| 38 | func ReadMsgInto(c io.Reader, msg Message) (err error) { |
| 39 | return msgCtl.ReadMsgInto(c, msg) |
| 40 | } |
| 41 | |
| 42 | func WriteMsg(c io.Writer, msg any) (err error) { |
| 43 | return msgCtl.WriteMsg(c, msg) |
| 44 | } |