代码拉取完成,页面将自动刷新
同步操作将从 Hprose/hprose-go 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/**********************************************************\
| |
| hprose |
| |
| Official WebSite: http://www.hprose.com/ |
| http://www.hprose.org/ |
| |
\**********************************************************/
/**********************************************************\
* *
* hprose/jsonrpc_client_filter.go *
* *
* jsonrpc client filter for Go. *
* *
* LastModified: May 22, 2015 *
* Author: Ma Bingyao <andot@hprose.com> *
* *
\**********************************************************/
package hprose
import (
"bytes"
"encoding/json"
)
var id = 1
// JSONRPCClientFilter is a JSONRPC Client Filter
type JSONRPCClientFilter struct {
Version string
}
// NewJSONRPCClientFilter is a constructor for JSONRPCClientFilter
func NewJSONRPCClientFilter(version string) JSONRPCClientFilter {
if version == "1.0" || version == "1.1" || version == "2.0" {
return JSONRPCClientFilter{Version: version}
}
panic("version must be 1.0, 1.1 or 2.0 in string format.")
}
// InputFilter for JSONRPC Client
func (filter JSONRPCClientFilter) InputFilter(data []byte, context Context) []byte {
var response map[string]interface{}
if err := json.Unmarshal(data, &response); err != nil {
return data
}
result := response["result"]
err := response["error"]
buf := new(bytes.Buffer)
writer := NewWriter(buf, true)
if err != nil {
e := err.(map[string]interface{})
buf.WriteByte(TagError)
writer.WriteString(e["message"].(string))
} else {
buf.WriteByte(TagResult)
writer.Serialize(result)
}
buf.WriteByte(TagEnd)
data = buf.Bytes()
return data
}
// OutputFilter for JSONRPC Client
func (filter JSONRPCClientFilter) OutputFilter(data []byte, context Context) []byte {
request := make(map[string]interface{})
if filter.Version == "1.1" {
request["version"] = "1.1"
} else if filter.Version == "2.0" {
request["jsonrpc"] = "2.0"
}
istream := NewBytesReader(data)
reader := NewReader(istream, false)
reader.JSONCompatible = true
tag, _ := istream.ReadByte()
if tag == TagCall {
request["method"], _ = reader.ReadString()
tag, _ = istream.ReadByte()
if tag == TagList {
reader.Reset()
if count, err := reader.ReadInteger(TagOpenbrace); err == nil {
params := make([]interface{}, count)
for i := 0; i < count; i++ {
reader.Unserialize(¶ms[i])
}
request["params"] = params
}
}
}
request["id"] = id
id++
data, _ = json.Marshal(request)
return data
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。