func ReplyErrorAndArgs(errcode int32, args ...interface{}) *rpc.Message { msg := rpc.NewMessage(rpc.MAX_BUF_LEN) if errcode > 0 { sr := util.NewStoreArchiver(msg.Header) sr.Write(int8(1)) sr.Write(errcode) msg.Header = msg.Header[:sr.Len()] } if len(args) > 0 { mw := NewMessageWriter(msg) for i := 0; i < len(args); i++ { err := mw.Write(args[i]) if err != nil { msg.Free() panic("write args failed") return nil } } mw.Flush() } return msg }
func (obj *BaseScene) Serial() ([]byte, error) { ar := util.NewStoreArchiver(nil) ps := obj.GetVisiblePropertys(0) ar.Write(int16(len(ps))) return ar.Data(), nil }
//序列化 func (rec *GlobalDataTestRec) Serial() ([]byte, error) { ar := util.NewStoreArchiver(nil) for _, v := range rec.Rows { ar.WriteString(v.ID) ar.Write(v.Flag) } return ar.Data(), nil }
//序列化一行 func (rec *GlobalDataTestRec) SerialRow(row int) ([]byte, error) { if row < 0 || row >= len(rec.Rows) { return nil, ErrRowError } ar := util.NewStoreArchiver(nil) v := rec.Rows[row] ar.WriteString(v.ID) ar.Write(v.Flag) return ar.Data(), nil }
func (ps *PBPropCodec) Update(index int16, value interface{}, self bool, objid ObjectID) interface{} { update := &s2c.UpdateProperty{} update.Self = proto.Bool(self) update.Index = proto.Int32(objid.Index) update.Serial = proto.Int32(objid.Serial) ar := util.NewStoreArchiver(nil) ar.Write(index) ar.Write(value) update.Propinfo = ar.Data() return update }
//错误消息 func ReplyErrorMessage(errcode int32) *rpc.Message { msg := rpc.NewMessage(1) if errcode == 0 { return msg } sr := util.NewStoreArchiver(msg.Header) sr.Write(int8(1)) sr.Write(errcode) msg.Header = msg.Header[:sr.Len()] return msg }
func (ts *PBTableCodec) RecModify(rec datatype.Recorder, row, col int) interface{} { out := &s2c.RecordGrid{} out.Record = proto.String(rec.GetName()) out.Row = proto.Int32(int32(row)) out.Col = proto.Int32(int32(col)) value, _ := rec.Get(row, col) ar := util.NewStoreArchiver(nil) ar.Write(value) out.Gridinfo = ar.Data() return out }
func AppendArgs(msg *rpc.Message, args ...interface{}) { w := &BodyWriter{util.NewStoreArchiver(msg.Body), msg} if len(args) > 0 { for i := 0; i < len(args); i++ { err := w.Write(args[i]) if err != nil { msg.Free() panic("write args failed") } } w.Flush() } }
func (obj *Item) Serial() ([]byte, error) { ar := util.NewStoreArchiver(nil) ps := obj.GetVisiblePropertys(0) ar.Write(int16(len(ps))) ar.Write(int16(0)) ar.Write(obj.ID) ar.Write(int16(1)) ar.Write(obj.Time) ar.Write(int16(2)) ar.Write(obj.Amount) return ar.Data(), nil }
func (obj *GlobalData) Serial() ([]byte, error) { ar := util.NewStoreArchiver(nil) ps := obj.GetVisiblePropertys(0) ar.Write(int16(len(ps))) ar.Write(int16(0)) ar.Write(obj.Name) ar.Write(int16(1)) ar.Write(obj.Test1) ar.Write(int16(2)) ar.Write(obj.Test2) return ar.Data(), nil }
func (obj *BaseScene) SerialModify() ([]byte, error) { if len(obj.Mmodify) == 0 { return nil, nil } ar := util.NewStoreArchiver(nil) ar.Write(int16(len(obj.Mmodify))) for k, v := range obj.Mmodify { if !obj.PropertyIsPrivate(k) { continue } idx, _ := obj.GetPropertyIndex(k) ar.Write(int16(idx)) ar.Write(v) } return ar.Data(), nil }
func (c *byteClientCodec) WriteRequest(sending *sync.Mutex, seq uint64, call *Call) (err error) { sending.Lock() defer sending.Unlock() msg := call.Args msg.Header = msg.Header[:0] w := util.NewStoreArchiver(msg.Header) w.Write(seq) w.Write(call.mb.Uid) w.WriteString(call.ServiceMethod) msg.Header = msg.Header[:w.Len()] count := uint16(len(msg.Header) + len(msg.Body)) binary.Write(c.encBuf, binary.BigEndian, count) //数据大小 binary.Write(c.encBuf, binary.BigEndian, uint16(len(msg.Header))) //头部大小 c.encBuf.Write(msg.Header) if len(msg.Body) > 0 { c.encBuf.Write(msg.Body) } msg.Header = msg.Header[:0] return c.encBuf.Flush() }
func (client *Client) CallBack(serviceMethod string, src Mailbox, reply ReplyCB, args ...interface{}) error { var msg *Message if len(args) > 0 { msg = NewMessage(MAX_BUF_LEN) ar := util.NewStoreArchiver(msg.Body) for i := 0; i < len(args); i++ { err := ar.Write(args[i]) if err != nil { msg.Free() return err } } msg.Body = msg.Body[:ar.Len()] } err := client.CallMessageBack(serviceMethod, src, msg, reply) if msg != nil { msg.Free() } return err }
func NewHeadWriter(msg *rpc.Message) *HeadWriter { msg.Header = msg.Header[:0] w := &HeadWriter{util.NewStoreArchiver(msg.Header), msg} return w }
func NewMessage() *BodyWriter { msg := rpc.NewMessage(rpc.MAX_BUF_LEN) w := &BodyWriter{util.NewStoreArchiver(msg.Body), msg} return w }
func NewMessageWriter(msg *rpc.Message) *BodyWriter { msg.Body = msg.Body[:0] w := &BodyWriter{util.NewStoreArchiver(msg.Body), msg} return w }