0 Star 0 Fork 12

wulugeng/hprose-go

forked from Hprose/hprose-go 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
class_manager.go 2.38 KB
一键复制 编辑 原始数据 按行查看 历史
Hprose 提交于 2015-06-26 18:16 . Changed Mutex to RWMutex
/**********************************************************\
| |
| hprose |
| |
| Official WebSite: http://www.hprose.com/ |
| http://www.hprose.org/ |
| |
\**********************************************************/
/**********************************************************\
* *
* hprose/class_manager.go *
* *
* hprose ClassManager for Go. *
* *
* LastModified: Jun 26, 2015 *
* Author: Ma Bingyao <andot@hprose.com> *
* *
\**********************************************************/
package hprose
import (
"reflect"
"sync"
)
type classManager struct {
classCache map[string]reflect.Type
aliasCache map[reflect.Type]string
tagCache map[reflect.Type]string
mutex sync.RWMutex
}
// Register class with alias.
func (cm *classManager) Register(class reflect.Type, alias string, tag ...string) {
cm.mutex.Lock()
cm.classCache[alias] = class
cm.aliasCache[class] = alias
if len(tag) == 1 {
cm.tagCache[class] = tag[0]
}
cm.mutex.Unlock()
}
// GetClassAlias by class.
func (cm *classManager) GetClassAlias(class reflect.Type) (alias string) {
cm.mutex.RLock()
alias = cm.aliasCache[class]
cm.mutex.RUnlock()
return alias
}
// GetClass by alias.
func (cm *classManager) GetClass(alias string) (class reflect.Type) {
cm.mutex.RLock()
class = cm.classCache[alias]
cm.mutex.RUnlock()
return class
}
// GetTag by class.
func (cm *classManager) GetTag(class reflect.Type) (tag string) {
cm.mutex.RLock()
tag = cm.tagCache[class]
cm.mutex.RUnlock()
return tag
}
func initClassManager() *classManager {
cm := new(classManager)
cm.classCache = make(map[string]reflect.Type)
cm.aliasCache = make(map[reflect.Type]string)
cm.tagCache = make(map[reflect.Type]string)
return cm
}
// ClassManager used to be register class with alias for hprose serialize/unserialize.
var ClassManager = initClassManager()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wulugeng/hprose-go.git
git@gitee.com:wulugeng/hprose-go.git
wulugeng
hprose-go
hprose-go
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385