本文整理汇总了Golang中git/apache/org/thrift/git/lib/go/thrift.NewTMemoryBufferLen函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTMemoryBufferLen函数的具体用法?Golang NewTMemoryBufferLen怎么用?Golang NewTMemoryBufferLen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTMemoryBufferLen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: binary
func binary() {
fmt.Printf("\n ==== demo Thrift Binary serialization ====\n")
t := thrift.NewTMemoryBufferLen(1024)
p := thrift.NewTBinaryProtocolFactoryDefault().GetProtocol(t)
tser := &thrift.TSerializer{
Transport: t,
Protocol: p,
}
str := "hi there"
a := &tutorial.Work{
Num1: 12,
Num2: 24,
Comment: &str,
}
by, err := tser.Write(a)
panicOn(err)
fmt.Printf("by = '%v', length %v\n", string(by), len(by))
t2 := thrift.NewTMemoryBufferLen(1024)
p2 := thrift.NewTBinaryProtocolFactoryDefault().GetProtocol(t2)
deser := &thrift.TDeserializer{
Transport: t2,
Protocol: p2,
}
b := tutorial.NewWork()
deser.Transport.Close() // resets underlying bytes.Buffer
err = deser.Read(b, by)
panicOn(err)
fmt.Printf("b = '%#v'\n", b)
}
示例2: ParseThriftMsgBegin
//
// 解析Thrift数据的Message Header
//
func ParseThriftMsgBegin(msg []byte) (name string, typeId thrift.TMessageType, seqId int32, err error) {
transport := thrift.NewTMemoryBufferLen(256)
transport.Write(msg)
protocol := thrift.NewTBinaryProtocolTransport(transport)
name, typeId, seqId, err = protocol.ReadMessageBegin()
return
}
示例3: GetWorkerNotFoundData
func GetWorkerNotFoundData(service string, seqId int32) []byte {
// 构建thrift的Transport
transport := thrift.NewTMemoryBufferLen(1024)
protocol := thrift.NewTBinaryProtocolTransport(transport)
// 构建一个Message, 写入Exception
msg := fmt.Sprintf("Worker: %s Not Found", service)
exc := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, msg)
protocol.WriteMessageBegin(service, thrift.EXCEPTION, seqId)
exc.Write(protocol)
protocol.WriteMessageEnd()
bytes := transport.Bytes()
return bytes
}
示例4: Process
// Process function
func (s *Server) Process(str *string) (string, error) {
buffer := new(bytes.Buffer)
_, err := buffer.WriteString(*str)
if err != nil {
s.Err(err)
return "", err
}
t1 := &thrift.TMemoryBuffer{Buffer: buffer}
in := thrift.NewTJSONProtocol(t1)
t2 := thrift.NewTMemoryBufferLen(1024)
//defer t2.Close()
out := thrift.NewTJSONProtocol(t2)
s.processor.Process(in, out)
return t2.String(), nil
}
示例5: GetWorkerNotFoundData
func GetWorkerNotFoundData(req *Request, module string) []byte {
req.Response.TypeId = thrift.EXCEPTION
// 构建thrift的Transport
transport := thrift.NewTMemoryBufferLen(100)
protocol := thrift.NewTBinaryProtocolTransport(transport)
// 构建一个Message, 写入Exception
msg := fmt.Sprintf("Worker FOR %s#%s.%s Not Found", module, req.Service, req.Request.Name)
exc := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, msg)
protocol.WriteMessageBegin(req.Request.Name, thrift.EXCEPTION, req.Request.SeqId)
exc.Write(protocol)
protocol.WriteMessageEnd()
bytes := transport.Bytes()
return bytes
}
示例6: GetThriftException
func GetThriftException(req *Request, module string) []byte {
req.Response.TypeId = thrift.EXCEPTION
// 构建thrift的Transport
transport := thrift.NewTMemoryBufferLen(256)
protocol := thrift.NewTBinaryProtocolTransport(transport)
msg := fmt.Sprintf("Module: %s, Service: %s, Method: %s, Error: %v", module, req.Service, req.Request.Name, req.Response.Err)
// 构建一个Message, 写入Exception
exc := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, msg)
protocol.WriteMessageBegin(req.Service, thrift.EXCEPTION, req.Request.SeqId)
exc.Write(protocol)
protocol.WriteMessageEnd()
bytes := transport.Bytes()
return bytes
}
示例7: GetServiceNotFoundData
//
// 生成Thrift格式的Exception Message
//
func GetServiceNotFoundData(req *Request) []byte {
req.Response.TypeId = thrift.EXCEPTION
// 构建thrift的Transport
transport := thrift.NewTMemoryBufferLen(100)
protocol := thrift.NewTBinaryProtocolTransport(transport)
// 构建一个Message, 写入Exception
msg := fmt.Sprintf("Service: %s Not Found", req.Service)
exc := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, msg)
protocol.WriteMessageBegin(req.Request.Name, thrift.EXCEPTION, req.Request.SeqId)
exc.Write(protocol)
protocol.WriteMessageEnd()
protocol.Flush()
bytes := transport.Bytes()
return bytes
}
示例8: NewThriftHandler
// NewThriftHandler retuns http.Handler
func NewThriftHandler(processor thrift.TProcessor) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != `POST` {
http.Error(w, "Thrift Handler requires POST access", http.StatusInternalServerError)
return
}
buffer := new(bytes.Buffer)
_, err := buffer.ReadFrom(r.Body)
if err != nil {
http.Error(w, "Could not read body", http.StatusInternalServerError)
return
}
inTransport := &thrift.TMemoryBuffer{Buffer: buffer}
inProtocol := thrift.NewTJSONProtocol(inTransport)
outTransport := thrift.NewTMemoryBufferLen(1024)
outProtocol := thrift.NewTJSONProtocol(outTransport)
processor.Process(inProtocol, outProtocol)
fmt.Fprint(w, outTransport)
}
}
示例9: main
//.........这里部分代码省略.........
tmp0, err28 := (strconv.Atoi(flag.Arg(1)))
if err28 != nil {
Usage()
return
}
argvalue0 := int32(tmp0)
value0 := argvalue0
argvalue1 := flag.Arg(2) == "true"
value1 := argvalue1
fmt.Print(client.ActiveFontUser(value0, value1))
fmt.Print("\n")
break
case "FindApplyFormByUnit":
if flag.NArg()-1 != 1 {
fmt.Fprintln(os.Stderr, "FindApplyFormByUnit requires 1 args")
flag.Usage()
}
tmp0, err30 := (strconv.Atoi(flag.Arg(1)))
if err30 != nil {
Usage()
return
}
argvalue0 := int32(tmp0)
value0 := argvalue0
fmt.Print(client.FindApplyFormByUnit(value0))
fmt.Print("\n")
break
case "PushBoxStatus":
if flag.NArg()-1 != 1 {
fmt.Fprintln(os.Stderr, "PushBoxStatus requires 1 args")
flag.Usage()
}
arg31 := flag.Arg(1)
mbTrans32 := thrift.NewTMemoryBufferLen(len(arg31))
defer mbTrans32.Close()
_, err33 := mbTrans32.WriteString(arg31)
if err33 != nil {
Usage()
return
}
factory34 := thrift.NewTSimpleJSONProtocolFactory()
jsProt35 := factory34.GetProtocol(mbTrans32)
argvalue0 := service.NewBoxStatus()
err36 := argvalue0.Read(jsProt35)
if err36 != nil {
Usage()
return
}
value0 := argvalue0
fmt.Print(client.PushBoxStatus(value0))
fmt.Print("\n")
break
case "DeleteApplyForm":
if flag.NArg()-1 != 1 {
fmt.Fprintln(os.Stderr, "DeleteApplyForm requires 1 args")
flag.Usage()
}
tmp0, err37 := (strconv.Atoi(flag.Arg(1)))
if err37 != nil {
Usage()
return
}
argvalue0 := int32(tmp0)
value0 := argvalue0
fmt.Print(client.DeleteApplyForm(value0))
fmt.Print("\n")
示例10: main
//.........这里部分代码省略.........
protocolFactory = thrift.NewTCompactProtocolFactory()
break
case "simplejson":
protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
break
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
break
case "binary", "":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
break
default:
fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol)
Usage()
os.Exit(1)
}
client := services.NewCitySvcClientFactory(trans, protocolFactory)
if err := trans.Open(); err != nil {
fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err)
os.Exit(1)
}
switch cmd {
case "createCity":
if flag.NArg()-1 != 3 {
fmt.Fprintln(os.Stderr, "CreateCity requires 3 args")
flag.Usage()
}
argvalue0 := flag.Arg(1)
value0 := argvalue0
argvalue1 := flag.Arg(2)
value1 := argvalue1
arg191 := flag.Arg(3)
mbTrans192 := thrift.NewTMemoryBufferLen(len(arg191))
defer mbTrans192.Close()
_, err193 := mbTrans192.WriteString(arg191)
if err193 != nil {
Usage()
return
}
factory194 := thrift.NewTSimpleJSONProtocolFactory()
jsProt195 := factory194.GetProtocol(mbTrans192)
containerStruct2 := services.NewCitySvcCreateCityArgs()
err196 := containerStruct2.ReadField3(jsProt195)
if err196 != nil {
Usage()
return
}
argvalue2 := containerStruct2.Coords
value2 := argvalue2
fmt.Print(client.CreateCity(value0, value1, value2))
fmt.Print("\n")
break
case "getNearBy":
if flag.NArg()-1 != 2 {
fmt.Fprintln(os.Stderr, "GetNearBy requires 2 args")
flag.Usage()
}
arg197 := flag.Arg(1)
mbTrans198 := thrift.NewTMemoryBufferLen(len(arg197))
defer mbTrans198.Close()
_, err199 := mbTrans198.WriteString(arg197)
if err199 != nil {
Usage()
return
}
示例11: main
func main() {
flag.Usage = Usage
var host string
var port int
var protocol string
var urlString string
var framed bool
var useHttp bool
var parsedUrl url.URL
var trans thrift.TTransport
_ = strconv.Atoi
_ = math.Abs
flag.Usage = Usage
flag.StringVar(&host, "h", "localhost", "Specify host and port")
flag.IntVar(&port, "p", 9090, "Specify port")
flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)")
flag.StringVar(&urlString, "u", "", "Specify the url")
flag.BoolVar(&framed, "framed", false, "Use framed transport")
flag.BoolVar(&useHttp, "http", false, "Use http")
flag.Parse()
if len(urlString) > 0 {
parsedUrl, err := url.Parse(urlString)
if err != nil {
fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
flag.Usage()
}
host = parsedUrl.Host
useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http"
} else if useHttp {
_, err := url.Parse(fmt.Sprint("http://", host, ":", port))
if err != nil {
fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
flag.Usage()
}
}
cmd := flag.Arg(0)
var err error
if useHttp {
trans, err = thrift.NewTHttpClient(parsedUrl.String())
} else {
portStr := fmt.Sprint(port)
if strings.Contains(host, ":") {
host, portStr, err = net.SplitHostPort(host)
if err != nil {
fmt.Fprintln(os.Stderr, "error with host:", err)
os.Exit(1)
}
}
trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr))
if err != nil {
fmt.Fprintln(os.Stderr, "error resolving address:", err)
os.Exit(1)
}
if framed {
trans = thrift.NewTFramedTransport(trans)
}
}
if err != nil {
fmt.Fprintln(os.Stderr, "Error creating transport", err)
os.Exit(1)
}
defer trans.Close()
var protocolFactory thrift.TProtocolFactory
switch protocol {
case "compact":
protocolFactory = thrift.NewTCompactProtocolFactory()
break
case "simplejson":
protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
break
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
break
case "binary", "":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
break
default:
fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol)
Usage()
os.Exit(1)
}
client := services.NewAreaSvcClientFactory(trans, protocolFactory)
if err := trans.Open(); err != nil {
fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err)
os.Exit(1)
}
switch cmd {
case "createArea":
if flag.NArg()-1 != 2 {
fmt.Fprintln(os.Stderr, "CreateArea requires 2 args")
flag.Usage()
}
argvalue0 := flag.Arg(1)
value0 := argvalue0
arg144 := flag.Arg(2)
mbTrans145 := thrift.NewTMemoryBufferLen(len(arg144))
defer mbTrans145.Close()
//.........这里部分代码省略.........
示例12: main
//.........这里部分代码省略.........
case "binary", "":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
break
default:
fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol)
Usage()
os.Exit(1)
}
client := notestore.NewNoteStoreClientFactory(trans, protocolFactory)
if err := trans.Open(); err != nil {
fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err)
os.Exit(1)
}
switch cmd {
case "getSyncState":
if flag.NArg()-1 != 1 {
fmt.Fprintln(os.Stderr, "GetSyncState requires 1 args")
flag.Usage()
}
argvalue0 := flag.Arg(1)
value0 := argvalue0
fmt.Print(client.GetSyncState(value0))
fmt.Print("\n")
break
case "getSyncStateWithMetrics":
if flag.NArg()-1 != 2 {
fmt.Fprintln(os.Stderr, "GetSyncStateWithMetrics requires 2 args")
flag.Usage()
}
argvalue0 := flag.Arg(1)
value0 := argvalue0
arg194 := flag.Arg(2)
mbTrans195 := thrift.NewTMemoryBufferLen(len(arg194))
defer mbTrans195.Close()
_, err196 := mbTrans195.WriteString(arg194)
if err196 != nil {
Usage()
return
}
factory197 := thrift.NewTSimpleJSONProtocolFactory()
jsProt198 := factory197.GetProtocol(mbTrans195)
argvalue1 := notestore.NewClientUsageMetrics()
err199 := argvalue1.Read(jsProt198)
if err199 != nil {
Usage()
return
}
value1 := argvalue1
fmt.Print(client.GetSyncStateWithMetrics(value0, value1))
fmt.Print("\n")
break
case "getSyncChunk":
if flag.NArg()-1 != 4 {
fmt.Fprintln(os.Stderr, "GetSyncChunk requires 4 args")
flag.Usage()
}
argvalue0 := flag.Arg(1)
value0 := argvalue0
tmp1, err201 := (strconv.Atoi(flag.Arg(2)))
if err201 != nil {
Usage()
return
}
argvalue1 := int32(tmp1)
value1 := argvalue1
示例13: main
func main() {
flag.Usage = Usage
var host string
var port int
var protocol string
var urlString string
var framed bool
var useHttp bool
var parsedUrl url.URL
var trans thrift.TTransport
_ = strconv.Atoi
_ = math.Abs
flag.Usage = Usage
flag.StringVar(&host, "h", "localhost", "Specify host and port")
flag.IntVar(&port, "p", 9090, "Specify port")
flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)")
flag.StringVar(&urlString, "u", "", "Specify the url")
flag.BoolVar(&framed, "framed", false, "Use framed transport")
flag.BoolVar(&useHttp, "http", false, "Use http")
flag.Parse()
if len(urlString) > 0 {
parsedUrl, err := url.Parse(urlString)
if err != nil {
fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
flag.Usage()
}
host = parsedUrl.Host
useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http"
} else if useHttp {
_, err := url.Parse(fmt.Sprint("http://", host, ":", port))
if err != nil {
fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
flag.Usage()
}
}
cmd := flag.Arg(0)
var err error
if useHttp {
trans, err = thrift.NewTHttpClient(parsedUrl.String())
} else {
portStr := fmt.Sprint(port)
if strings.Contains(host, ":") {
host, portStr, err = net.SplitHostPort(host)
if err != nil {
fmt.Fprintln(os.Stderr, "error with host:", err)
os.Exit(1)
}
}
trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr))
if err != nil {
fmt.Fprintln(os.Stderr, "error resolving address:", err)
os.Exit(1)
}
if framed {
trans = thrift.NewTFramedTransport(trans)
}
}
if err != nil {
fmt.Fprintln(os.Stderr, "Error creating transport", err)
os.Exit(1)
}
defer trans.Close()
var protocolFactory thrift.TProtocolFactory
switch protocol {
case "compact":
protocolFactory = thrift.NewTCompactProtocolFactory()
break
case "simplejson":
protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
break
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
break
case "binary", "":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
break
default:
fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol)
Usage()
os.Exit(1)
}
client := bolt.NewBoltSchedulerServiceClientFactory(trans, protocolFactory)
if err := trans.Open(); err != nil {
fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err)
os.Exit(1)
}
switch cmd {
case "deployComputation":
if flag.NArg()-1 != 1 {
fmt.Fprintln(os.Stderr, "DeployComputation requires 1 args")
flag.Usage()
}
arg102 := flag.Arg(1)
mbTrans103 := thrift.NewTMemoryBufferLen(len(arg102))
defer mbTrans103.Close()
_, err104 := mbTrans103.WriteString(arg102)
if err104 != nil {
//.........这里部分代码省略.........
示例14: main
func main() {
flag.Usage = Usage
var host string
var port int
var protocol string
var urlString string
var framed bool
var useHttp bool
var parsedUrl url.URL
var trans thrift.TTransport
_ = math.MinInt32 // will become unneeded eventually
_ = strconv.Atoi
flag.Usage = Usage
flag.StringVar(&host, "h", "localhost", "Specify host and port")
flag.IntVar(&port, "p", 9090, "Specify port")
flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)")
flag.StringVar(&urlString, "u", "", "Specify the url")
flag.BoolVar(&framed, "framed", false, "Use framed transport")
flag.BoolVar(&useHttp, "http", false, "Use http")
flag.Parse()
if len(urlString) > 0 {
parsedUrl, err := url.Parse(urlString)
if err != nil {
fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
flag.Usage()
}
host = parsedUrl.Host
useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http"
} else if useHttp {
_, err := url.Parse(fmt.Sprint("http://", host, ":", port))
if err != nil {
fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
flag.Usage()
}
}
cmd := flag.Arg(0)
var err error
if useHttp {
trans, err = thrift.NewTHttpClient(parsedUrl.String())
} else {
portStr := fmt.Sprint(port)
if strings.Contains(host, ":") {
host, portStr, err = net.SplitHostPort(host)
if err != nil {
fmt.Fprintln(os.Stderr, "error with host:", err)
os.Exit(1)
}
}
trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr))
if err != nil {
fmt.Fprintln(os.Stderr, "error resolving address:", err)
os.Exit(1)
}
if framed {
trans = thrift.NewTFramedTransport(trans)
}
}
if err != nil {
fmt.Fprintln(os.Stderr, "Error creating transport", err)
os.Exit(1)
}
defer trans.Close()
var protocolFactory thrift.TProtocolFactory
switch protocol {
case "compact":
protocolFactory = thrift.NewTCompactProtocolFactory()
break
case "simplejson":
protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
break
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
break
case "binary", "":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
break
default:
fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol)
Usage()
os.Exit(1)
}
client := service.NewAdServletClientFactory(trans, protocolFactory)
if err := trans.Open(); err != nil {
fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err)
os.Exit(1)
}
switch cmd {
case "Sender":
if flag.NArg()-1 != 1 {
fmt.Fprintln(os.Stderr, "Sender requires 1 args")
flag.Usage()
}
arg10 := flag.Arg(1)
mbTrans11 := thrift.NewTMemoryBufferLen(len(arg10))
defer mbTrans11.Close()
_, err12 := mbTrans11.WriteString(arg10)
if err12 != nil {
//.........这里部分代码省略.........
示例15: init
"git.apache.org/thrift.git/lib/go/thrift"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
"github.com/huodon/wpc/thrift/impl"
"github.com/huodon/wpc/thrift/service"
)
var upgrade = websocket.Upgrader{
HandshakeTimeout: 15 * time.Second,
Error: func(w http.ResponseWriter, r *http.Request, status int, reason error) {
log.Printf("some error happend: %v, state: %d, reason: %s", r.Host, status, reason)
},
}
var (
trans = thrift.NewTMemoryBufferLen(bytes.MinRead << 4)
proto = thrift.NewTJSONProtocol(trans)
process = thrift.NewTMultiplexedProcessor()
boxProc = service.NewBoxServiceProcessor(impl.GetServiceImpl())
inChan = make(chan []byte)
)
func init() {
process.RegisterDefault(boxProc)
}
func wsHandle(w http.ResponseWriter, r *http.Request) {
log.Println(`incomeing websocket request`)
c, err := upgrade.Upgrade(w, r, nil)
defer c.Close()