14 Star 51 Fork 12

Hprose/hprose-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
class_manager.go 2.37 KB
一键复制 编辑 原始数据 按行查看 历史
Hprose 提交于 2015-05-25 22:03 . Changed directory
/**********************************************************\
| |
| hprose |
| |
| Official WebSite: http://www.hprose.com/ |
| http://www.hprose.org/ |
| |
\**********************************************************/
/**********************************************************\
* *
* hprose/class_manager.go *
* *
* hprose ClassManager for Go. *
* *
* LastModified: May 24, 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.Mutex
}
// 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.Lock()
alias = cm.aliasCache[class]
cm.mutex.Unlock()
return alias
}
// GetClass by alias.
func (cm *classManager) GetClass(alias string) (class reflect.Type) {
cm.mutex.Lock()
class = cm.classCache[alias]
cm.mutex.Unlock()
return class
}
// GetTag by class.
func (cm *classManager) GetTag(class reflect.Type) (tag string) {
cm.mutex.Lock()
tag = cm.tagCache[class]
cm.mutex.Unlock()
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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/andot/hprose-go.git
git@gitee.com:andot/hprose-go.git
andot
hprose-go
hprose-go
v1.5.1

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385