示例#1
0
func (conn *ProtoBufConn) GetRequestBody(req *protobuf.Packet, body interface{}) error {
	if value, ok := body.(proto.Message); ok {
		return proto.Unmarshal(req.GetSerializedPacket(), value)
	}

	return fmt.Errorf("GetRequestBody value type error %v", body)
}
示例#2
0
func (conn *ProtoBufConn) ReadRequest(req *protobuf.Packet) error {

	conn.c.SetReadDeadline(time.Now().Add(ConnReadTimeOut))

	dst, err := conn.c.ReadMessage()
	if err != nil {
		logger.Debug("ReadRequest Read binary Err: %v", err)
		return err
	}

	//dst, err := snappy.Decode(nil, dstBuffer.Bytes())

	if err != nil {
		logger.Debug("ReadRequest Decode Err: %v", err)
		return err
	}

	conn.last_time = time.Now().Unix()

	//logger.Info("ReadRequest dst: %v", dst)

	err = proto.Unmarshal(dst, req)
	conn.msg_id = req.GetId()
	return err
}
示例#3
0
func (conn *ProtoBufConn) writeRequest(r *protobuf.Packet) error {
	r.SetId(conn.msg_id)
	conn.send <- r
	return nil
}