Exemple #1
0
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
}
Exemple #2
0
func (obj *BaseScene) Serial() ([]byte, error) {
	ar := util.NewStoreArchiver(nil)
	ps := obj.GetVisiblePropertys(0)
	ar.Write(int16(len(ps)))

	return ar.Data(), nil
}
Exemple #3
0
//序列化
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
}
Exemple #4
0
//序列化一行
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
}
Exemple #5
0
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
}
Exemple #6
0
//错误消息
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
}
Exemple #7
0
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
}
Exemple #8
0
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()
	}
}
Exemple #9
0
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
}
Exemple #10
0
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
}
Exemple #11
0
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
}
Exemple #12
0
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()
}
Exemple #13
0
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
}
Exemple #14
0
func NewHeadWriter(msg *rpc.Message) *HeadWriter {
	msg.Header = msg.Header[:0]
	w := &HeadWriter{util.NewStoreArchiver(msg.Header), msg}
	return w
}
Exemple #15
0
func NewMessage() *BodyWriter {
	msg := rpc.NewMessage(rpc.MAX_BUF_LEN)
	w := &BodyWriter{util.NewStoreArchiver(msg.Body), msg}
	return w
}
Exemple #16
0
func NewMessageWriter(msg *rpc.Message) *BodyWriter {
	msg.Body = msg.Body[:0]
	w := &BodyWriter{util.NewStoreArchiver(msg.Body), msg}
	return w
}