├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── idl ├── shared.thrift └── tutorial.thrift ├── keys ├── server.crt └── server.key ├── serialize.go ├── src ├── client │ ├── client.go │ └── main.go └── server │ ├── handler.go │ ├── main.go │ └── server.go └── vendor ├── git.apache.org └── thrift.git │ └── lib │ └── go │ └── thrift │ ├── application_exception.go │ ├── application_exception_test.go │ ├── binary_protocol.go │ ├── binary_protocol_test.go │ ├── buffered_transport.go │ ├── buffered_transport_test.go │ ├── compact_protocol.go │ ├── compact_protocol_test.go │ ├── debug_protocol.go │ ├── deserializer.go │ ├── exception.go │ ├── exception_test.go │ ├── field.go │ ├── framed_transport.go │ ├── framed_transport_test.go │ ├── http_client.go │ ├── http_client_test.go │ ├── iostream_transport.go │ ├── iostream_transport_test.go │ ├── json_protocol.go │ ├── json_protocol_test.go │ ├── lowlevel_benchmarks_test.go │ ├── memory_buffer.go │ ├── memory_buffer_test.go │ ├── messagetype.go │ ├── multiplexed_protocol.go │ ├── numeric.go │ ├── pointerize.go │ ├── processor.go │ ├── processor_factory.go │ ├── protocol.go │ ├── protocol_exception.go │ ├── protocol_factory.go │ ├── protocol_test.go │ ├── rich_transport.go │ ├── rich_transport_test.go │ ├── serializer.go │ ├── serializer_test.go │ ├── serializer_types_test.go │ ├── server.go │ ├── server_socket.go │ ├── server_test.go │ ├── server_transport.go │ ├── simple_json_protocol.go │ ├── simple_json_protocol_test.go │ ├── simple_server.go │ ├── socket.go │ ├── ssl_server_socket.go │ ├── ssl_socket.go │ ├── transport.go │ ├── transport_exception.go │ ├── transport_exception_test.go │ ├── transport_factory.go │ ├── transport_test.go │ ├── type.go │ ├── zlib_transport.go │ └── zlib_transport_test.go ├── shared ├── constants.go ├── shared_service-remote │ └── shared_service-remote.go ├── sharedservice.go └── ttypes.go └── tutorial ├── calculator-remote └── calculator-remote.go ├── calculator.go ├── constants.go └── ttypes.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | bin/* 26 | *~ 27 | vendor/shared/* 28 | vendor/tutorial/* 29 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | # use the vendor/ subdir which holds the vendored apache thrift go library, version 3 | # the vendored thrift is commit fa0796d33208eadafb6f42964c8ef29d7751bfc2 on 1.0.0-dev, 4 | # last commit there is Fri Oct 16 21:33:39 2015 +0200, from https://github.com/apache/thrift 5 | all: 6 | cd src/client && GO15VENDOREXPERIMENT=1 go build -o ../../bin/thrift-ex-client 7 | cd src/server && GO15VENDOREXPERIMENT=1 go build -o ../../bin/thrift-ex-server 8 | 9 | regen: 10 | rm -rf vendor/shared vendor/tutorial 11 | thrift -version || true # thrift -version needs to be 1.0.0-dev ! 12 | thrift --gen go -out vendor -r -I idl idl/tutorial.thrift 13 | 14 | 15 | clean: 16 | rm -f bin/* *~ 17 | 18 | run: 19 | bin/thrift-ex-server -secure & 20 | sleep 1 && bin/thrift-ex-client -secure 21 | sleep 1 && pkill -9 thrift-ex-server 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # golang-thrift-minimal-example 2 | 3 | This is a minimal working example of how to use golang and apache thrift. 4 | 5 | It was extracted from the apache thrift tutorial; https://github.com/apache/thrift. 6 | 7 | Go 1.5.1 and GO15VENDOREXPERIMENT=1 required, as vendor/ is used. 8 | You will need to have the 'thrift' binary from 1.0.0-dev (current github source build) installed prior to running make && make run. 9 | 10 | ## version 11 | Specifically the https://github.com/apache/thrift/tree/master/tutorial/go example is re-organized here 12 | to make it easier to understand and extend. 13 | 14 | The vendored golang thrift library code is commit fa0796d33208eadafb6f42964c8ef29d7751bfc2 on 1.0.0-dev. 15 | 16 | The last commit there is Fri Oct 16 21:33:39 2015 +0200, from https://github.com/apache/thrift 17 | 18 | See the vendor/git.apache.org directory for the vendored apache-thrift-golang library code. To allow the generated examples to 19 | run no matter where you put this code, we generate into vendor/shared and vendor/tutorial. For actual use, 20 | you'll probably want to generate into a unique directory that can be version controlled. See the -out flag to `thrift` to control where generated code goes. 21 | 22 | LICENSE: Apache 2.0. 23 | -------------------------------------------------------------------------------- /idl/shared.thrift: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | /** 21 | * This Thrift file can be included by other Thrift files that want to share 22 | * these definitions. 23 | */ 24 | 25 | namespace cpp shared 26 | namespace d share // "shared" would collide with the eponymous D keyword. 27 | namespace java shared 28 | namespace perl shared 29 | namespace php shared 30 | 31 | struct SharedStruct { 32 | 1: i32 key 33 | 2: string value 34 | } 35 | 36 | service SharedService { 37 | SharedStruct getStruct(1: i32 key) 38 | } 39 | -------------------------------------------------------------------------------- /idl/tutorial.thrift: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | # Thrift Tutorial 21 | # Mark Slee (mcslee@facebook.com) 22 | # 23 | # This file aims to teach you how to use Thrift, in a .thrift file. Neato. The 24 | # first thing to notice is that .thrift files support standard shell comments. 25 | # This lets you make your thrift file executable and include your Thrift build 26 | # step on the top line. And you can place comments like this anywhere you like. 27 | # 28 | # Before running this file, you will need to have installed the thrift compiler 29 | # into /usr/local/bin. 30 | 31 | /** 32 | * The first thing to know about are types. The available types in Thrift are: 33 | * 34 | * bool Boolean, one byte 35 | * byte Signed byte 36 | * i16 Signed 16-bit integer 37 | * i32 Signed 32-bit integer 38 | * i64 Signed 64-bit integer 39 | * double 64-bit floating point value 40 | * string String 41 | * binary Blob (byte array) 42 | * map Map from one type to another 43 | * list Ordered list of one type 44 | * set Set of unique elements of one type 45 | * 46 | * Did you also notice that Thrift supports C style comments? 47 | */ 48 | 49 | // Just in case you were wondering... yes. We support simple C comments too. 50 | 51 | /** 52 | * Thrift files can reference other Thrift files to include common struct 53 | * and service definitions. These are found using the current path, or by 54 | * searching relative to any paths specified with the -I compiler flag. 55 | * 56 | * Included objects are accessed using the name of the .thrift file as a 57 | * prefix. i.e. shared.SharedObject 58 | */ 59 | include "shared.thrift" 60 | 61 | /** 62 | * Thrift files can namespace, package, or prefix their output in various 63 | * target languages. 64 | */ 65 | namespace cpp tutorial 66 | namespace java tutorial 67 | namespace php tutorial 68 | namespace perl tutorial 69 | 70 | /** 71 | * Thrift lets you do typedefs to get pretty names for your types. Standard 72 | * C style here. 73 | */ 74 | typedef i32 MyInteger 75 | 76 | /** 77 | * Thrift also lets you define constants for use across languages. Complex 78 | * types and structs are specified using JSON notation. 79 | */ 80 | const i32 INT32CONSTANT = 9853 81 | const map MAPCONSTANT = {'hello':'world', 'goodnight':'moon'} 82 | 83 | /** 84 | * You can define enums, which are just 32 bit integers. Values are optional 85 | * and start at 1 if not supplied, C style again. 86 | */ 87 | enum Operation { 88 | ADD = 1, 89 | SUBTRACT = 2, 90 | MULTIPLY = 3, 91 | DIVIDE = 4 92 | } 93 | 94 | /** 95 | * Structs are the basic complex data structures. They are comprised of fields 96 | * which each have an integer identifier, a type, a symbolic name, and an 97 | * optional default value. 98 | * 99 | * Fields can be declared "optional", which ensures they will not be included 100 | * in the serialized output if they aren't set. Note that this requires some 101 | * manual management in some languages. 102 | */ 103 | struct Work { 104 | 1: i32 num1 = 0, 105 | 2: i32 num2, 106 | 3: Operation op, 107 | 4: optional string comment, 108 | } 109 | 110 | /** 111 | * Structs can also be exceptions, if they are nasty. 112 | */ 113 | exception InvalidOperation { 114 | 1: i32 whatOp, 115 | 2: string why 116 | } 117 | 118 | /** 119 | * Ahh, now onto the cool part, defining a service. Services just need a name 120 | * and can optionally inherit from another service using the extends keyword. 121 | */ 122 | service Calculator extends shared.SharedService { 123 | 124 | /** 125 | * A method definition looks like C code. It has a return type, arguments, 126 | * and optionally a list of exceptions that it may throw. Note that argument 127 | * lists and exception lists are specified using the exact same syntax as 128 | * field lists in struct or exception definitions. 129 | */ 130 | 131 | void ping(), 132 | 133 | i32 add(1:i32 num1, 2:i32 num2), 134 | 135 | i32 calculate(1:i32 logid, 2:Work w) throws (1:InvalidOperation ouch), 136 | 137 | /** 138 | * This method has a oneway modifier. That means the client only makes 139 | * a request and does not listen for any response at all. Oneway methods 140 | * must be void. 141 | */ 142 | oneway void zip() 143 | 144 | } 145 | 146 | /** 147 | * That just about covers the basics. Take a look in the test/ folder for more 148 | * detailed examples. After you run this file, your generated code shows up 149 | * in folders with names gen-. The generated code isn't too scary 150 | * to look at. It even has pretty indentation. 151 | */ 152 | -------------------------------------------------------------------------------- /keys/server.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIENzCCAx+gAwIBAgIJAOYfYfw7NCOcMA0GCSqGSIb3DQEBBQUAMIGxMQswCQYD 3 | VQQGEwJVUzERMA8GA1UECAwITWFyeWxhbmQxFDASBgNVBAcMC0ZvcmVzdCBIaWxs 4 | MScwJQYDVQQKDB5UaGUgQXBhY2hlIFNvZnR3YXJlIEZvdW5kYXRpb24xFjAUBgNV 5 | BAsMDUFwYWNoZSBUaHJpZnQxEjAQBgNVBAMMCWxvY2FsaG9zdDEkMCIGCSqGSIb3 6 | DQEJARYVZGV2QHRocmlmdC5hcGFjaGUub3JnMB4XDTE0MDQwNzE4NTgwMFoXDTIy 7 | MDYyNDE4NTgwMFowgbExCzAJBgNVBAYTAlVTMREwDwYDVQQIDAhNYXJ5bGFuZDEU 8 | MBIGA1UEBwwLRm9yZXN0IEhpbGwxJzAlBgNVBAoMHlRoZSBBcGFjaGUgU29mdHdh 9 | cmUgRm91bmRhdGlvbjEWMBQGA1UECwwNQXBhY2hlIFRocmlmdDESMBAGA1UEAwwJ 10 | bG9jYWxob3N0MSQwIgYJKoZIhvcNAQkBFhVkZXZAdGhyaWZ0LmFwYWNoZS5vcmcw 11 | ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCqE9TE9wEXp5LRtLQVDSGQ 12 | GV78+7ZtP/I/ZaJ6Q6ZGlfxDFvZjFF73seNhAvlKlYm/jflIHYLnNOCySN8I2Xw6 13 | L9MbC+jvwkEKfQo4eDoxZnOZjNF5J1/lZtBeOowMkhhzBMH1Rds351/HjKNg6ZKg 14 | 2Cldd0j7HbDtEixOLgLbPRpBcaYrLrNMasf3Hal+x8/b8ue28x93HSQBGmZmMIUw 15 | AinEu/fNP4lLGl/0kZb76TnyRpYSPYojtS6CnkH+QLYnsRREXJYwD1Xku62LipkX 16 | wCkRTnZ5nUsDMX6FPKgjQFQCWDXG/N096+PRUQAChhrXsJ+gF3NqWtDmtrhVQF4n 17 | AgMBAAGjUDBOMB0GA1UdDgQWBBQo8v0wzQPx3EEexJPGlxPK1PpgKjAfBgNVHSME 18 | GDAWgBQo8v0wzQPx3EEexJPGlxPK1PpgKjAMBgNVHRMEBTADAQH/MA0GCSqGSIb3 19 | DQEBBQUAA4IBAQBGFRiJslcX0aJkwZpzTwSUdgcfKbpvNEbCNtVohfQVTI4a/oN5 20 | U+yqDZJg3vOaOuiAZqyHcIlZ8qyesCgRN314Tl4/JQ++CW8mKj1meTgo5YFxcZYm 21 | T9vsI3C+Nzn84DINgI9mx6yktIt3QOKZRDpzyPkUzxsyJ8J427DaimDrjTR+fTwD 22 | 1Dh09xeeMnSa5zeV1HEDyJTqCXutLetwQ/IyfmMBhIx+nvB5f67pz/m+Dv6V0r3I 23 | p4HCcdnDUDGJbfqtoqsAATQQWO+WWuswB6mOhDbvPTxhRpZq6AkgWqv4S+u3M2GO 24 | r5p9FrBgavAw5bKO54C0oQKpN/5fta5l6Ws0 25 | -----END CERTIFICATE----- 26 | -------------------------------------------------------------------------------- /keys/server.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCqE9TE9wEXp5LR 3 | tLQVDSGQGV78+7ZtP/I/ZaJ6Q6ZGlfxDFvZjFF73seNhAvlKlYm/jflIHYLnNOCy 4 | SN8I2Xw6L9MbC+jvwkEKfQo4eDoxZnOZjNF5J1/lZtBeOowMkhhzBMH1Rds351/H 5 | jKNg6ZKg2Cldd0j7HbDtEixOLgLbPRpBcaYrLrNMasf3Hal+x8/b8ue28x93HSQB 6 | GmZmMIUwAinEu/fNP4lLGl/0kZb76TnyRpYSPYojtS6CnkH+QLYnsRREXJYwD1Xk 7 | u62LipkXwCkRTnZ5nUsDMX6FPKgjQFQCWDXG/N096+PRUQAChhrXsJ+gF3NqWtDm 8 | trhVQF4nAgMBAAECggEAW/y52YYW6ypROGbZ94DQpFV0kLO7qT8q0Ksxw5sPNaIt 9 | fEPRIymDa8ikyHWJS5Oxmw84wo5jnJV26jaLmwe2Lupq7Xf1lqej8f5LJtuv7cQR 10 | xfzp1vM65KJFFJHp6WqjGqJ6HSSZOpVDsnQYcXQjQCdpyAmaSWd3p+FqYSZ1mQmD 11 | bFNI7jqpczWSZhTdotQ7p7Hn9TVCehflP3yGIB3bQ+wCcCB85dOBz201L+YgaIck 12 | Sz43A4NvWaQIRLRDw7s9GW4jY5T0Jv282WIeAlVpVxLIwu48r4R4yGTIx9Ydowvq 13 | 57+Y5iPPjAXxu0V9t00oS3bYxDaKh2DUfc/5zowq8QKBgQDYNVPXmaG0aIH4vjQ9 14 | 7fRdw/UDkYcQbn6CnglQOu77/S8ogQzpKCVJgJgkZNqOVtQMEPzekGEcLTbje1gU 15 | 8Bky2k+PL9UwbFy0emnOVh4rqrNXHsRvJcehNT/PRb5hjF3MUMFV/0iD4b+naFaE 16 | jrSWiZ2ZXj2qfwAK52GFbtOuBQKBgQDJYQuGiY0r22E4waJmCSKczoBT3cwlVzWj 17 | V2ljgA9RHLNTVkvNNYQLGu2qngFrtwpeaSnsMDerVG4wKAQWyCnYzxVrlnC4uDrJ 18 | HXuFEltBWi9Ffbgfsnd3749AT0oBP1NT2tMleguyf5DFgjCR3VRJLdrVaaZ8row/ 19 | LqKcFMqnOwKBgB+OIO99l7E584Y3VG6ZdSneOLtNmRXX2pT7tcZE465ZdHGH7Dd3 20 | SYHhx9K/+Xn+yDH+pLli/xlarAEldmSP6k2WuTfftlC78AfTOfAId5zN7CDR9791 21 | Fx67I9X/itq33tS8EIuZl57P6uXm/4GXRloWOa8xpvRkVsBApuYPl8t1AoGATQDS 22 | y2sllDObBXzlgGbV2WgNIgSZ311toTv3jJiXQsjauW8yJRHln+l4H9mzaWDgkiFc 23 | ang1kUoDqF5k0eFQPxtQcYdhKwEnWWfwp33RbzfxA32DPnubuzzbZhfrkHaKgnIW 24 | cyor9uFYlm2l7ODZLfJez2RKyTplXnOSsmQw6akCgYAz3dj9Hskyj+HVJ+ht1OcE 25 | c7ai/ESkSA7Vajp0tjJp0EKjW/zq8DvUSXOtcdnJgkKycFluLwbmnaN4txBds1C1 26 | Qr8Rt2sUCCBNZe1L6DHe3XBdbkJe9sgZVNTjtUSQrzy8UhvsCqG4YWeCu07Szcbc 27 | rdPUV9/uQkdx8VrShxlD8A== 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /serialize.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "git.apache.org/thrift.git/lib/go/thrift" 6 | "github.com/glycerine/golang-thrift-minimal-example/vendor/tutorial" 7 | ) 8 | 9 | func main() { 10 | binary() 11 | compact() 12 | } 13 | 14 | func binary() { 15 | fmt.Printf("\n ==== demo Thrift Binary serialization ====\n") 16 | t := thrift.NewTMemoryBufferLen(1024) 17 | p := thrift.NewTBinaryProtocolFactoryDefault().GetProtocol(t) 18 | 19 | tser := &thrift.TSerializer{ 20 | Transport: t, 21 | Protocol: p, 22 | } 23 | 24 | str := "hi there" 25 | a := &tutorial.Work{ 26 | Num1: 12, 27 | Num2: 24, 28 | Comment: &str, 29 | } 30 | 31 | by, err := tser.Write(a) 32 | panicOn(err) 33 | fmt.Printf("by = '%v', length %v\n", string(by), len(by)) 34 | 35 | t2 := thrift.NewTMemoryBufferLen(1024) 36 | p2 := thrift.NewTBinaryProtocolFactoryDefault().GetProtocol(t2) 37 | 38 | deser := &thrift.TDeserializer{ 39 | Transport: t2, 40 | Protocol: p2, 41 | } 42 | 43 | b := tutorial.NewWork() 44 | deser.Transport.Close() // resets underlying bytes.Buffer 45 | err = deser.Read(b, by) 46 | panicOn(err) 47 | fmt.Printf("b = '%#v'\n", b) 48 | } 49 | 50 | func compact() { 51 | fmt.Printf("\n ==== demo Thrift Compact Binary serialization ====\n") 52 | 53 | t := thrift.NewTMemoryBufferLen(1024) 54 | p := thrift.NewTCompactProtocolFactory().GetProtocol(t) 55 | 56 | tser := &thrift.TSerializer{ 57 | Transport: t, 58 | Protocol: p, 59 | } 60 | 61 | str := "hi there" 62 | a := &tutorial.Work{ 63 | Num1: 12, 64 | Num2: 24, 65 | Comment: &str, 66 | } 67 | 68 | by, err := tser.Write(a) 69 | panicOn(err) 70 | fmt.Printf("by = '%v', length %v\n", string(by), len(by)) 71 | 72 | t2 := thrift.NewTMemoryBufferLen(1024) 73 | p2 := thrift.NewTCompactProtocolFactory().GetProtocol(t2) 74 | 75 | deser := &thrift.TDeserializer{ 76 | Transport: t2, 77 | Protocol: p2, 78 | } 79 | 80 | b := tutorial.NewWork() 81 | deser.Transport.Close() // resets underlying bytes.Buffer 82 | err = deser.Read(b, by) 83 | panicOn(err) 84 | fmt.Printf("b = '%#v'\n", b) 85 | } 86 | 87 | func panicOn(err error) { 88 | if err != nil { 89 | panic(err) 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/client/client.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import ( 23 | "crypto/tls" 24 | "fmt" 25 | 26 | "tutorial" 27 | 28 | "git.apache.org/thrift.git/lib/go/thrift" 29 | ) 30 | 31 | func handleClient(client *tutorial.CalculatorClient) (err error) { 32 | client.Ping() 33 | fmt.Println("ping()") 34 | 35 | sum, _ := client.Add(1, 1) 36 | fmt.Print("1+1=", sum, "\n") 37 | 38 | work := tutorial.NewWork() 39 | work.Op = tutorial.Operation_DIVIDE 40 | work.Num1 = 1 41 | work.Num2 = 0 42 | quotient, err := client.Calculate(1, work) 43 | if err != nil { 44 | switch v := err.(type) { 45 | case *tutorial.InvalidOperation: 46 | fmt.Println("Invalid operation:", v) 47 | default: 48 | fmt.Println("Error during operation:", err) 49 | } 50 | return err 51 | } else { 52 | fmt.Println("Whoa we can divide by 0 with new value:", quotient) 53 | } 54 | 55 | work.Op = tutorial.Operation_SUBTRACT 56 | work.Num1 = 15 57 | work.Num2 = 10 58 | diff, err := client.Calculate(1, work) 59 | if err != nil { 60 | switch v := err.(type) { 61 | case *tutorial.InvalidOperation: 62 | fmt.Println("Invalid operation:", v) 63 | default: 64 | fmt.Println("Error during operation:", err) 65 | } 66 | return err 67 | } else { 68 | fmt.Print("15-10=", diff, "\n") 69 | } 70 | 71 | log, err := client.GetStruct(1) 72 | if err != nil { 73 | fmt.Println("Unable to get struct:", err) 74 | return err 75 | } else { 76 | fmt.Println("Check log:", log.Value) 77 | } 78 | return err 79 | } 80 | 81 | func runClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error { 82 | var transport thrift.TTransport 83 | var err error 84 | if secure { 85 | cfg := new(tls.Config) 86 | cfg.InsecureSkipVerify = true 87 | transport, err = thrift.NewTSSLSocket(addr, cfg) 88 | } else { 89 | transport, err = thrift.NewTSocket(addr) 90 | } 91 | if err != nil { 92 | fmt.Println("Error opening socket:", err) 93 | return err 94 | } 95 | if transport == nil { 96 | return fmt.Errorf("Error opening socket, got nil transport. Is server available?") 97 | } 98 | transport = transportFactory.GetTransport(transport) 99 | if transport == nil { 100 | return fmt.Errorf("Error from transportFactory.GetTransport(), got nil transport. Is server available?") 101 | } 102 | 103 | err = transport.Open() 104 | if err != nil { 105 | return err 106 | } 107 | defer transport.Close() 108 | 109 | return handleClient(tutorial.NewCalculatorClientFactory(transport, protocolFactory)) 110 | } 111 | -------------------------------------------------------------------------------- /src/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import ( 23 | "flag" 24 | "fmt" 25 | "os" 26 | 27 | "git.apache.org/thrift.git/lib/go/thrift" 28 | ) 29 | 30 | func Usage() { 31 | fmt.Fprint(os.Stderr, "Usage of ", os.Args[0], ":\n") 32 | flag.PrintDefaults() 33 | fmt.Fprint(os.Stderr, "\n") 34 | } 35 | 36 | func main() { 37 | flag.Usage = Usage 38 | // always be a client in this copy 39 | //server := flag.Bool("server", false, "Run server") 40 | protocol := flag.String("P", "binary", "Specify the protocol (binary, compact, json, simplejson)") 41 | framed := flag.Bool("framed", false, "Use framed transport") 42 | buffered := flag.Bool("buffered", false, "Use buffered transport") 43 | addr := flag.String("addr", "localhost:9090", "Address to listen to") 44 | secure := flag.Bool("secure", false, "Use tls secure transport") 45 | 46 | flag.Parse() 47 | 48 | var protocolFactory thrift.TProtocolFactory 49 | switch *protocol { 50 | case "compact": 51 | protocolFactory = thrift.NewTCompactProtocolFactory() 52 | case "simplejson": 53 | protocolFactory = thrift.NewTSimpleJSONProtocolFactory() 54 | case "json": 55 | protocolFactory = thrift.NewTJSONProtocolFactory() 56 | case "binary", "": 57 | protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() 58 | default: 59 | fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n") 60 | Usage() 61 | os.Exit(1) 62 | } 63 | 64 | var transportFactory thrift.TTransportFactory 65 | if *buffered { 66 | transportFactory = thrift.NewTBufferedTransportFactory(8192) 67 | } else { 68 | transportFactory = thrift.NewTTransportFactory() 69 | } 70 | 71 | if *framed { 72 | transportFactory = thrift.NewTFramedTransportFactory(transportFactory) 73 | } 74 | 75 | // always be client 76 | fmt.Printf("*secure = '%v'\n", *secure) 77 | fmt.Printf("*addr = '%v'\n", *addr) 78 | if err := runClient(transportFactory, protocolFactory, *addr, *secure); err != nil { 79 | fmt.Println("error running client:", err) 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/server/handler.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import ( 23 | "fmt" 24 | "shared" 25 | "strconv" 26 | "tutorial" 27 | ) 28 | 29 | type CalculatorHandler struct { 30 | log map[int]*shared.SharedStruct 31 | } 32 | 33 | func NewCalculatorHandler() *CalculatorHandler { 34 | return &CalculatorHandler{log: make(map[int]*shared.SharedStruct)} 35 | } 36 | 37 | func (p *CalculatorHandler) Ping() (err error) { 38 | fmt.Print("ping()\n") 39 | return nil 40 | } 41 | 42 | func (p *CalculatorHandler) Add(num1 int32, num2 int32) (retval17 int32, err error) { 43 | fmt.Print("add(", num1, ",", num2, ")\n") 44 | return num1 + num2, nil 45 | } 46 | 47 | func (p *CalculatorHandler) Calculate(logid int32, w *tutorial.Work) (val int32, err error) { 48 | fmt.Print("calculate(", logid, ", {", w.Op, ",", w.Num1, ",", w.Num2, "})\n") 49 | switch w.Op { 50 | case tutorial.Operation_ADD: 51 | val = w.Num1 + w.Num2 52 | break 53 | case tutorial.Operation_SUBTRACT: 54 | val = w.Num1 - w.Num2 55 | break 56 | case tutorial.Operation_MULTIPLY: 57 | val = w.Num1 * w.Num2 58 | break 59 | case tutorial.Operation_DIVIDE: 60 | if w.Num2 == 0 { 61 | ouch := tutorial.NewInvalidOperation() 62 | ouch.WhatOp = int32(w.Op) 63 | ouch.Why = "Cannot divide by 0" 64 | err = ouch 65 | return 66 | } 67 | val = w.Num1 / w.Num2 68 | break 69 | default: 70 | ouch := tutorial.NewInvalidOperation() 71 | ouch.WhatOp = int32(w.Op) 72 | ouch.Why = "Unknown operation" 73 | err = ouch 74 | return 75 | } 76 | entry := shared.NewSharedStruct() 77 | entry.Key = logid 78 | entry.Value = strconv.Itoa(int(val)) 79 | k := int(logid) 80 | /* 81 | oldvalue, exists := p.log[k] 82 | if exists { 83 | fmt.Print("Replacing ", oldvalue, " with ", entry, " for key ", k, "\n") 84 | } else { 85 | fmt.Print("Adding ", entry, " for key ", k, "\n") 86 | } 87 | */ 88 | p.log[k] = entry 89 | return val, err 90 | } 91 | 92 | func (p *CalculatorHandler) GetStruct(key int32) (*shared.SharedStruct, error) { 93 | fmt.Print("getStruct(", key, ")\n") 94 | v, _ := p.log[int(key)] 95 | return v, nil 96 | } 97 | 98 | func (p *CalculatorHandler) Zip() (err error) { 99 | fmt.Print("zip()\n") 100 | return nil 101 | } 102 | -------------------------------------------------------------------------------- /src/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import ( 23 | "flag" 24 | "fmt" 25 | "os" 26 | 27 | "git.apache.org/thrift.git/lib/go/thrift" 28 | ) 29 | 30 | func Usage() { 31 | fmt.Fprint(os.Stderr, "Usage of ", os.Args[0], ":\n") 32 | flag.PrintDefaults() 33 | fmt.Fprint(os.Stderr, "\n") 34 | } 35 | 36 | func main() { 37 | flag.Usage = Usage 38 | protocol := flag.String("P", "binary", "Specify the protocol (binary, compact, json, simplejson)") 39 | framed := flag.Bool("framed", false, "Use framed transport") 40 | buffered := flag.Bool("buffered", false, "Use buffered transport") 41 | addr := flag.String("addr", "localhost:9090", "Address to listen to") 42 | secure := flag.Bool("secure", false, "Use tls secure transport") 43 | 44 | flag.Parse() 45 | 46 | var protocolFactory thrift.TProtocolFactory 47 | switch *protocol { 48 | case "compact": 49 | protocolFactory = thrift.NewTCompactProtocolFactory() 50 | case "simplejson": 51 | protocolFactory = thrift.NewTSimpleJSONProtocolFactory() 52 | case "json": 53 | protocolFactory = thrift.NewTJSONProtocolFactory() 54 | case "binary", "": 55 | protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() 56 | default: 57 | fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n") 58 | Usage() 59 | os.Exit(1) 60 | } 61 | 62 | var transportFactory thrift.TTransportFactory 63 | if *buffered { 64 | transportFactory = thrift.NewTBufferedTransportFactory(8192) 65 | } else { 66 | transportFactory = thrift.NewTTransportFactory() 67 | } 68 | 69 | if *framed { 70 | transportFactory = thrift.NewTFramedTransportFactory(transportFactory) 71 | } 72 | 73 | // always run server here 74 | if err := runServer(transportFactory, protocolFactory, *addr, *secure); err != nil { 75 | fmt.Println("error running server:", err) 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/server/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import ( 23 | "crypto/tls" 24 | "fmt" 25 | "tutorial" 26 | 27 | "git.apache.org/thrift.git/lib/go/thrift" 28 | ) 29 | 30 | func runServer(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error { 31 | var transport thrift.TServerTransport 32 | var err error 33 | if secure { 34 | cfg := new(tls.Config) 35 | if cert, err := tls.LoadX509KeyPair("keys/server.crt", "keys/server.key"); err == nil { 36 | cfg.Certificates = append(cfg.Certificates, cert) 37 | } else { 38 | return err 39 | } 40 | transport, err = thrift.NewTSSLServerSocket(addr, cfg) 41 | } else { 42 | transport, err = thrift.NewTServerSocket(addr) 43 | } 44 | 45 | if err != nil { 46 | return err 47 | } 48 | fmt.Printf("%T\n", transport) 49 | handler := NewCalculatorHandler() 50 | processor := tutorial.NewCalculatorProcessor(handler) 51 | server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory) 52 | 53 | fmt.Println("Starting the simple server... on ", addr) 54 | return server.Serve() 55 | } 56 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/application_exception.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | const ( 23 | UNKNOWN_APPLICATION_EXCEPTION = 0 24 | UNKNOWN_METHOD = 1 25 | INVALID_MESSAGE_TYPE_EXCEPTION = 2 26 | WRONG_METHOD_NAME = 3 27 | BAD_SEQUENCE_ID = 4 28 | MISSING_RESULT = 5 29 | INTERNAL_ERROR = 6 30 | PROTOCOL_ERROR = 7 31 | ) 32 | 33 | // Application level Thrift exception 34 | type TApplicationException interface { 35 | TException 36 | TypeId() int32 37 | Read(iprot TProtocol) (TApplicationException, error) 38 | Write(oprot TProtocol) error 39 | } 40 | 41 | type tApplicationException struct { 42 | message string 43 | type_ int32 44 | } 45 | 46 | func (e tApplicationException) Error() string { 47 | return e.message 48 | } 49 | 50 | func NewTApplicationException(type_ int32, message string) TApplicationException { 51 | return &tApplicationException{message, type_} 52 | } 53 | 54 | func (p *tApplicationException) TypeId() int32 { 55 | return p.type_ 56 | } 57 | 58 | func (p *tApplicationException) Read(iprot TProtocol) (TApplicationException, error) { 59 | _, err := iprot.ReadStructBegin() 60 | if err != nil { 61 | return nil, err 62 | } 63 | 64 | message := "" 65 | type_ := int32(UNKNOWN_APPLICATION_EXCEPTION) 66 | 67 | for { 68 | _, ttype, id, err := iprot.ReadFieldBegin() 69 | if err != nil { 70 | return nil, err 71 | } 72 | if ttype == STOP { 73 | break 74 | } 75 | switch id { 76 | case 1: 77 | if ttype == STRING { 78 | if message, err = iprot.ReadString(); err != nil { 79 | return nil, err 80 | } 81 | } else { 82 | if err = SkipDefaultDepth(iprot, ttype); err != nil { 83 | return nil, err 84 | } 85 | } 86 | case 2: 87 | if ttype == I32 { 88 | if type_, err = iprot.ReadI32(); err != nil { 89 | return nil, err 90 | } 91 | } else { 92 | if err = SkipDefaultDepth(iprot, ttype); err != nil { 93 | return nil, err 94 | } 95 | } 96 | default: 97 | if err = SkipDefaultDepth(iprot, ttype); err != nil { 98 | return nil, err 99 | } 100 | } 101 | if err = iprot.ReadFieldEnd(); err != nil { 102 | return nil, err 103 | } 104 | } 105 | return NewTApplicationException(type_, message), iprot.ReadStructEnd() 106 | } 107 | 108 | func (p *tApplicationException) Write(oprot TProtocol) (err error) { 109 | err = oprot.WriteStructBegin("TApplicationException") 110 | if len(p.Error()) > 0 { 111 | err = oprot.WriteFieldBegin("message", STRING, 1) 112 | if err != nil { 113 | return 114 | } 115 | err = oprot.WriteString(p.Error()) 116 | if err != nil { 117 | return 118 | } 119 | err = oprot.WriteFieldEnd() 120 | if err != nil { 121 | return 122 | } 123 | } 124 | err = oprot.WriteFieldBegin("type", I32, 2) 125 | if err != nil { 126 | return 127 | } 128 | err = oprot.WriteI32(p.type_) 129 | if err != nil { 130 | return 131 | } 132 | err = oprot.WriteFieldEnd() 133 | if err != nil { 134 | return 135 | } 136 | err = oprot.WriteFieldStop() 137 | if err != nil { 138 | return 139 | } 140 | err = oprot.WriteStructEnd() 141 | return 142 | } 143 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/application_exception_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "testing" 24 | ) 25 | 26 | func TestTApplicationException(t *testing.T) { 27 | exc := NewTApplicationException(UNKNOWN_APPLICATION_EXCEPTION, "") 28 | if exc.Error() != "" { 29 | t.Fatalf("Expected empty string for exception but found '%s'", exc.Error()) 30 | } 31 | if exc.TypeId() != UNKNOWN_APPLICATION_EXCEPTION { 32 | t.Fatalf("Expected type UNKNOWN for exception but found '%s'", exc.TypeId()) 33 | } 34 | exc = NewTApplicationException(WRONG_METHOD_NAME, "junk_method") 35 | if exc.Error() != "junk_method" { 36 | t.Fatalf("Expected 'junk_method' for exception but found '%s'", exc.Error()) 37 | } 38 | if exc.TypeId() != WRONG_METHOD_NAME { 39 | t.Fatalf("Expected type WRONG_METHOD_NAME for exception but found '%s'", exc.TypeId()) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/binary_protocol.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "encoding/binary" 24 | "errors" 25 | "fmt" 26 | "io" 27 | "math" 28 | ) 29 | 30 | type TBinaryProtocol struct { 31 | trans TRichTransport 32 | origTransport TTransport 33 | reader io.Reader 34 | writer io.Writer 35 | strictRead bool 36 | strictWrite bool 37 | buffer [64]byte 38 | } 39 | 40 | type TBinaryProtocolFactory struct { 41 | strictRead bool 42 | strictWrite bool 43 | } 44 | 45 | func NewTBinaryProtocolTransport(t TTransport) *TBinaryProtocol { 46 | return NewTBinaryProtocol(t, false, true) 47 | } 48 | 49 | func NewTBinaryProtocol(t TTransport, strictRead, strictWrite bool) *TBinaryProtocol { 50 | p := &TBinaryProtocol{origTransport: t, strictRead: strictRead, strictWrite: strictWrite} 51 | if et, ok := t.(TRichTransport); ok { 52 | p.trans = et 53 | } else { 54 | p.trans = NewTRichTransport(t) 55 | } 56 | p.reader = p.trans 57 | p.writer = p.trans 58 | return p 59 | } 60 | 61 | func NewTBinaryProtocolFactoryDefault() *TBinaryProtocolFactory { 62 | return NewTBinaryProtocolFactory(false, true) 63 | } 64 | 65 | func NewTBinaryProtocolFactory(strictRead, strictWrite bool) *TBinaryProtocolFactory { 66 | return &TBinaryProtocolFactory{strictRead: strictRead, strictWrite: strictWrite} 67 | } 68 | 69 | func (p *TBinaryProtocolFactory) GetProtocol(t TTransport) TProtocol { 70 | return NewTBinaryProtocol(t, p.strictRead, p.strictWrite) 71 | } 72 | 73 | /** 74 | * Writing Methods 75 | */ 76 | 77 | func (p *TBinaryProtocol) WriteMessageBegin(name string, typeId TMessageType, seqId int32) error { 78 | if p.strictWrite { 79 | version := uint32(VERSION_1) | uint32(typeId) 80 | e := p.WriteI32(int32(version)) 81 | if e != nil { 82 | return e 83 | } 84 | e = p.WriteString(name) 85 | if e != nil { 86 | return e 87 | } 88 | e = p.WriteI32(seqId) 89 | return e 90 | } else { 91 | e := p.WriteString(name) 92 | if e != nil { 93 | return e 94 | } 95 | e = p.WriteByte(int8(typeId)) 96 | if e != nil { 97 | return e 98 | } 99 | e = p.WriteI32(seqId) 100 | return e 101 | } 102 | return nil 103 | } 104 | 105 | func (p *TBinaryProtocol) WriteMessageEnd() error { 106 | return nil 107 | } 108 | 109 | func (p *TBinaryProtocol) WriteStructBegin(name string) error { 110 | return nil 111 | } 112 | 113 | func (p *TBinaryProtocol) WriteStructEnd() error { 114 | return nil 115 | } 116 | 117 | func (p *TBinaryProtocol) WriteFieldBegin(name string, typeId TType, id int16) error { 118 | e := p.WriteByte(int8(typeId)) 119 | if e != nil { 120 | return e 121 | } 122 | e = p.WriteI16(id) 123 | return e 124 | } 125 | 126 | func (p *TBinaryProtocol) WriteFieldEnd() error { 127 | return nil 128 | } 129 | 130 | func (p *TBinaryProtocol) WriteFieldStop() error { 131 | e := p.WriteByte(STOP) 132 | return e 133 | } 134 | 135 | func (p *TBinaryProtocol) WriteMapBegin(keyType TType, valueType TType, size int) error { 136 | e := p.WriteByte(int8(keyType)) 137 | if e != nil { 138 | return e 139 | } 140 | e = p.WriteByte(int8(valueType)) 141 | if e != nil { 142 | return e 143 | } 144 | e = p.WriteI32(int32(size)) 145 | return e 146 | } 147 | 148 | func (p *TBinaryProtocol) WriteMapEnd() error { 149 | return nil 150 | } 151 | 152 | func (p *TBinaryProtocol) WriteListBegin(elemType TType, size int) error { 153 | e := p.WriteByte(int8(elemType)) 154 | if e != nil { 155 | return e 156 | } 157 | e = p.WriteI32(int32(size)) 158 | return e 159 | } 160 | 161 | func (p *TBinaryProtocol) WriteListEnd() error { 162 | return nil 163 | } 164 | 165 | func (p *TBinaryProtocol) WriteSetBegin(elemType TType, size int) error { 166 | e := p.WriteByte(int8(elemType)) 167 | if e != nil { 168 | return e 169 | } 170 | e = p.WriteI32(int32(size)) 171 | return e 172 | } 173 | 174 | func (p *TBinaryProtocol) WriteSetEnd() error { 175 | return nil 176 | } 177 | 178 | func (p *TBinaryProtocol) WriteBool(value bool) error { 179 | if value { 180 | return p.WriteByte(1) 181 | } 182 | return p.WriteByte(0) 183 | } 184 | 185 | func (p *TBinaryProtocol) WriteByte(value int8) error { 186 | e := p.trans.WriteByte(byte(value)) 187 | return NewTProtocolException(e) 188 | } 189 | 190 | func (p *TBinaryProtocol) WriteI16(value int16) error { 191 | v := p.buffer[0:2] 192 | binary.BigEndian.PutUint16(v, uint16(value)) 193 | _, e := p.writer.Write(v) 194 | return NewTProtocolException(e) 195 | } 196 | 197 | func (p *TBinaryProtocol) WriteI32(value int32) error { 198 | v := p.buffer[0:4] 199 | binary.BigEndian.PutUint32(v, uint32(value)) 200 | _, e := p.writer.Write(v) 201 | return NewTProtocolException(e) 202 | } 203 | 204 | func (p *TBinaryProtocol) WriteI64(value int64) error { 205 | v := p.buffer[0:8] 206 | binary.BigEndian.PutUint64(v, uint64(value)) 207 | _, err := p.writer.Write(v) 208 | return NewTProtocolException(err) 209 | } 210 | 211 | func (p *TBinaryProtocol) WriteDouble(value float64) error { 212 | return p.WriteI64(int64(math.Float64bits(value))) 213 | } 214 | 215 | func (p *TBinaryProtocol) WriteString(value string) error { 216 | e := p.WriteI32(int32(len(value))) 217 | if e != nil { 218 | return e 219 | } 220 | _, err := p.trans.WriteString(value) 221 | return NewTProtocolException(err) 222 | } 223 | 224 | func (p *TBinaryProtocol) WriteBinary(value []byte) error { 225 | e := p.WriteI32(int32(len(value))) 226 | if e != nil { 227 | return e 228 | } 229 | _, err := p.writer.Write(value) 230 | return NewTProtocolException(err) 231 | } 232 | 233 | /** 234 | * Reading methods 235 | */ 236 | 237 | func (p *TBinaryProtocol) ReadMessageBegin() (name string, typeId TMessageType, seqId int32, err error) { 238 | size, e := p.ReadI32() 239 | if e != nil { 240 | return "", typeId, 0, NewTProtocolException(e) 241 | } 242 | if size < 0 { 243 | typeId = TMessageType(size & 0x0ff) 244 | version := int64(int64(size) & VERSION_MASK) 245 | if version != VERSION_1 { 246 | return name, typeId, seqId, NewTProtocolExceptionWithType(BAD_VERSION, fmt.Errorf("Bad version in ReadMessageBegin")) 247 | } 248 | name, e = p.ReadString() 249 | if e != nil { 250 | return name, typeId, seqId, NewTProtocolException(e) 251 | } 252 | seqId, e = p.ReadI32() 253 | if e != nil { 254 | return name, typeId, seqId, NewTProtocolException(e) 255 | } 256 | return name, typeId, seqId, nil 257 | } 258 | if p.strictRead { 259 | return name, typeId, seqId, NewTProtocolExceptionWithType(BAD_VERSION, fmt.Errorf("Missing version in ReadMessageBegin")) 260 | } 261 | name, e2 := p.readStringBody(size) 262 | if e2 != nil { 263 | return name, typeId, seqId, e2 264 | } 265 | b, e3 := p.ReadByte() 266 | if e3 != nil { 267 | return name, typeId, seqId, e3 268 | } 269 | typeId = TMessageType(b) 270 | seqId, e4 := p.ReadI32() 271 | if e4 != nil { 272 | return name, typeId, seqId, e4 273 | } 274 | return name, typeId, seqId, nil 275 | } 276 | 277 | func (p *TBinaryProtocol) ReadMessageEnd() error { 278 | return nil 279 | } 280 | 281 | func (p *TBinaryProtocol) ReadStructBegin() (name string, err error) { 282 | return 283 | } 284 | 285 | func (p *TBinaryProtocol) ReadStructEnd() error { 286 | return nil 287 | } 288 | 289 | func (p *TBinaryProtocol) ReadFieldBegin() (name string, typeId TType, seqId int16, err error) { 290 | t, err := p.ReadByte() 291 | typeId = TType(t) 292 | if err != nil { 293 | return name, typeId, seqId, err 294 | } 295 | if t != STOP { 296 | seqId, err = p.ReadI16() 297 | } 298 | return name, typeId, seqId, err 299 | } 300 | 301 | func (p *TBinaryProtocol) ReadFieldEnd() error { 302 | return nil 303 | } 304 | 305 | var invalidDataLength = NewTProtocolExceptionWithType(INVALID_DATA, errors.New("Invalid data length")) 306 | 307 | func (p *TBinaryProtocol) ReadMapBegin() (kType, vType TType, size int, err error) { 308 | k, e := p.ReadByte() 309 | if e != nil { 310 | err = NewTProtocolException(e) 311 | return 312 | } 313 | kType = TType(k) 314 | v, e := p.ReadByte() 315 | if e != nil { 316 | err = NewTProtocolException(e) 317 | return 318 | } 319 | vType = TType(v) 320 | size32, e := p.ReadI32() 321 | if e != nil { 322 | err = NewTProtocolException(e) 323 | return 324 | } 325 | if size32 < 0 { 326 | err = invalidDataLength 327 | return 328 | } 329 | size = int(size32) 330 | return kType, vType, size, nil 331 | } 332 | 333 | func (p *TBinaryProtocol) ReadMapEnd() error { 334 | return nil 335 | } 336 | 337 | func (p *TBinaryProtocol) ReadListBegin() (elemType TType, size int, err error) { 338 | b, e := p.ReadByte() 339 | if e != nil { 340 | err = NewTProtocolException(e) 341 | return 342 | } 343 | elemType = TType(b) 344 | size32, e := p.ReadI32() 345 | if e != nil { 346 | err = NewTProtocolException(e) 347 | return 348 | } 349 | if size32 < 0 { 350 | err = invalidDataLength 351 | return 352 | } 353 | size = int(size32) 354 | 355 | return 356 | } 357 | 358 | func (p *TBinaryProtocol) ReadListEnd() error { 359 | return nil 360 | } 361 | 362 | func (p *TBinaryProtocol) ReadSetBegin() (elemType TType, size int, err error) { 363 | b, e := p.ReadByte() 364 | if e != nil { 365 | err = NewTProtocolException(e) 366 | return 367 | } 368 | elemType = TType(b) 369 | size32, e := p.ReadI32() 370 | if e != nil { 371 | err = NewTProtocolException(e) 372 | return 373 | } 374 | if size32 < 0 { 375 | err = invalidDataLength 376 | return 377 | } 378 | size = int(size32) 379 | return elemType, size, nil 380 | } 381 | 382 | func (p *TBinaryProtocol) ReadSetEnd() error { 383 | return nil 384 | } 385 | 386 | func (p *TBinaryProtocol) ReadBool() (bool, error) { 387 | b, e := p.ReadByte() 388 | v := true 389 | if b != 1 { 390 | v = false 391 | } 392 | return v, e 393 | } 394 | 395 | func (p *TBinaryProtocol) ReadByte() (int8, error) { 396 | v, err := p.trans.ReadByte() 397 | return int8(v), err 398 | } 399 | 400 | func (p *TBinaryProtocol) ReadI16() (value int16, err error) { 401 | buf := p.buffer[0:2] 402 | err = p.readAll(buf) 403 | value = int16(binary.BigEndian.Uint16(buf)) 404 | return value, err 405 | } 406 | 407 | func (p *TBinaryProtocol) ReadI32() (value int32, err error) { 408 | buf := p.buffer[0:4] 409 | err = p.readAll(buf) 410 | value = int32(binary.BigEndian.Uint32(buf)) 411 | return value, err 412 | } 413 | 414 | func (p *TBinaryProtocol) ReadI64() (value int64, err error) { 415 | buf := p.buffer[0:8] 416 | err = p.readAll(buf) 417 | value = int64(binary.BigEndian.Uint64(buf)) 418 | return value, err 419 | } 420 | 421 | func (p *TBinaryProtocol) ReadDouble() (value float64, err error) { 422 | buf := p.buffer[0:8] 423 | err = p.readAll(buf) 424 | value = math.Float64frombits(binary.BigEndian.Uint64(buf)) 425 | return value, err 426 | } 427 | 428 | func (p *TBinaryProtocol) ReadString() (value string, err error) { 429 | size, e := p.ReadI32() 430 | if e != nil { 431 | return "", e 432 | } 433 | if size < 0 { 434 | err = invalidDataLength 435 | return 436 | } 437 | 438 | return p.readStringBody(size) 439 | } 440 | 441 | func (p *TBinaryProtocol) ReadBinary() ([]byte, error) { 442 | size, e := p.ReadI32() 443 | if e != nil { 444 | return nil, e 445 | } 446 | if size < 0 { 447 | return nil, invalidDataLength 448 | } 449 | if uint64(size) > p.trans.RemainingBytes() { 450 | return nil, invalidDataLength 451 | } 452 | 453 | isize := int(size) 454 | buf := make([]byte, isize) 455 | _, err := io.ReadFull(p.trans, buf) 456 | return buf, NewTProtocolException(err) 457 | } 458 | 459 | func (p *TBinaryProtocol) Flush() (err error) { 460 | return NewTProtocolException(p.trans.Flush()) 461 | } 462 | 463 | func (p *TBinaryProtocol) Skip(fieldType TType) (err error) { 464 | return SkipDefaultDepth(p, fieldType) 465 | } 466 | 467 | func (p *TBinaryProtocol) Transport() TTransport { 468 | return p.origTransport 469 | } 470 | 471 | func (p *TBinaryProtocol) readAll(buf []byte) error { 472 | _, err := io.ReadFull(p.reader, buf) 473 | return NewTProtocolException(err) 474 | } 475 | 476 | func (p *TBinaryProtocol) readStringBody(size int32) (value string, err error) { 477 | if size < 0 { 478 | return "", nil 479 | } 480 | if uint64(size) > p.trans.RemainingBytes() { 481 | return "", invalidDataLength 482 | } 483 | var buf []byte 484 | if int(size) <= len(p.buffer) { 485 | buf = p.buffer[0:size] 486 | } else { 487 | buf = make([]byte, size) 488 | } 489 | _, e := io.ReadFull(p.trans, buf) 490 | return string(buf), NewTProtocolException(e) 491 | } 492 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/binary_protocol_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "testing" 24 | ) 25 | 26 | func TestReadWriteBinaryProtocol(t *testing.T) { 27 | ReadWriteProtocolTest(t, NewTBinaryProtocolFactoryDefault()) 28 | } 29 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/buffered_transport.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "bufio" 24 | ) 25 | 26 | type TBufferedTransportFactory struct { 27 | size int 28 | } 29 | 30 | type TBufferedTransport struct { 31 | bufio.ReadWriter 32 | tp TTransport 33 | } 34 | 35 | func (p *TBufferedTransportFactory) GetTransport(trans TTransport) TTransport { 36 | return NewTBufferedTransport(trans, p.size) 37 | } 38 | 39 | func NewTBufferedTransportFactory(bufferSize int) *TBufferedTransportFactory { 40 | return &TBufferedTransportFactory{size: bufferSize} 41 | } 42 | 43 | func NewTBufferedTransport(trans TTransport, bufferSize int) *TBufferedTransport { 44 | return &TBufferedTransport{ 45 | ReadWriter: bufio.ReadWriter{ 46 | Reader: bufio.NewReaderSize(trans, bufferSize), 47 | Writer: bufio.NewWriterSize(trans, bufferSize), 48 | }, 49 | tp: trans, 50 | } 51 | } 52 | 53 | func (p *TBufferedTransport) IsOpen() bool { 54 | return p.tp.IsOpen() 55 | } 56 | 57 | func (p *TBufferedTransport) Open() (err error) { 58 | return p.tp.Open() 59 | } 60 | 61 | func (p *TBufferedTransport) Close() (err error) { 62 | return p.tp.Close() 63 | } 64 | 65 | func (p *TBufferedTransport) Flush() error { 66 | if err := p.ReadWriter.Flush(); err != nil { 67 | return err 68 | } 69 | return p.tp.Flush() 70 | } 71 | 72 | func (p *TBufferedTransport) RemainingBytes() (num_bytes uint64) { 73 | return p.tp.RemainingBytes() 74 | } 75 | 76 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/buffered_transport_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "testing" 24 | ) 25 | 26 | func TestBufferedTransport(t *testing.T) { 27 | trans := NewTBufferedTransport(NewTMemoryBuffer(), 10240) 28 | TransportTest(t, trans, trans) 29 | } 30 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/compact_protocol_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "bytes" 24 | "testing" 25 | ) 26 | 27 | func TestReadWriteCompactProtocol(t *testing.T) { 28 | ReadWriteProtocolTest(t, NewTCompactProtocolFactory()) 29 | transports := []TTransport{ 30 | NewTMemoryBuffer(), 31 | NewStreamTransportRW(bytes.NewBuffer(make([]byte, 0, 16384))), 32 | NewTFramedTransport(NewTMemoryBuffer()), 33 | } 34 | for _, trans := range transports { 35 | p := NewTCompactProtocol(trans); 36 | ReadWriteBool(t, p, trans); 37 | p = NewTCompactProtocol(trans); 38 | ReadWriteByte(t, p, trans); 39 | p = NewTCompactProtocol(trans); 40 | ReadWriteI16(t, p, trans); 41 | p = NewTCompactProtocol(trans); 42 | ReadWriteI32(t, p, trans); 43 | p = NewTCompactProtocol(trans); 44 | ReadWriteI64(t, p, trans); 45 | p = NewTCompactProtocol(trans); 46 | ReadWriteDouble(t, p, trans); 47 | p = NewTCompactProtocol(trans); 48 | ReadWriteString(t, p, trans); 49 | p = NewTCompactProtocol(trans); 50 | ReadWriteBinary(t, p, trans); 51 | trans.Close(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/debug_protocol.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "log" 24 | ) 25 | 26 | type TDebugProtocol struct { 27 | Delegate TProtocol 28 | LogPrefix string 29 | } 30 | 31 | type TDebugProtocolFactory struct { 32 | Underlying TProtocolFactory 33 | LogPrefix string 34 | } 35 | 36 | func NewTDebugProtocolFactory(underlying TProtocolFactory, logPrefix string) *TDebugProtocolFactory { 37 | return &TDebugProtocolFactory{ 38 | Underlying: underlying, 39 | LogPrefix: logPrefix, 40 | } 41 | } 42 | 43 | func (t *TDebugProtocolFactory) GetProtocol(trans TTransport) TProtocol { 44 | return &TDebugProtocol{ 45 | Delegate: t.Underlying.GetProtocol(trans), 46 | LogPrefix: t.LogPrefix, 47 | } 48 | } 49 | 50 | func (tdp *TDebugProtocol) WriteMessageBegin(name string, typeId TMessageType, seqid int32) error { 51 | err := tdp.Delegate.WriteMessageBegin(name, typeId, seqid) 52 | log.Printf("%sWriteMessageBegin(name=%#v, typeId=%#v, seqid=%#v) => %#v", tdp.LogPrefix, name, typeId, seqid, err) 53 | return err 54 | } 55 | func (tdp *TDebugProtocol) WriteMessageEnd() error { 56 | err := tdp.Delegate.WriteMessageEnd() 57 | log.Printf("%sWriteMessageEnd() => %#v", tdp.LogPrefix, err) 58 | return err 59 | } 60 | func (tdp *TDebugProtocol) WriteStructBegin(name string) error { 61 | err := tdp.Delegate.WriteStructBegin(name) 62 | log.Printf("%sWriteStructBegin(name=%#v) => %#v", tdp.LogPrefix, name, err) 63 | return err 64 | } 65 | func (tdp *TDebugProtocol) WriteStructEnd() error { 66 | err := tdp.Delegate.WriteStructEnd() 67 | log.Printf("%sWriteStructEnd() => %#v", tdp.LogPrefix, err) 68 | return err 69 | } 70 | func (tdp *TDebugProtocol) WriteFieldBegin(name string, typeId TType, id int16) error { 71 | err := tdp.Delegate.WriteFieldBegin(name, typeId, id) 72 | log.Printf("%sWriteFieldBegin(name=%#v, typeId=%#v, id%#v) => %#v", tdp.LogPrefix, name, typeId, id, err) 73 | return err 74 | } 75 | func (tdp *TDebugProtocol) WriteFieldEnd() error { 76 | err := tdp.Delegate.WriteFieldEnd() 77 | log.Printf("%sWriteFieldEnd() => %#v", tdp.LogPrefix, err) 78 | return err 79 | } 80 | func (tdp *TDebugProtocol) WriteFieldStop() error { 81 | err := tdp.Delegate.WriteFieldStop() 82 | log.Printf("%sWriteFieldStop() => %#v", tdp.LogPrefix, err) 83 | return err 84 | } 85 | func (tdp *TDebugProtocol) WriteMapBegin(keyType TType, valueType TType, size int) error { 86 | err := tdp.Delegate.WriteMapBegin(keyType, valueType, size) 87 | log.Printf("%sWriteMapBegin(keyType=%#v, valueType=%#v, size=%#v) => %#v", tdp.LogPrefix, keyType, valueType, size, err) 88 | return err 89 | } 90 | func (tdp *TDebugProtocol) WriteMapEnd() error { 91 | err := tdp.Delegate.WriteMapEnd() 92 | log.Printf("%sWriteMapEnd() => %#v", tdp.LogPrefix, err) 93 | return err 94 | } 95 | func (tdp *TDebugProtocol) WriteListBegin(elemType TType, size int) error { 96 | err := tdp.Delegate.WriteListBegin(elemType, size) 97 | log.Printf("%sWriteListBegin(elemType=%#v, size=%#v) => %#v", tdp.LogPrefix, elemType, size, err) 98 | return err 99 | } 100 | func (tdp *TDebugProtocol) WriteListEnd() error { 101 | err := tdp.Delegate.WriteListEnd() 102 | log.Printf("%sWriteListEnd() => %#v", tdp.LogPrefix, err) 103 | return err 104 | } 105 | func (tdp *TDebugProtocol) WriteSetBegin(elemType TType, size int) error { 106 | err := tdp.Delegate.WriteSetBegin(elemType, size) 107 | log.Printf("%sWriteSetBegin(elemType=%#v, size=%#v) => %#v", tdp.LogPrefix, elemType, size, err) 108 | return err 109 | } 110 | func (tdp *TDebugProtocol) WriteSetEnd() error { 111 | err := tdp.Delegate.WriteSetEnd() 112 | log.Printf("%sWriteSetEnd() => %#v", tdp.LogPrefix, err) 113 | return err 114 | } 115 | func (tdp *TDebugProtocol) WriteBool(value bool) error { 116 | err := tdp.Delegate.WriteBool(value) 117 | log.Printf("%sWriteBool(value=%#v) => %#v", tdp.LogPrefix, value, err) 118 | return err 119 | } 120 | func (tdp *TDebugProtocol) WriteByte(value int8) error { 121 | err := tdp.Delegate.WriteByte(value) 122 | log.Printf("%sWriteByte(value=%#v) => %#v", tdp.LogPrefix, value, err) 123 | return err 124 | } 125 | func (tdp *TDebugProtocol) WriteI16(value int16) error { 126 | err := tdp.Delegate.WriteI16(value) 127 | log.Printf("%sWriteI16(value=%#v) => %#v", tdp.LogPrefix, value, err) 128 | return err 129 | } 130 | func (tdp *TDebugProtocol) WriteI32(value int32) error { 131 | err := tdp.Delegate.WriteI32(value) 132 | log.Printf("%sWriteI32(value=%#v) => %#v", tdp.LogPrefix, value, err) 133 | return err 134 | } 135 | func (tdp *TDebugProtocol) WriteI64(value int64) error { 136 | err := tdp.Delegate.WriteI64(value) 137 | log.Printf("%sWriteI64(value=%#v) => %#v", tdp.LogPrefix, value, err) 138 | return err 139 | } 140 | func (tdp *TDebugProtocol) WriteDouble(value float64) error { 141 | err := tdp.Delegate.WriteDouble(value) 142 | log.Printf("%sWriteDouble(value=%#v) => %#v", tdp.LogPrefix, value, err) 143 | return err 144 | } 145 | func (tdp *TDebugProtocol) WriteString(value string) error { 146 | err := tdp.Delegate.WriteString(value) 147 | log.Printf("%sWriteString(value=%#v) => %#v", tdp.LogPrefix, value, err) 148 | return err 149 | } 150 | func (tdp *TDebugProtocol) WriteBinary(value []byte) error { 151 | err := tdp.Delegate.WriteBinary(value) 152 | log.Printf("%sWriteBinary(value=%#v) => %#v", tdp.LogPrefix, value, err) 153 | return err 154 | } 155 | 156 | func (tdp *TDebugProtocol) ReadMessageBegin() (name string, typeId TMessageType, seqid int32, err error) { 157 | name, typeId, seqid, err = tdp.Delegate.ReadMessageBegin() 158 | log.Printf("%sReadMessageBegin() (name=%#v, typeId=%#v, seqid=%#v, err=%#v)", tdp.LogPrefix, name, typeId, seqid, err) 159 | return 160 | } 161 | func (tdp *TDebugProtocol) ReadMessageEnd() (err error) { 162 | err = tdp.Delegate.ReadMessageEnd() 163 | log.Printf("%sReadMessageEnd() err=%#v", tdp.LogPrefix, err) 164 | return 165 | } 166 | func (tdp *TDebugProtocol) ReadStructBegin() (name string, err error) { 167 | name, err = tdp.Delegate.ReadStructBegin() 168 | log.Printf("%sReadStructBegin() (name%#v, err=%#v)", tdp.LogPrefix, name, err) 169 | return 170 | } 171 | func (tdp *TDebugProtocol) ReadStructEnd() (err error) { 172 | err = tdp.Delegate.ReadStructEnd() 173 | log.Printf("%sReadStructEnd() err=%#v", tdp.LogPrefix, err) 174 | return 175 | } 176 | func (tdp *TDebugProtocol) ReadFieldBegin() (name string, typeId TType, id int16, err error) { 177 | name, typeId, id, err = tdp.Delegate.ReadFieldBegin() 178 | log.Printf("%sReadFieldBegin() (name=%#v, typeId=%#v, id=%#v, err=%#v)", tdp.LogPrefix, name, typeId, id, err) 179 | return 180 | } 181 | func (tdp *TDebugProtocol) ReadFieldEnd() (err error) { 182 | err = tdp.Delegate.ReadFieldEnd() 183 | log.Printf("%sReadFieldEnd() err=%#v", tdp.LogPrefix, err) 184 | return 185 | } 186 | func (tdp *TDebugProtocol) ReadMapBegin() (keyType TType, valueType TType, size int, err error) { 187 | keyType, valueType, size, err = tdp.Delegate.ReadMapBegin() 188 | log.Printf("%sReadMapBegin() (keyType=%#v, valueType=%#v, size=%#v, err=%#v)", tdp.LogPrefix, keyType, valueType, size, err) 189 | return 190 | } 191 | func (tdp *TDebugProtocol) ReadMapEnd() (err error) { 192 | err = tdp.Delegate.ReadMapEnd() 193 | log.Printf("%sReadMapEnd() err=%#v", tdp.LogPrefix, err) 194 | return 195 | } 196 | func (tdp *TDebugProtocol) ReadListBegin() (elemType TType, size int, err error) { 197 | elemType, size, err = tdp.Delegate.ReadListBegin() 198 | log.Printf("%sReadListBegin() (elemType=%#v, size=%#v, err=%#v)", tdp.LogPrefix, elemType, size, err) 199 | return 200 | } 201 | func (tdp *TDebugProtocol) ReadListEnd() (err error) { 202 | err = tdp.Delegate.ReadListEnd() 203 | log.Printf("%sReadListEnd() err=%#v", tdp.LogPrefix, err) 204 | return 205 | } 206 | func (tdp *TDebugProtocol) ReadSetBegin() (elemType TType, size int, err error) { 207 | elemType, size, err = tdp.Delegate.ReadSetBegin() 208 | log.Printf("%sReadSetBegin() (elemType=%#v, size=%#v, err=%#v)", tdp.LogPrefix, elemType, size, err) 209 | return 210 | } 211 | func (tdp *TDebugProtocol) ReadSetEnd() (err error) { 212 | err = tdp.Delegate.ReadSetEnd() 213 | log.Printf("%sReadSetEnd() err=%#v", tdp.LogPrefix, err) 214 | return 215 | } 216 | func (tdp *TDebugProtocol) ReadBool() (value bool, err error) { 217 | value, err = tdp.Delegate.ReadBool() 218 | log.Printf("%sReadBool() (value=%#v, err=%#v)", tdp.LogPrefix, value, err) 219 | return 220 | } 221 | func (tdp *TDebugProtocol) ReadByte() (value int8, err error) { 222 | value, err = tdp.Delegate.ReadByte() 223 | log.Printf("%sReadByte() (value=%#v, err=%#v)", tdp.LogPrefix, value, err) 224 | return 225 | } 226 | func (tdp *TDebugProtocol) ReadI16() (value int16, err error) { 227 | value, err = tdp.Delegate.ReadI16() 228 | log.Printf("%sReadI16() (value=%#v, err=%#v)", tdp.LogPrefix, value, err) 229 | return 230 | } 231 | func (tdp *TDebugProtocol) ReadI32() (value int32, err error) { 232 | value, err = tdp.Delegate.ReadI32() 233 | log.Printf("%sReadI32() (value=%#v, err=%#v)", tdp.LogPrefix, value, err) 234 | return 235 | } 236 | func (tdp *TDebugProtocol) ReadI64() (value int64, err error) { 237 | value, err = tdp.Delegate.ReadI64() 238 | log.Printf("%sReadI64() (value=%#v, err=%#v)", tdp.LogPrefix, value, err) 239 | return 240 | } 241 | func (tdp *TDebugProtocol) ReadDouble() (value float64, err error) { 242 | value, err = tdp.Delegate.ReadDouble() 243 | log.Printf("%sReadDouble() (value=%#v, err=%#v)", tdp.LogPrefix, value, err) 244 | return 245 | } 246 | func (tdp *TDebugProtocol) ReadString() (value string, err error) { 247 | value, err = tdp.Delegate.ReadString() 248 | log.Printf("%sReadString() (value=%#v, err=%#v)", tdp.LogPrefix, value, err) 249 | return 250 | } 251 | func (tdp *TDebugProtocol) ReadBinary() (value []byte, err error) { 252 | value, err = tdp.Delegate.ReadBinary() 253 | log.Printf("%sReadBinary() (value=%#v, err=%#v)", tdp.LogPrefix, value, err) 254 | return 255 | } 256 | func (tdp *TDebugProtocol) Skip(fieldType TType) (err error) { 257 | err = tdp.Delegate.Skip(fieldType) 258 | log.Printf("%sSkip(fieldType=%#v) (err=%#v)", tdp.LogPrefix, fieldType, err) 259 | return 260 | } 261 | func (tdp *TDebugProtocol) Flush() (err error) { 262 | err = tdp.Delegate.Flush() 263 | log.Printf("%sFlush() (err=%#v)", tdp.LogPrefix, err) 264 | return 265 | } 266 | 267 | func (tdp *TDebugProtocol) Transport() TTransport { 268 | return tdp.Delegate.Transport() 269 | } 270 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/deserializer.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | type TDeserializer struct { 23 | Transport TTransport 24 | Protocol TProtocol 25 | } 26 | 27 | func NewTDeserializer() *TDeserializer { 28 | var transport TTransport 29 | transport = NewTMemoryBufferLen(1024) 30 | 31 | protocol := NewTBinaryProtocolFactoryDefault().GetProtocol(transport) 32 | 33 | return &TDeserializer{ 34 | transport, 35 | protocol} 36 | } 37 | 38 | func (t *TDeserializer) ReadString(msg TStruct, s string) (err error) { 39 | err = nil 40 | if _, err = t.Transport.Write([]byte(s)); err != nil { 41 | return 42 | } 43 | if err = msg.Read(t.Protocol); err != nil { 44 | return 45 | } 46 | return 47 | } 48 | 49 | func (t *TDeserializer) Read(msg TStruct, b []byte) (err error) { 50 | err = nil 51 | if _, err = t.Transport.Write(b); err != nil { 52 | return 53 | } 54 | if err = msg.Read(t.Protocol); err != nil { 55 | return 56 | } 57 | return 58 | } 59 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/exception.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "errors" 24 | ) 25 | 26 | // Generic Thrift exception 27 | type TException interface { 28 | error 29 | } 30 | 31 | // Prepends additional information to an error without losing the Thrift exception interface 32 | func PrependError(prepend string, err error) error { 33 | if t, ok := err.(TTransportException); ok { 34 | return NewTTransportException(t.TypeId(), prepend+t.Error()) 35 | } 36 | if t, ok := err.(TProtocolException); ok { 37 | return NewTProtocolExceptionWithType(t.TypeId(), errors.New(prepend+err.Error())) 38 | } 39 | if t, ok := err.(TApplicationException); ok { 40 | return NewTApplicationException(t.TypeId(), prepend+t.Error()) 41 | } 42 | 43 | return errors.New(prepend + err.Error()) 44 | } 45 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/exception_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "errors" 24 | "testing" 25 | ) 26 | 27 | func TestPrependError(t *testing.T) { 28 | err := NewTApplicationException(INTERNAL_ERROR, "original error") 29 | err2, ok := PrependError("Prepend: ", err).(TApplicationException) 30 | if !ok { 31 | t.Fatal("Couldn't cast error TApplicationException") 32 | } 33 | if err2.Error() != "Prepend: original error" { 34 | t.Fatal("Unexpected error string") 35 | } 36 | if err2.TypeId() != INTERNAL_ERROR { 37 | t.Fatal("Unexpected type error") 38 | } 39 | 40 | err3 := NewTProtocolExceptionWithType(INVALID_DATA, errors.New("original error")) 41 | err4, ok := PrependError("Prepend: ", err3).(TProtocolException) 42 | if !ok { 43 | t.Fatal("Couldn't cast error TProtocolException") 44 | } 45 | if err4.Error() != "Prepend: original error" { 46 | t.Fatal("Unexpected error string") 47 | } 48 | if err4.TypeId() != INVALID_DATA { 49 | t.Fatal("Unexpected type error") 50 | } 51 | 52 | err5 := NewTTransportException(TIMED_OUT, "original error") 53 | err6, ok := PrependError("Prepend: ", err5).(TTransportException) 54 | if !ok { 55 | t.Fatal("Couldn't cast error TTransportException") 56 | } 57 | if err6.Error() != "Prepend: original error" { 58 | t.Fatal("Unexpected error string") 59 | } 60 | if err6.TypeId() != TIMED_OUT { 61 | t.Fatal("Unexpected type error") 62 | } 63 | 64 | err7 := errors.New("original error") 65 | err8 := PrependError("Prepend: ", err7) 66 | if err8.Error() != "Prepend: original error" { 67 | t.Fatal("Unexpected error string") 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/field.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | // Helper class that encapsulates field metadata. 23 | type field struct { 24 | name string 25 | typeId TType 26 | id int 27 | } 28 | 29 | func newField(n string, t TType, i int) *field { 30 | return &field{name: n, typeId: t, id: i} 31 | } 32 | 33 | func (p *field) Name() string { 34 | if p == nil { 35 | return "" 36 | } 37 | return p.name 38 | } 39 | 40 | func (p *field) TypeId() TType { 41 | if p == nil { 42 | return TType(VOID) 43 | } 44 | return p.typeId 45 | } 46 | 47 | func (p *field) Id() int { 48 | if p == nil { 49 | return -1 50 | } 51 | return p.id 52 | } 53 | 54 | func (p *field) String() string { 55 | if p == nil { 56 | return "" 57 | } 58 | return "" 59 | } 60 | 61 | var ANONYMOUS_FIELD *field 62 | 63 | type fieldSlice []field 64 | 65 | func (p fieldSlice) Len() int { 66 | return len(p) 67 | } 68 | 69 | func (p fieldSlice) Less(i, j int) bool { 70 | return p[i].Id() < p[j].Id() 71 | } 72 | 73 | func (p fieldSlice) Swap(i, j int) { 74 | p[i], p[j] = p[j], p[i] 75 | } 76 | 77 | func init() { 78 | ANONYMOUS_FIELD = newField("", STOP, 0) 79 | } 80 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/framed_transport.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "bufio" 24 | "bytes" 25 | "encoding/binary" 26 | "fmt" 27 | "io" 28 | ) 29 | 30 | const DEFAULT_MAX_LENGTH = 16384000 31 | 32 | type TFramedTransport struct { 33 | transport TTransport 34 | buf bytes.Buffer 35 | reader *bufio.Reader 36 | frameSize uint32 //Current remaining size of the frame. if ==0 read next frame header 37 | buffer [4]byte 38 | maxLength uint32 39 | } 40 | 41 | type tFramedTransportFactory struct { 42 | factory TTransportFactory 43 | maxLength uint32 44 | } 45 | 46 | func NewTFramedTransportFactory(factory TTransportFactory) TTransportFactory { 47 | return &tFramedTransportFactory{factory: factory, maxLength: DEFAULT_MAX_LENGTH} 48 | } 49 | 50 | func NewTFramedTransportFactoryMaxLength(factory TTransportFactory, maxLength uint32) TTransportFactory { 51 | return &tFramedTransportFactory{factory: factory, maxLength: maxLength} 52 | } 53 | 54 | func (p *tFramedTransportFactory) GetTransport(base TTransport) TTransport { 55 | return NewTFramedTransportMaxLength(p.factory.GetTransport(base), p.maxLength) 56 | } 57 | 58 | func NewTFramedTransport(transport TTransport) *TFramedTransport { 59 | return &TFramedTransport{transport: transport, reader: bufio.NewReader(transport), maxLength: DEFAULT_MAX_LENGTH} 60 | } 61 | 62 | func NewTFramedTransportMaxLength(transport TTransport, maxLength uint32) *TFramedTransport { 63 | return &TFramedTransport{transport: transport, reader: bufio.NewReader(transport), maxLength: maxLength} 64 | } 65 | 66 | func (p *TFramedTransport) Open() error { 67 | return p.transport.Open() 68 | } 69 | 70 | func (p *TFramedTransport) IsOpen() bool { 71 | return p.transport.IsOpen() 72 | } 73 | 74 | func (p *TFramedTransport) Close() error { 75 | return p.transport.Close() 76 | } 77 | 78 | func (p *TFramedTransport) Read(buf []byte) (l int, err error) { 79 | if p.frameSize == 0 { 80 | p.frameSize, err = p.readFrameHeader() 81 | if err != nil { 82 | return 83 | } 84 | } 85 | if p.frameSize < uint32(len(buf)) { 86 | frameSize := p.frameSize 87 | tmp := make([]byte, p.frameSize) 88 | l, err = p.Read(tmp) 89 | copy(buf, tmp) 90 | if err == nil { 91 | err = NewTTransportExceptionFromError(fmt.Errorf("Not enough frame size %d to read %d bytes", frameSize, len(buf))) 92 | return 93 | } 94 | } 95 | got, err := p.reader.Read(buf) 96 | p.frameSize = p.frameSize - uint32(got) 97 | //sanity check 98 | if p.frameSize < 0 { 99 | return 0, NewTTransportException(UNKNOWN_TRANSPORT_EXCEPTION, "Negative frame size") 100 | } 101 | return got, NewTTransportExceptionFromError(err) 102 | } 103 | 104 | func (p *TFramedTransport) ReadByte() (c byte, err error) { 105 | if p.frameSize == 0 { 106 | p.frameSize, err = p.readFrameHeader() 107 | if err != nil { 108 | return 109 | } 110 | } 111 | if p.frameSize < 1 { 112 | return 0, NewTTransportExceptionFromError(fmt.Errorf("Not enough frame size %d to read %d bytes", p.frameSize, 1)) 113 | } 114 | c, err = p.reader.ReadByte() 115 | if err == nil { 116 | p.frameSize-- 117 | } 118 | return 119 | } 120 | 121 | func (p *TFramedTransport) Write(buf []byte) (int, error) { 122 | n, err := p.buf.Write(buf) 123 | return n, NewTTransportExceptionFromError(err) 124 | } 125 | 126 | func (p *TFramedTransport) WriteByte(c byte) error { 127 | return p.buf.WriteByte(c) 128 | } 129 | 130 | func (p *TFramedTransport) WriteString(s string) (n int, err error) { 131 | return p.buf.WriteString(s) 132 | } 133 | 134 | func (p *TFramedTransport) Flush() error { 135 | size := p.buf.Len() 136 | buf := p.buffer[:4] 137 | binary.BigEndian.PutUint32(buf, uint32(size)) 138 | _, err := p.transport.Write(buf) 139 | if err != nil { 140 | return NewTTransportExceptionFromError(err) 141 | } 142 | if size > 0 { 143 | if n, err := p.buf.WriteTo(p.transport); err != nil { 144 | print("Error while flushing write buffer of size ", size, " to transport, only wrote ", n, " bytes: ", err.Error(), "\n") 145 | return NewTTransportExceptionFromError(err) 146 | } 147 | } 148 | err = p.transport.Flush() 149 | return NewTTransportExceptionFromError(err) 150 | } 151 | 152 | func (p *TFramedTransport) readFrameHeader() (uint32, error) { 153 | buf := p.buffer[:4] 154 | if _, err := io.ReadFull(p.reader, buf); err != nil { 155 | return 0, err 156 | } 157 | size := binary.BigEndian.Uint32(buf) 158 | if size < 0 || size > p.maxLength { 159 | return 0, NewTTransportException(UNKNOWN_TRANSPORT_EXCEPTION, fmt.Sprintf("Incorrect frame size (%d)", size)) 160 | } 161 | return size, nil 162 | } 163 | 164 | func (p *TFramedTransport) RemainingBytes() (num_bytes uint64) { 165 | return uint64(p.frameSize) 166 | } 167 | 168 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/framed_transport_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "testing" 24 | ) 25 | 26 | func TestFramedTransport(t *testing.T) { 27 | trans := NewTFramedTransport(NewTMemoryBuffer()) 28 | TransportTest(t, trans, trans) 29 | } 30 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/http_client.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "bytes" 24 | "io" 25 | "net/http" 26 | "net/url" 27 | "strconv" 28 | ) 29 | 30 | type THttpClient struct { 31 | response *http.Response 32 | url *url.URL 33 | requestBuffer *bytes.Buffer 34 | header http.Header 35 | nsecConnectTimeout int64 36 | nsecReadTimeout int64 37 | } 38 | 39 | type THttpClientTransportFactory struct { 40 | url string 41 | isPost bool 42 | } 43 | 44 | func (p *THttpClientTransportFactory) GetTransport(trans TTransport) TTransport { 45 | if trans != nil { 46 | t, ok := trans.(*THttpClient) 47 | if ok && t.url != nil { 48 | if t.requestBuffer != nil { 49 | t2, _ := NewTHttpPostClient(t.url.String()) 50 | return t2 51 | } 52 | t2, _ := NewTHttpClient(t.url.String()) 53 | return t2 54 | } 55 | } 56 | if p.isPost { 57 | s, _ := NewTHttpPostClient(p.url) 58 | return s 59 | } 60 | s, _ := NewTHttpClient(p.url) 61 | return s 62 | } 63 | 64 | func NewTHttpClientTransportFactory(url string) *THttpClientTransportFactory { 65 | return &THttpClientTransportFactory{url: url, isPost: false} 66 | } 67 | 68 | func NewTHttpPostClientTransportFactory(url string) *THttpClientTransportFactory { 69 | return &THttpClientTransportFactory{url: url, isPost: true} 70 | } 71 | 72 | func NewTHttpClient(urlstr string) (TTransport, error) { 73 | parsedURL, err := url.Parse(urlstr) 74 | if err != nil { 75 | return nil, err 76 | } 77 | response, err := http.Get(urlstr) 78 | if err != nil { 79 | return nil, err 80 | } 81 | return &THttpClient{response: response, url: parsedURL}, nil 82 | } 83 | 84 | func NewTHttpPostClient(urlstr string) (TTransport, error) { 85 | parsedURL, err := url.Parse(urlstr) 86 | if err != nil { 87 | return nil, err 88 | } 89 | buf := make([]byte, 0, 1024) 90 | return &THttpClient{url: parsedURL, requestBuffer: bytes.NewBuffer(buf), header: http.Header{}}, nil 91 | } 92 | 93 | // Set the HTTP Header for this specific Thrift Transport 94 | // It is important that you first assert the TTransport as a THttpClient type 95 | // like so: 96 | // 97 | // httpTrans := trans.(THttpClient) 98 | // httpTrans.SetHeader("User-Agent","Thrift Client 1.0") 99 | func (p *THttpClient) SetHeader(key string, value string) { 100 | p.header.Add(key, value) 101 | } 102 | 103 | // Get the HTTP Header represented by the supplied Header Key for this specific Thrift Transport 104 | // It is important that you first assert the TTransport as a THttpClient type 105 | // like so: 106 | // 107 | // httpTrans := trans.(THttpClient) 108 | // hdrValue := httpTrans.GetHeader("User-Agent") 109 | func (p *THttpClient) GetHeader(key string) string { 110 | return p.header.Get(key) 111 | } 112 | 113 | // Deletes the HTTP Header given a Header Key for this specific Thrift Transport 114 | // It is important that you first assert the TTransport as a THttpClient type 115 | // like so: 116 | // 117 | // httpTrans := trans.(THttpClient) 118 | // httpTrans.DelHeader("User-Agent") 119 | func (p *THttpClient) DelHeader(key string) { 120 | p.header.Del(key) 121 | } 122 | 123 | func (p *THttpClient) Open() error { 124 | // do nothing 125 | return nil 126 | } 127 | 128 | func (p *THttpClient) IsOpen() bool { 129 | return p.response != nil || p.requestBuffer != nil 130 | } 131 | 132 | func (p *THttpClient) closeResponse() error { 133 | var err error 134 | if p.response != nil && p.response.Body != nil { 135 | err = p.response.Body.Close() 136 | } 137 | 138 | p.response = nil 139 | return err 140 | } 141 | 142 | func (p *THttpClient) Close() error { 143 | if p.requestBuffer != nil { 144 | p.requestBuffer.Reset() 145 | p.requestBuffer = nil 146 | } 147 | return p.closeResponse() 148 | } 149 | 150 | func (p *THttpClient) Read(buf []byte) (int, error) { 151 | if p.response == nil { 152 | return 0, NewTTransportException(NOT_OPEN, "Response buffer is empty, no request.") 153 | } 154 | n, err := p.response.Body.Read(buf) 155 | if n > 0 && (err == nil || err == io.EOF) { 156 | return n, nil 157 | } 158 | return n, NewTTransportExceptionFromError(err) 159 | } 160 | 161 | func (p *THttpClient) ReadByte() (c byte, err error) { 162 | return readByte(p.response.Body) 163 | } 164 | 165 | func (p *THttpClient) Write(buf []byte) (int, error) { 166 | n, err := p.requestBuffer.Write(buf) 167 | return n, err 168 | } 169 | 170 | func (p *THttpClient) WriteByte(c byte) error { 171 | return p.requestBuffer.WriteByte(c) 172 | } 173 | 174 | func (p *THttpClient) WriteString(s string) (n int, err error) { 175 | return p.requestBuffer.WriteString(s) 176 | } 177 | 178 | func (p *THttpClient) Flush() error { 179 | // Close any previous response body to avoid leaking connections. 180 | p.closeResponse() 181 | 182 | client := &http.Client{} 183 | req, err := http.NewRequest("POST", p.url.String(), p.requestBuffer) 184 | if err != nil { 185 | return NewTTransportExceptionFromError(err) 186 | } 187 | p.header.Add("Content-Type", "application/x-thrift") 188 | req.Header = p.header 189 | response, err := client.Do(req) 190 | if err != nil { 191 | return NewTTransportExceptionFromError(err) 192 | } 193 | if response.StatusCode != http.StatusOK { 194 | // Close the response to avoid leaking file descriptors. 195 | response.Body.Close() 196 | // TODO(pomack) log bad response 197 | return NewTTransportException(UNKNOWN_TRANSPORT_EXCEPTION, "HTTP Response code: "+strconv.Itoa(response.StatusCode)) 198 | } 199 | p.response = response 200 | return nil 201 | } 202 | 203 | func (p *THttpClient) RemainingBytes() (num_bytes uint64) { 204 | len := p.response.ContentLength 205 | if len >= 0 { 206 | return uint64(len) 207 | } 208 | 209 | const maxSize = ^uint64(0) 210 | return maxSize // the thruth is, we just don't know unless framed is used 211 | } 212 | 213 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/http_client_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "testing" 24 | ) 25 | 26 | func TestHttpClient(t *testing.T) { 27 | l, addr := HttpClientSetupForTest(t) 28 | if l != nil { 29 | defer l.Close() 30 | } 31 | trans, err := NewTHttpPostClient("http://" + addr.String()) 32 | if err != nil { 33 | l.Close() 34 | t.Fatalf("Unable to connect to %s: %s", addr.String(), err) 35 | } 36 | TransportTest(t, trans, trans) 37 | } 38 | 39 | func TestHttpClientHeaders(t *testing.T) { 40 | l, addr := HttpClientSetupForTest(t) 41 | if l != nil { 42 | defer l.Close() 43 | } 44 | trans, err := NewTHttpPostClient("http://" + addr.String()) 45 | if err != nil { 46 | l.Close() 47 | t.Fatalf("Unable to connect to %s: %s", addr.String(), err) 48 | } 49 | TransportHeaderTest(t, trans, trans) 50 | } 51 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/iostream_transport.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "bufio" 24 | "io" 25 | ) 26 | 27 | // StreamTransport is a Transport made of an io.Reader and/or an io.Writer 28 | type StreamTransport struct { 29 | io.Reader 30 | io.Writer 31 | isReadWriter bool 32 | closed bool 33 | } 34 | 35 | type StreamTransportFactory struct { 36 | Reader io.Reader 37 | Writer io.Writer 38 | isReadWriter bool 39 | } 40 | 41 | func (p *StreamTransportFactory) GetTransport(trans TTransport) TTransport { 42 | if trans != nil { 43 | t, ok := trans.(*StreamTransport) 44 | if ok { 45 | if t.isReadWriter { 46 | return NewStreamTransportRW(t.Reader.(io.ReadWriter)) 47 | } 48 | if t.Reader != nil && t.Writer != nil { 49 | return NewStreamTransport(t.Reader, t.Writer) 50 | } 51 | if t.Reader != nil && t.Writer == nil { 52 | return NewStreamTransportR(t.Reader) 53 | } 54 | if t.Reader == nil && t.Writer != nil { 55 | return NewStreamTransportW(t.Writer) 56 | } 57 | return &StreamTransport{} 58 | } 59 | } 60 | if p.isReadWriter { 61 | return NewStreamTransportRW(p.Reader.(io.ReadWriter)) 62 | } 63 | if p.Reader != nil && p.Writer != nil { 64 | return NewStreamTransport(p.Reader, p.Writer) 65 | } 66 | if p.Reader != nil && p.Writer == nil { 67 | return NewStreamTransportR(p.Reader) 68 | } 69 | if p.Reader == nil && p.Writer != nil { 70 | return NewStreamTransportW(p.Writer) 71 | } 72 | return &StreamTransport{} 73 | } 74 | 75 | func NewStreamTransportFactory(reader io.Reader, writer io.Writer, isReadWriter bool) *StreamTransportFactory { 76 | return &StreamTransportFactory{Reader: reader, Writer: writer, isReadWriter: isReadWriter} 77 | } 78 | 79 | func NewStreamTransport(r io.Reader, w io.Writer) *StreamTransport { 80 | return &StreamTransport{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)} 81 | } 82 | 83 | func NewStreamTransportR(r io.Reader) *StreamTransport { 84 | return &StreamTransport{Reader: bufio.NewReader(r)} 85 | } 86 | 87 | func NewStreamTransportW(w io.Writer) *StreamTransport { 88 | return &StreamTransport{Writer: bufio.NewWriter(w)} 89 | } 90 | 91 | func NewStreamTransportRW(rw io.ReadWriter) *StreamTransport { 92 | bufrw := bufio.NewReadWriter(bufio.NewReader(rw), bufio.NewWriter(rw)) 93 | return &StreamTransport{Reader: bufrw, Writer: bufrw, isReadWriter: true} 94 | } 95 | 96 | func (p *StreamTransport) IsOpen() bool { 97 | return !p.closed 98 | } 99 | 100 | // implicitly opened on creation, can't be reopened once closed 101 | func (p *StreamTransport) Open() error { 102 | if !p.closed { 103 | return NewTTransportException(ALREADY_OPEN, "StreamTransport already open.") 104 | } else { 105 | return NewTTransportException(NOT_OPEN, "cannot reopen StreamTransport.") 106 | } 107 | } 108 | 109 | // Closes both the input and output streams. 110 | func (p *StreamTransport) Close() error { 111 | if p.closed { 112 | return NewTTransportException(NOT_OPEN, "StreamTransport already closed.") 113 | } 114 | p.closed = true 115 | closedReader := false 116 | if p.Reader != nil { 117 | c, ok := p.Reader.(io.Closer) 118 | if ok { 119 | e := c.Close() 120 | closedReader = true 121 | if e != nil { 122 | return e 123 | } 124 | } 125 | p.Reader = nil 126 | } 127 | if p.Writer != nil && (!closedReader || !p.isReadWriter) { 128 | c, ok := p.Writer.(io.Closer) 129 | if ok { 130 | e := c.Close() 131 | if e != nil { 132 | return e 133 | } 134 | } 135 | p.Writer = nil 136 | } 137 | return nil 138 | } 139 | 140 | // Flushes the underlying output stream if not null. 141 | func (p *StreamTransport) Flush() error { 142 | if p.Writer == nil { 143 | return NewTTransportException(NOT_OPEN, "Cannot flush null outputStream") 144 | } 145 | f, ok := p.Writer.(Flusher) 146 | if ok { 147 | err := f.Flush() 148 | if err != nil { 149 | return NewTTransportExceptionFromError(err) 150 | } 151 | } 152 | return nil 153 | } 154 | 155 | func (p *StreamTransport) Read(c []byte) (n int, err error) { 156 | n, err = p.Reader.Read(c) 157 | if err != nil { 158 | err = NewTTransportExceptionFromError(err) 159 | } 160 | return 161 | } 162 | 163 | func (p *StreamTransport) ReadByte() (c byte, err error) { 164 | f, ok := p.Reader.(io.ByteReader) 165 | if ok { 166 | c, err = f.ReadByte() 167 | } else { 168 | c, err = readByte(p.Reader) 169 | } 170 | if err != nil { 171 | err = NewTTransportExceptionFromError(err) 172 | } 173 | return 174 | } 175 | 176 | func (p *StreamTransport) Write(c []byte) (n int, err error) { 177 | n, err = p.Writer.Write(c) 178 | if err != nil { 179 | err = NewTTransportExceptionFromError(err) 180 | } 181 | return 182 | } 183 | 184 | func (p *StreamTransport) WriteByte(c byte) (err error) { 185 | f, ok := p.Writer.(io.ByteWriter) 186 | if ok { 187 | err = f.WriteByte(c) 188 | } else { 189 | err = writeByte(p.Writer, c) 190 | } 191 | if err != nil { 192 | err = NewTTransportExceptionFromError(err) 193 | } 194 | return 195 | } 196 | 197 | func (p *StreamTransport) WriteString(s string) (n int, err error) { 198 | f, ok := p.Writer.(stringWriter) 199 | if ok { 200 | n, err = f.WriteString(s) 201 | } else { 202 | n, err = p.Writer.Write([]byte(s)) 203 | } 204 | if err != nil { 205 | err = NewTTransportExceptionFromError(err) 206 | } 207 | return 208 | } 209 | 210 | func (p *StreamTransport) RemainingBytes() (num_bytes uint64) { 211 | const maxSize = ^uint64(0) 212 | return maxSize // the thruth is, we just don't know unless framed is used 213 | } 214 | 215 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/iostream_transport_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "bytes" 24 | "testing" 25 | ) 26 | 27 | func TestStreamTransport(t *testing.T) { 28 | trans := NewStreamTransportRW(bytes.NewBuffer(make([]byte, 0, 1024))) 29 | TransportTest(t, trans, trans) 30 | } 31 | 32 | func TestStreamTransportOpenClose(t *testing.T) { 33 | trans := NewStreamTransportRW(bytes.NewBuffer(make([]byte, 0, 1024))) 34 | if !trans.IsOpen() { 35 | t.Fatal("StreamTransport should be already open") 36 | } 37 | if trans.Open() == nil { 38 | t.Fatal("StreamTransport should return error when open twice") 39 | } 40 | if trans.Close() != nil { 41 | t.Fatal("StreamTransport should not return error when closing open transport") 42 | } 43 | if trans.IsOpen() { 44 | t.Fatal("StreamTransport should not be open after close") 45 | } 46 | if trans.Close() == nil { 47 | t.Fatal("StreamTransport should return error when closing a non open transport") 48 | } 49 | if trans.Open() == nil { 50 | t.Fatal("StreamTransport should not be able to reopen") 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/lowlevel_benchmarks_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "bytes" 24 | "testing" 25 | ) 26 | 27 | var binaryProtoF = NewTBinaryProtocolFactoryDefault() 28 | var compactProtoF = NewTCompactProtocolFactory() 29 | 30 | var buf = bytes.NewBuffer(make([]byte, 0, 1024)) 31 | 32 | var tfv = []TTransportFactory{ 33 | NewTMemoryBufferTransportFactory(1024), 34 | NewStreamTransportFactory(buf, buf, true), 35 | NewTFramedTransportFactory(NewTMemoryBufferTransportFactory(1024)), 36 | } 37 | 38 | func BenchmarkBinaryBool_0(b *testing.B) { 39 | trans := tfv[0].GetTransport(nil) 40 | p := binaryProtoF.GetProtocol(trans) 41 | for i := 0; i < b.N; i++ { 42 | ReadWriteBool(b, p, trans) 43 | } 44 | } 45 | 46 | func BenchmarkBinaryByte_0(b *testing.B) { 47 | trans := tfv[0].GetTransport(nil) 48 | p := binaryProtoF.GetProtocol(trans) 49 | for i := 0; i < b.N; i++ { 50 | ReadWriteByte(b, p, trans) 51 | } 52 | } 53 | 54 | func BenchmarkBinaryI16_0(b *testing.B) { 55 | trans := tfv[0].GetTransport(nil) 56 | p := binaryProtoF.GetProtocol(trans) 57 | for i := 0; i < b.N; i++ { 58 | ReadWriteI16(b, p, trans) 59 | } 60 | } 61 | 62 | func BenchmarkBinaryI32_0(b *testing.B) { 63 | trans := tfv[0].GetTransport(nil) 64 | p := binaryProtoF.GetProtocol(trans) 65 | for i := 0; i < b.N; i++ { 66 | ReadWriteI32(b, p, trans) 67 | } 68 | } 69 | func BenchmarkBinaryI64_0(b *testing.B) { 70 | trans := tfv[0].GetTransport(nil) 71 | p := binaryProtoF.GetProtocol(trans) 72 | for i := 0; i < b.N; i++ { 73 | ReadWriteI64(b, p, trans) 74 | } 75 | } 76 | func BenchmarkBinaryDouble_0(b *testing.B) { 77 | trans := tfv[0].GetTransport(nil) 78 | p := binaryProtoF.GetProtocol(trans) 79 | for i := 0; i < b.N; i++ { 80 | ReadWriteDouble(b, p, trans) 81 | } 82 | } 83 | func BenchmarkBinaryString_0(b *testing.B) { 84 | trans := tfv[0].GetTransport(nil) 85 | p := binaryProtoF.GetProtocol(trans) 86 | for i := 0; i < b.N; i++ { 87 | ReadWriteString(b, p, trans) 88 | } 89 | } 90 | func BenchmarkBinaryBinary_0(b *testing.B) { 91 | trans := tfv[0].GetTransport(nil) 92 | p := binaryProtoF.GetProtocol(trans) 93 | for i := 0; i < b.N; i++ { 94 | ReadWriteBinary(b, p, trans) 95 | } 96 | } 97 | 98 | func BenchmarkBinaryBool_1(b *testing.B) { 99 | trans := tfv[1].GetTransport(nil) 100 | p := binaryProtoF.GetProtocol(trans) 101 | for i := 0; i < b.N; i++ { 102 | ReadWriteBool(b, p, trans) 103 | } 104 | } 105 | 106 | func BenchmarkBinaryByte_1(b *testing.B) { 107 | trans := tfv[1].GetTransport(nil) 108 | p := binaryProtoF.GetProtocol(trans) 109 | for i := 0; i < b.N; i++ { 110 | ReadWriteByte(b, p, trans) 111 | } 112 | } 113 | 114 | func BenchmarkBinaryI16_1(b *testing.B) { 115 | trans := tfv[1].GetTransport(nil) 116 | p := binaryProtoF.GetProtocol(trans) 117 | for i := 0; i < b.N; i++ { 118 | ReadWriteI16(b, p, trans) 119 | } 120 | } 121 | 122 | func BenchmarkBinaryI32_1(b *testing.B) { 123 | trans := tfv[1].GetTransport(nil) 124 | p := binaryProtoF.GetProtocol(trans) 125 | for i := 0; i < b.N; i++ { 126 | ReadWriteI32(b, p, trans) 127 | } 128 | } 129 | func BenchmarkBinaryI64_1(b *testing.B) { 130 | trans := tfv[1].GetTransport(nil) 131 | p := binaryProtoF.GetProtocol(trans) 132 | for i := 0; i < b.N; i++ { 133 | ReadWriteI64(b, p, trans) 134 | } 135 | } 136 | func BenchmarkBinaryDouble_1(b *testing.B) { 137 | trans := tfv[1].GetTransport(nil) 138 | p := binaryProtoF.GetProtocol(trans) 139 | for i := 0; i < b.N; i++ { 140 | ReadWriteDouble(b, p, trans) 141 | } 142 | } 143 | func BenchmarkBinaryString_1(b *testing.B) { 144 | trans := tfv[1].GetTransport(nil) 145 | p := binaryProtoF.GetProtocol(trans) 146 | for i := 0; i < b.N; i++ { 147 | ReadWriteString(b, p, trans) 148 | } 149 | } 150 | func BenchmarkBinaryBinary_1(b *testing.B) { 151 | trans := tfv[1].GetTransport(nil) 152 | p := binaryProtoF.GetProtocol(trans) 153 | for i := 0; i < b.N; i++ { 154 | ReadWriteBinary(b, p, trans) 155 | } 156 | } 157 | 158 | func BenchmarkBinaryBool_2(b *testing.B) { 159 | trans := tfv[2].GetTransport(nil) 160 | p := binaryProtoF.GetProtocol(trans) 161 | for i := 0; i < b.N; i++ { 162 | ReadWriteBool(b, p, trans) 163 | } 164 | } 165 | 166 | func BenchmarkBinaryByte_2(b *testing.B) { 167 | trans := tfv[2].GetTransport(nil) 168 | p := binaryProtoF.GetProtocol(trans) 169 | for i := 0; i < b.N; i++ { 170 | ReadWriteByte(b, p, trans) 171 | } 172 | } 173 | 174 | func BenchmarkBinaryI16_2(b *testing.B) { 175 | trans := tfv[2].GetTransport(nil) 176 | p := binaryProtoF.GetProtocol(trans) 177 | for i := 0; i < b.N; i++ { 178 | ReadWriteI16(b, p, trans) 179 | } 180 | } 181 | 182 | func BenchmarkBinaryI32_2(b *testing.B) { 183 | trans := tfv[2].GetTransport(nil) 184 | p := binaryProtoF.GetProtocol(trans) 185 | for i := 0; i < b.N; i++ { 186 | ReadWriteI32(b, p, trans) 187 | } 188 | } 189 | func BenchmarkBinaryI64_2(b *testing.B) { 190 | trans := tfv[2].GetTransport(nil) 191 | p := binaryProtoF.GetProtocol(trans) 192 | for i := 0; i < b.N; i++ { 193 | ReadWriteI64(b, p, trans) 194 | } 195 | } 196 | func BenchmarkBinaryDouble_2(b *testing.B) { 197 | trans := tfv[2].GetTransport(nil) 198 | p := binaryProtoF.GetProtocol(trans) 199 | for i := 0; i < b.N; i++ { 200 | ReadWriteDouble(b, p, trans) 201 | } 202 | } 203 | func BenchmarkBinaryString_2(b *testing.B) { 204 | trans := tfv[2].GetTransport(nil) 205 | p := binaryProtoF.GetProtocol(trans) 206 | for i := 0; i < b.N; i++ { 207 | ReadWriteString(b, p, trans) 208 | } 209 | } 210 | func BenchmarkBinaryBinary_2(b *testing.B) { 211 | trans := tfv[2].GetTransport(nil) 212 | p := binaryProtoF.GetProtocol(trans) 213 | for i := 0; i < b.N; i++ { 214 | ReadWriteBinary(b, p, trans) 215 | } 216 | } 217 | 218 | func BenchmarkCompactBool_0(b *testing.B) { 219 | trans := tfv[0].GetTransport(nil) 220 | p := compactProtoF.GetProtocol(trans) 221 | for i := 0; i < b.N; i++ { 222 | ReadWriteBool(b, p, trans) 223 | } 224 | } 225 | 226 | func BenchmarkCompactByte_0(b *testing.B) { 227 | trans := tfv[0].GetTransport(nil) 228 | p := compactProtoF.GetProtocol(trans) 229 | for i := 0; i < b.N; i++ { 230 | ReadWriteByte(b, p, trans) 231 | } 232 | } 233 | 234 | func BenchmarkCompactI16_0(b *testing.B) { 235 | trans := tfv[0].GetTransport(nil) 236 | p := compactProtoF.GetProtocol(trans) 237 | for i := 0; i < b.N; i++ { 238 | ReadWriteI16(b, p, trans) 239 | } 240 | } 241 | 242 | func BenchmarkCompactI32_0(b *testing.B) { 243 | trans := tfv[0].GetTransport(nil) 244 | p := compactProtoF.GetProtocol(trans) 245 | for i := 0; i < b.N; i++ { 246 | ReadWriteI32(b, p, trans) 247 | } 248 | } 249 | func BenchmarkCompactI64_0(b *testing.B) { 250 | trans := tfv[0].GetTransport(nil) 251 | p := compactProtoF.GetProtocol(trans) 252 | for i := 0; i < b.N; i++ { 253 | ReadWriteI64(b, p, trans) 254 | } 255 | } 256 | func BenchmarkCompactDouble0(b *testing.B) { 257 | trans := tfv[0].GetTransport(nil) 258 | p := compactProtoF.GetProtocol(trans) 259 | for i := 0; i < b.N; i++ { 260 | ReadWriteDouble(b, p, trans) 261 | } 262 | } 263 | func BenchmarkCompactString0(b *testing.B) { 264 | trans := tfv[0].GetTransport(nil) 265 | p := compactProtoF.GetProtocol(trans) 266 | for i := 0; i < b.N; i++ { 267 | ReadWriteString(b, p, trans) 268 | } 269 | } 270 | func BenchmarkCompactBinary0(b *testing.B) { 271 | trans := tfv[0].GetTransport(nil) 272 | p := compactProtoF.GetProtocol(trans) 273 | for i := 0; i < b.N; i++ { 274 | ReadWriteBinary(b, p, trans) 275 | } 276 | } 277 | 278 | func BenchmarkCompactBool_1(b *testing.B) { 279 | trans := tfv[1].GetTransport(nil) 280 | p := compactProtoF.GetProtocol(trans) 281 | for i := 0; i < b.N; i++ { 282 | ReadWriteBool(b, p, trans) 283 | } 284 | } 285 | 286 | func BenchmarkCompactByte_1(b *testing.B) { 287 | trans := tfv[1].GetTransport(nil) 288 | p := compactProtoF.GetProtocol(trans) 289 | for i := 0; i < b.N; i++ { 290 | ReadWriteByte(b, p, trans) 291 | } 292 | } 293 | 294 | func BenchmarkCompactI16_1(b *testing.B) { 295 | trans := tfv[1].GetTransport(nil) 296 | p := compactProtoF.GetProtocol(trans) 297 | for i := 0; i < b.N; i++ { 298 | ReadWriteI16(b, p, trans) 299 | } 300 | } 301 | 302 | func BenchmarkCompactI32_1(b *testing.B) { 303 | trans := tfv[1].GetTransport(nil) 304 | p := compactProtoF.GetProtocol(trans) 305 | for i := 0; i < b.N; i++ { 306 | ReadWriteI32(b, p, trans) 307 | } 308 | } 309 | func BenchmarkCompactI64_1(b *testing.B) { 310 | trans := tfv[1].GetTransport(nil) 311 | p := compactProtoF.GetProtocol(trans) 312 | for i := 0; i < b.N; i++ { 313 | ReadWriteI64(b, p, trans) 314 | } 315 | } 316 | func BenchmarkCompactDouble1(b *testing.B) { 317 | trans := tfv[1].GetTransport(nil) 318 | p := compactProtoF.GetProtocol(trans) 319 | for i := 0; i < b.N; i++ { 320 | ReadWriteDouble(b, p, trans) 321 | } 322 | } 323 | func BenchmarkCompactString1(b *testing.B) { 324 | trans := tfv[1].GetTransport(nil) 325 | p := compactProtoF.GetProtocol(trans) 326 | for i := 0; i < b.N; i++ { 327 | ReadWriteString(b, p, trans) 328 | } 329 | } 330 | func BenchmarkCompactBinary1(b *testing.B) { 331 | trans := tfv[1].GetTransport(nil) 332 | p := compactProtoF.GetProtocol(trans) 333 | for i := 0; i < b.N; i++ { 334 | ReadWriteBinary(b, p, trans) 335 | } 336 | } 337 | 338 | func BenchmarkCompactBool_2(b *testing.B) { 339 | trans := tfv[2].GetTransport(nil) 340 | p := compactProtoF.GetProtocol(trans) 341 | for i := 0; i < b.N; i++ { 342 | ReadWriteBool(b, p, trans) 343 | } 344 | } 345 | 346 | func BenchmarkCompactByte_2(b *testing.B) { 347 | trans := tfv[2].GetTransport(nil) 348 | p := compactProtoF.GetProtocol(trans) 349 | for i := 0; i < b.N; i++ { 350 | ReadWriteByte(b, p, trans) 351 | } 352 | } 353 | 354 | func BenchmarkCompactI16_2(b *testing.B) { 355 | trans := tfv[2].GetTransport(nil) 356 | p := compactProtoF.GetProtocol(trans) 357 | for i := 0; i < b.N; i++ { 358 | ReadWriteI16(b, p, trans) 359 | } 360 | } 361 | 362 | func BenchmarkCompactI32_2(b *testing.B) { 363 | trans := tfv[2].GetTransport(nil) 364 | p := compactProtoF.GetProtocol(trans) 365 | for i := 0; i < b.N; i++ { 366 | ReadWriteI32(b, p, trans) 367 | } 368 | } 369 | func BenchmarkCompactI64_2(b *testing.B) { 370 | trans := tfv[2].GetTransport(nil) 371 | p := compactProtoF.GetProtocol(trans) 372 | for i := 0; i < b.N; i++ { 373 | ReadWriteI64(b, p, trans) 374 | } 375 | } 376 | func BenchmarkCompactDouble2(b *testing.B) { 377 | trans := tfv[2].GetTransport(nil) 378 | p := compactProtoF.GetProtocol(trans) 379 | for i := 0; i < b.N; i++ { 380 | ReadWriteDouble(b, p, trans) 381 | } 382 | } 383 | func BenchmarkCompactString2(b *testing.B) { 384 | trans := tfv[2].GetTransport(nil) 385 | p := compactProtoF.GetProtocol(trans) 386 | for i := 0; i < b.N; i++ { 387 | ReadWriteString(b, p, trans) 388 | } 389 | } 390 | func BenchmarkCompactBinary2(b *testing.B) { 391 | trans := tfv[2].GetTransport(nil) 392 | p := compactProtoF.GetProtocol(trans) 393 | for i := 0; i < b.N; i++ { 394 | ReadWriteBinary(b, p, trans) 395 | } 396 | } 397 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/memory_buffer.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "bytes" 24 | ) 25 | 26 | // Memory buffer-based implementation of the TTransport interface. 27 | type TMemoryBuffer struct { 28 | *bytes.Buffer 29 | size int 30 | } 31 | 32 | type TMemoryBufferTransportFactory struct { 33 | size int 34 | } 35 | 36 | func (p *TMemoryBufferTransportFactory) GetTransport(trans TTransport) TTransport { 37 | if trans != nil { 38 | t, ok := trans.(*TMemoryBuffer) 39 | if ok && t.size > 0 { 40 | return NewTMemoryBufferLen(t.size) 41 | } 42 | } 43 | return NewTMemoryBufferLen(p.size) 44 | } 45 | 46 | func NewTMemoryBufferTransportFactory(size int) *TMemoryBufferTransportFactory { 47 | return &TMemoryBufferTransportFactory{size: size} 48 | } 49 | 50 | func NewTMemoryBuffer() *TMemoryBuffer { 51 | return &TMemoryBuffer{Buffer: &bytes.Buffer{}, size: 0} 52 | } 53 | 54 | func NewTMemoryBufferLen(size int) *TMemoryBuffer { 55 | buf := make([]byte, 0, size) 56 | return &TMemoryBuffer{Buffer: bytes.NewBuffer(buf), size: size} 57 | } 58 | 59 | func (p *TMemoryBuffer) IsOpen() bool { 60 | return true 61 | } 62 | 63 | func (p *TMemoryBuffer) Open() error { 64 | return nil 65 | } 66 | 67 | func (p *TMemoryBuffer) Close() error { 68 | p.Buffer.Reset() 69 | return nil 70 | } 71 | 72 | // Flushing a memory buffer is a no-op 73 | func (p *TMemoryBuffer) Flush() error { 74 | return nil 75 | } 76 | 77 | func (p *TMemoryBuffer) RemainingBytes() (num_bytes uint64) { 78 | return uint64(p.Buffer.Len()) 79 | } 80 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/memory_buffer_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "testing" 24 | ) 25 | 26 | func TestMemoryBuffer(t *testing.T) { 27 | trans := NewTMemoryBufferLen(1024) 28 | TransportTest(t, trans, trans) 29 | } 30 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/messagetype.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | // Message type constants in the Thrift protocol. 23 | type TMessageType int32 24 | 25 | const ( 26 | INVALID_TMESSAGE_TYPE TMessageType = 0 27 | CALL TMessageType = 1 28 | REPLY TMessageType = 2 29 | EXCEPTION TMessageType = 3 30 | ONEWAY TMessageType = 4 31 | ) 32 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/multiplexed_protocol.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "fmt" 24 | "strings" 25 | ) 26 | 27 | /* 28 | TMultiplexedProtocol is a protocol-independent concrete decorator 29 | that allows a Thrift client to communicate with a multiplexing Thrift server, 30 | by prepending the service name to the function name during function calls. 31 | 32 | NOTE: THIS IS NOT USED BY SERVERS. On the server, use TMultiplexedProcessor to handle request 33 | from a multiplexing client. 34 | 35 | This example uses a single socket transport to invoke two services: 36 | 37 | socket := thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT) 38 | transport := thrift.NewTFramedTransport(socket) 39 | protocol := thrift.NewTBinaryProtocolTransport(transport) 40 | 41 | mp := thrift.NewTMultiplexedProtocol(protocol, "Calculator") 42 | service := Calculator.NewCalculatorClient(mp) 43 | 44 | mp2 := thrift.NewTMultiplexedProtocol(protocol, "WeatherReport") 45 | service2 := WeatherReport.NewWeatherReportClient(mp2) 46 | 47 | err := transport.Open() 48 | if err != nil { 49 | t.Fatal("Unable to open client socket", err) 50 | } 51 | 52 | fmt.Println(service.Add(2,2)) 53 | fmt.Println(service2.GetTemperature()) 54 | */ 55 | 56 | type TMultiplexedProtocol struct { 57 | TProtocol 58 | serviceName string 59 | } 60 | 61 | const MULTIPLEXED_SEPARATOR = ":" 62 | 63 | func NewTMultiplexedProtocol(protocol TProtocol, serviceName string) *TMultiplexedProtocol { 64 | return &TMultiplexedProtocol{ 65 | TProtocol: protocol, 66 | serviceName: serviceName, 67 | } 68 | } 69 | 70 | func (t *TMultiplexedProtocol) WriteMessageBegin(name string, typeId TMessageType, seqid int32) error { 71 | if typeId == CALL || typeId == ONEWAY { 72 | return t.TProtocol.WriteMessageBegin(t.serviceName+MULTIPLEXED_SEPARATOR+name, typeId, seqid) 73 | } else { 74 | return t.TProtocol.WriteMessageBegin(name, typeId, seqid) 75 | } 76 | } 77 | 78 | /* 79 | TMultiplexedProcessor is a TProcessor allowing 80 | a single TServer to provide multiple services. 81 | 82 | To do so, you instantiate the processor and then register additional 83 | processors with it, as shown in the following example: 84 | 85 | var processor = thrift.NewTMultiplexedProcessor() 86 | 87 | firstProcessor := 88 | processor.RegisterProcessor("FirstService", firstProcessor) 89 | 90 | processor.registerProcessor( 91 | "Calculator", 92 | Calculator.NewCalculatorProcessor(&CalculatorHandler{}), 93 | ) 94 | 95 | processor.registerProcessor( 96 | "WeatherReport", 97 | WeatherReport.NewWeatherReportProcessor(&WeatherReportHandler{}), 98 | ) 99 | 100 | serverTransport, err := thrift.NewTServerSocketTimeout(addr, TIMEOUT) 101 | if err != nil { 102 | t.Fatal("Unable to create server socket", err) 103 | } 104 | server := thrift.NewTSimpleServer2(processor, serverTransport) 105 | server.Serve(); 106 | */ 107 | 108 | type TMultiplexedProcessor struct { 109 | serviceProcessorMap map[string]TProcessor 110 | DefaultProcessor TProcessor 111 | } 112 | 113 | func NewTMultiplexedProcessor() *TMultiplexedProcessor { 114 | return &TMultiplexedProcessor{ 115 | serviceProcessorMap: make(map[string]TProcessor), 116 | } 117 | } 118 | 119 | func (t *TMultiplexedProcessor) RegisterDefault(processor TProcessor) { 120 | t.DefaultProcessor = processor 121 | } 122 | 123 | func (t *TMultiplexedProcessor) RegisterProcessor(name string, processor TProcessor) { 124 | if t.serviceProcessorMap == nil { 125 | t.serviceProcessorMap = make(map[string]TProcessor) 126 | } 127 | t.serviceProcessorMap[name] = processor 128 | } 129 | 130 | func (t *TMultiplexedProcessor) Process(in, out TProtocol) (bool, TException) { 131 | name, typeId, seqid, err := in.ReadMessageBegin() 132 | if err != nil { 133 | return false, err 134 | } 135 | if typeId != CALL && typeId != ONEWAY { 136 | return false, fmt.Errorf("Unexpected message type %v", typeId) 137 | } 138 | //extract the service name 139 | v := strings.SplitN(name, MULTIPLEXED_SEPARATOR, 2) 140 | if len(v) != 2 { 141 | if t.DefaultProcessor != nil { 142 | smb := NewStoredMessageProtocol(in, name, typeId, seqid) 143 | return t.DefaultProcessor.Process(smb, out) 144 | } 145 | return false, fmt.Errorf("Service name not found in message name: %s. Did you forget to use a TMultiplexProtocol in your client?", name) 146 | } 147 | actualProcessor, ok := t.serviceProcessorMap[v[0]] 148 | if !ok { 149 | return false, fmt.Errorf("Service name not found: %s. Did you forget to call registerProcessor()?", v[0]) 150 | } 151 | smb := NewStoredMessageProtocol(in, v[1], typeId, seqid) 152 | return actualProcessor.Process(smb, out) 153 | } 154 | 155 | //Protocol that use stored message for ReadMessageBegin 156 | type storedMessageProtocol struct { 157 | TProtocol 158 | name string 159 | typeId TMessageType 160 | seqid int32 161 | } 162 | 163 | func NewStoredMessageProtocol(protocol TProtocol, name string, typeId TMessageType, seqid int32) *storedMessageProtocol { 164 | return &storedMessageProtocol{protocol, name, typeId, seqid} 165 | } 166 | 167 | func (s *storedMessageProtocol) ReadMessageBegin() (name string, typeId TMessageType, seqid int32, err error) { 168 | return s.name, s.typeId, s.seqid, nil 169 | } 170 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/numeric.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "math" 24 | "strconv" 25 | ) 26 | 27 | type Numeric interface { 28 | Int64() int64 29 | Int32() int32 30 | Int16() int16 31 | Byte() byte 32 | Int() int 33 | Float64() float64 34 | Float32() float32 35 | String() string 36 | isNull() bool 37 | } 38 | 39 | type numeric struct { 40 | iValue int64 41 | dValue float64 42 | sValue string 43 | isNil bool 44 | } 45 | 46 | var ( 47 | INFINITY Numeric 48 | NEGATIVE_INFINITY Numeric 49 | NAN Numeric 50 | ZERO Numeric 51 | NUMERIC_NULL Numeric 52 | ) 53 | 54 | func NewNumericFromDouble(dValue float64) Numeric { 55 | if math.IsInf(dValue, 1) { 56 | return INFINITY 57 | } 58 | if math.IsInf(dValue, -1) { 59 | return NEGATIVE_INFINITY 60 | } 61 | if math.IsNaN(dValue) { 62 | return NAN 63 | } 64 | iValue := int64(dValue) 65 | sValue := strconv.FormatFloat(dValue, 'g', 10, 64) 66 | isNil := false 67 | return &numeric{iValue: iValue, dValue: dValue, sValue: sValue, isNil: isNil} 68 | } 69 | 70 | func NewNumericFromI64(iValue int64) Numeric { 71 | dValue := float64(iValue) 72 | sValue := string(iValue) 73 | isNil := false 74 | return &numeric{iValue: iValue, dValue: dValue, sValue: sValue, isNil: isNil} 75 | } 76 | 77 | func NewNumericFromI32(iValue int32) Numeric { 78 | dValue := float64(iValue) 79 | sValue := string(iValue) 80 | isNil := false 81 | return &numeric{iValue: int64(iValue), dValue: dValue, sValue: sValue, isNil: isNil} 82 | } 83 | 84 | func NewNumericFromString(sValue string) Numeric { 85 | if sValue == INFINITY.String() { 86 | return INFINITY 87 | } 88 | if sValue == NEGATIVE_INFINITY.String() { 89 | return NEGATIVE_INFINITY 90 | } 91 | if sValue == NAN.String() { 92 | return NAN 93 | } 94 | iValue, _ := strconv.ParseInt(sValue, 10, 64) 95 | dValue, _ := strconv.ParseFloat(sValue, 64) 96 | isNil := len(sValue) == 0 97 | return &numeric{iValue: iValue, dValue: dValue, sValue: sValue, isNil: isNil} 98 | } 99 | 100 | func NewNumericFromJSONString(sValue string, isNull bool) Numeric { 101 | if isNull { 102 | return NewNullNumeric() 103 | } 104 | if sValue == JSON_INFINITY { 105 | return INFINITY 106 | } 107 | if sValue == JSON_NEGATIVE_INFINITY { 108 | return NEGATIVE_INFINITY 109 | } 110 | if sValue == JSON_NAN { 111 | return NAN 112 | } 113 | iValue, _ := strconv.ParseInt(sValue, 10, 64) 114 | dValue, _ := strconv.ParseFloat(sValue, 64) 115 | return &numeric{iValue: iValue, dValue: dValue, sValue: sValue, isNil: isNull} 116 | } 117 | 118 | func NewNullNumeric() Numeric { 119 | return &numeric{iValue: 0, dValue: 0.0, sValue: "", isNil: true} 120 | } 121 | 122 | func (p *numeric) Int64() int64 { 123 | return p.iValue 124 | } 125 | 126 | func (p *numeric) Int32() int32 { 127 | return int32(p.iValue) 128 | } 129 | 130 | func (p *numeric) Int16() int16 { 131 | return int16(p.iValue) 132 | } 133 | 134 | func (p *numeric) Byte() byte { 135 | return byte(p.iValue) 136 | } 137 | 138 | func (p *numeric) Int() int { 139 | return int(p.iValue) 140 | } 141 | 142 | func (p *numeric) Float64() float64 { 143 | return p.dValue 144 | } 145 | 146 | func (p *numeric) Float32() float32 { 147 | return float32(p.dValue) 148 | } 149 | 150 | func (p *numeric) String() string { 151 | return p.sValue 152 | } 153 | 154 | func (p *numeric) isNull() bool { 155 | return p.isNil 156 | } 157 | 158 | func init() { 159 | INFINITY = &numeric{iValue: 0, dValue: math.Inf(1), sValue: "Infinity", isNil: false} 160 | NEGATIVE_INFINITY = &numeric{iValue: 0, dValue: math.Inf(-1), sValue: "-Infinity", isNil: false} 161 | NAN = &numeric{iValue: 0, dValue: math.NaN(), sValue: "NaN", isNil: false} 162 | ZERO = &numeric{iValue: 0, dValue: 0, sValue: "0", isNil: false} 163 | NUMERIC_NULL = &numeric{iValue: 0, dValue: 0, sValue: "0", isNil: true} 164 | } 165 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/pointerize.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | /////////////////////////////////////////////////////////////////////////////// 23 | // This file is home to helpers that convert from various base types to 24 | // respective pointer types. This is necessary because Go does not permit 25 | // references to constants, nor can a pointer type to base type be allocated 26 | // and initialized in a single expression. 27 | // 28 | // E.g., this is not allowed: 29 | // 30 | // var ip *int = &5 31 | // 32 | // But this *is* allowed: 33 | // 34 | // func IntPtr(i int) *int { return &i } 35 | // var ip *int = IntPtr(5) 36 | // 37 | // Since pointers to base types are commonplace as [optional] fields in 38 | // exported thrift structs, we factor such helpers here. 39 | /////////////////////////////////////////////////////////////////////////////// 40 | 41 | func Float32Ptr(v float32) *float32 { return &v } 42 | func Float64Ptr(v float64) *float64 { return &v } 43 | func IntPtr(v int) *int { return &v } 44 | func Int32Ptr(v int32) *int32 { return &v } 45 | func Int64Ptr(v int64) *int64 { return &v } 46 | func StringPtr(v string) *string { return &v } 47 | func Uint32Ptr(v uint32) *uint32 { return &v } 48 | func Uint64Ptr(v uint64) *uint64 { return &v } 49 | func BoolPtr(v bool) *bool { return &v } 50 | func ByteSlicePtr(v []byte) *[]byte { return &v } 51 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/processor.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | // A processor is a generic object which operates upon an input stream and 23 | // writes to some output stream. 24 | type TProcessor interface { 25 | Process(in, out TProtocol) (bool, TException) 26 | } 27 | 28 | type TProcessorFunction interface { 29 | Process(seqId int32, in, out TProtocol) (bool, TException) 30 | } 31 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/processor_factory.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | // The default processor factory just returns a singleton 23 | // instance. 24 | type TProcessorFactory interface { 25 | GetProcessor(trans TTransport) TProcessor 26 | } 27 | 28 | type tProcessorFactory struct { 29 | processor TProcessor 30 | } 31 | 32 | func NewTProcessorFactory(p TProcessor) TProcessorFactory { 33 | return &tProcessorFactory{processor: p} 34 | } 35 | 36 | func (p *tProcessorFactory) GetProcessor(trans TTransport) TProcessor { 37 | return p.processor 38 | } 39 | 40 | /** 41 | * The default processor factory just returns a singleton 42 | * instance. 43 | */ 44 | type TProcessorFunctionFactory interface { 45 | GetProcessorFunction(trans TTransport) TProcessorFunction 46 | } 47 | 48 | type tProcessorFunctionFactory struct { 49 | processor TProcessorFunction 50 | } 51 | 52 | func NewTProcessorFunctionFactory(p TProcessorFunction) TProcessorFunctionFactory { 53 | return &tProcessorFunctionFactory{processor: p} 54 | } 55 | 56 | func (p *tProcessorFunctionFactory) GetProcessorFunction(trans TTransport) TProcessorFunction { 57 | return p.processor 58 | } 59 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/protocol.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "errors" 24 | ) 25 | 26 | const ( 27 | VERSION_MASK = 0xffff0000 28 | VERSION_1 = 0x80010000 29 | ) 30 | 31 | type TProtocol interface { 32 | WriteMessageBegin(name string, typeId TMessageType, seqid int32) error 33 | WriteMessageEnd() error 34 | WriteStructBegin(name string) error 35 | WriteStructEnd() error 36 | WriteFieldBegin(name string, typeId TType, id int16) error 37 | WriteFieldEnd() error 38 | WriteFieldStop() error 39 | WriteMapBegin(keyType TType, valueType TType, size int) error 40 | WriteMapEnd() error 41 | WriteListBegin(elemType TType, size int) error 42 | WriteListEnd() error 43 | WriteSetBegin(elemType TType, size int) error 44 | WriteSetEnd() error 45 | WriteBool(value bool) error 46 | WriteByte(value int8) error 47 | WriteI16(value int16) error 48 | WriteI32(value int32) error 49 | WriteI64(value int64) error 50 | WriteDouble(value float64) error 51 | WriteString(value string) error 52 | WriteBinary(value []byte) error 53 | 54 | ReadMessageBegin() (name string, typeId TMessageType, seqid int32, err error) 55 | ReadMessageEnd() error 56 | ReadStructBegin() (name string, err error) 57 | ReadStructEnd() error 58 | ReadFieldBegin() (name string, typeId TType, id int16, err error) 59 | ReadFieldEnd() error 60 | ReadMapBegin() (keyType TType, valueType TType, size int, err error) 61 | ReadMapEnd() error 62 | ReadListBegin() (elemType TType, size int, err error) 63 | ReadListEnd() error 64 | ReadSetBegin() (elemType TType, size int, err error) 65 | ReadSetEnd() error 66 | ReadBool() (value bool, err error) 67 | ReadByte() (value int8, err error) 68 | ReadI16() (value int16, err error) 69 | ReadI32() (value int32, err error) 70 | ReadI64() (value int64, err error) 71 | ReadDouble() (value float64, err error) 72 | ReadString() (value string, err error) 73 | ReadBinary() (value []byte, err error) 74 | 75 | Skip(fieldType TType) (err error) 76 | Flush() (err error) 77 | 78 | Transport() TTransport 79 | } 80 | 81 | // The maximum recursive depth the skip() function will traverse 82 | const DEFAULT_RECURSION_DEPTH = 64 83 | 84 | // Skips over the next data element from the provided input TProtocol object. 85 | func SkipDefaultDepth(prot TProtocol, typeId TType) (err error) { 86 | return Skip(prot, typeId, DEFAULT_RECURSION_DEPTH) 87 | } 88 | 89 | // Skips over the next data element from the provided input TProtocol object. 90 | func Skip(self TProtocol, fieldType TType, maxDepth int) (err error) { 91 | 92 | if maxDepth <= 0 { 93 | return NewTProtocolExceptionWithType( DEPTH_LIMIT, errors.New("Depth limit exceeded")) 94 | } 95 | 96 | switch fieldType { 97 | case STOP: 98 | return 99 | case BOOL: 100 | _, err = self.ReadBool() 101 | return 102 | case BYTE: 103 | _, err = self.ReadByte() 104 | return 105 | case I16: 106 | _, err = self.ReadI16() 107 | return 108 | case I32: 109 | _, err = self.ReadI32() 110 | return 111 | case I64: 112 | _, err = self.ReadI64() 113 | return 114 | case DOUBLE: 115 | _, err = self.ReadDouble() 116 | return 117 | case STRING: 118 | _, err = self.ReadString() 119 | return 120 | case STRUCT: 121 | if _, err = self.ReadStructBegin(); err != nil { 122 | return err 123 | } 124 | for { 125 | _, typeId, _, _ := self.ReadFieldBegin() 126 | if typeId == STOP { 127 | break 128 | } 129 | err := Skip(self, typeId, maxDepth-1) 130 | if err != nil { 131 | return err 132 | } 133 | self.ReadFieldEnd() 134 | } 135 | return self.ReadStructEnd() 136 | case MAP: 137 | keyType, valueType, size, err := self.ReadMapBegin() 138 | if err != nil { 139 | return err 140 | } 141 | for i := 0; i < size; i++ { 142 | err := Skip(self, keyType, maxDepth-1) 143 | if err != nil { 144 | return err 145 | } 146 | self.Skip(valueType) 147 | } 148 | return self.ReadMapEnd() 149 | case SET: 150 | elemType, size, err := self.ReadSetBegin() 151 | if err != nil { 152 | return err 153 | } 154 | for i := 0; i < size; i++ { 155 | err := Skip(self, elemType, maxDepth-1) 156 | if err != nil { 157 | return err 158 | } 159 | } 160 | return self.ReadSetEnd() 161 | case LIST: 162 | elemType, size, err := self.ReadListBegin() 163 | if err != nil { 164 | return err 165 | } 166 | for i := 0; i < size; i++ { 167 | err := Skip(self, elemType, maxDepth-1) 168 | if err != nil { 169 | return err 170 | } 171 | } 172 | return self.ReadListEnd() 173 | } 174 | return nil 175 | } 176 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/protocol_exception.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "encoding/base64" 24 | ) 25 | 26 | // Thrift Protocol exception 27 | type TProtocolException interface { 28 | TException 29 | TypeId() int 30 | } 31 | 32 | const ( 33 | UNKNOWN_PROTOCOL_EXCEPTION = 0 34 | INVALID_DATA = 1 35 | NEGATIVE_SIZE = 2 36 | SIZE_LIMIT = 3 37 | BAD_VERSION = 4 38 | NOT_IMPLEMENTED = 5 39 | DEPTH_LIMIT = 6 40 | ) 41 | 42 | type tProtocolException struct { 43 | typeId int 44 | message string 45 | } 46 | 47 | func (p *tProtocolException) TypeId() int { 48 | return p.typeId 49 | } 50 | 51 | func (p *tProtocolException) String() string { 52 | return p.message 53 | } 54 | 55 | func (p *tProtocolException) Error() string { 56 | return p.message 57 | } 58 | 59 | func NewTProtocolException(err error) TProtocolException { 60 | if err == nil { 61 | return nil 62 | } 63 | if e,ok := err.(TProtocolException); ok { 64 | return e 65 | } 66 | if _, ok := err.(base64.CorruptInputError); ok { 67 | return &tProtocolException{INVALID_DATA, err.Error()} 68 | } 69 | return &tProtocolException{UNKNOWN_PROTOCOL_EXCEPTION, err.Error()} 70 | } 71 | 72 | func NewTProtocolExceptionWithType(errType int, err error) TProtocolException { 73 | if err == nil { 74 | return nil 75 | } 76 | return &tProtocolException{errType, err.Error()} 77 | } 78 | 79 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/protocol_factory.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | // Factory interface for constructing protocol instances. 23 | type TProtocolFactory interface { 24 | GetProtocol(trans TTransport) TProtocol 25 | } 26 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/rich_transport.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import "io" 23 | 24 | type RichTransport struct { 25 | TTransport 26 | } 27 | 28 | // Wraps Transport to provide TRichTransport interface 29 | func NewTRichTransport(trans TTransport) *RichTransport { 30 | return &RichTransport{trans} 31 | } 32 | 33 | func (r *RichTransport) ReadByte() (c byte, err error) { 34 | return readByte(r.TTransport) 35 | } 36 | 37 | func (r *RichTransport) WriteByte(c byte) error { 38 | return writeByte(r.TTransport, c) 39 | } 40 | 41 | func (r *RichTransport) WriteString(s string) (n int, err error) { 42 | return r.Write([]byte(s)) 43 | } 44 | 45 | func (r *RichTransport) RemainingBytes() (num_bytes uint64) { 46 | return r.TTransport.RemainingBytes() 47 | } 48 | 49 | func readByte(r io.Reader) (c byte, err error) { 50 | v := [1]byte{0} 51 | n, err := r.Read(v[0:1]) 52 | if n > 0 && (err == nil || err == io.EOF) { 53 | return v[0], nil 54 | } 55 | if n > 0 && err != nil { 56 | return v[0], err 57 | } 58 | if err != nil { 59 | return 0, err 60 | } 61 | return v[0], nil 62 | } 63 | 64 | func writeByte(w io.Writer, c byte) error { 65 | v := [1]byte{c} 66 | _, err := w.Write(v[0:1]) 67 | return err 68 | } 69 | 70 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/rich_transport_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "bytes" 24 | "errors" 25 | "io" 26 | "reflect" 27 | "testing" 28 | ) 29 | 30 | func TestEnsureTransportsAreRich(t *testing.T) { 31 | buf := bytes.NewBuffer(make([]byte, 0, 1024)) 32 | 33 | transports := []TTransportFactory{ 34 | NewTMemoryBufferTransportFactory(1024), 35 | NewStreamTransportFactory(buf, buf, true), 36 | NewTFramedTransportFactory(NewTMemoryBufferTransportFactory(1024)), 37 | NewTHttpPostClientTransportFactory("http://127.0.0.1"), 38 | } 39 | for _, tf := range transports { 40 | trans := tf.GetTransport(nil) 41 | _, ok := trans.(TRichTransport) 42 | if !ok { 43 | t.Errorf("Transport %s does not implement TRichTransport interface", reflect.ValueOf(trans)) 44 | } 45 | } 46 | } 47 | 48 | // TestReadByte tests whether readByte handles error cases correctly. 49 | func TestReadByte(t *testing.T) { 50 | for i, test := range readByteTests { 51 | v, err := readByte(test.r) 52 | if v != test.v { 53 | t.Fatalf("TestReadByte %d: value differs. Expected %d, got %d", i, test.v, test.r.v) 54 | } 55 | if err != test.err { 56 | t.Fatalf("TestReadByte %d: error differs. Expected %s, got %s", i, test.err, test.r.err) 57 | } 58 | } 59 | } 60 | 61 | var someError = errors.New("Some error") 62 | var readByteTests = []struct { 63 | r *mockReader 64 | v byte 65 | err error 66 | }{ 67 | {&mockReader{0, 55, io.EOF}, 0, io.EOF}, // reader sends EOF w/o data 68 | {&mockReader{0, 55, someError}, 0, someError}, // reader sends some other error 69 | {&mockReader{1, 55, nil}, 55, nil}, // reader sends data w/o error 70 | {&mockReader{1, 55, io.EOF}, 55, nil}, // reader sends data with EOF 71 | {&mockReader{1, 55, someError}, 55, someError}, // reader sends data withsome error 72 | } 73 | 74 | type mockReader struct { 75 | n int 76 | v byte 77 | err error 78 | } 79 | 80 | func (r *mockReader) Read(p []byte) (n int, err error) { 81 | if r.n > 0 { 82 | p[0] = r.v 83 | } 84 | return r.n, r.err 85 | } 86 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/serializer.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | type TSerializer struct { 23 | Transport *TMemoryBuffer 24 | Protocol TProtocol 25 | } 26 | 27 | type TStruct interface { 28 | Write(p TProtocol) error 29 | Read(p TProtocol) error 30 | } 31 | 32 | func NewTSerializer() *TSerializer { 33 | transport := NewTMemoryBufferLen(1024) 34 | protocol := NewTBinaryProtocolFactoryDefault().GetProtocol(transport) 35 | 36 | return &TSerializer{ 37 | transport, 38 | protocol} 39 | } 40 | 41 | func (t *TSerializer) WriteString(msg TStruct) (s string, err error) { 42 | t.Transport.Reset() 43 | 44 | if err = msg.Write(t.Protocol); err != nil { 45 | return 46 | } 47 | 48 | if err = t.Protocol.Flush(); err != nil { 49 | return 50 | } 51 | if err = t.Transport.Flush(); err != nil { 52 | return 53 | } 54 | 55 | return t.Transport.String(), nil 56 | } 57 | 58 | func (t *TSerializer) Write(msg TStruct) (b []byte, err error) { 59 | t.Transport.Reset() 60 | 61 | if err = msg.Write(t.Protocol); err != nil { 62 | return 63 | } 64 | 65 | if err = t.Protocol.Flush(); err != nil { 66 | return 67 | } 68 | 69 | if err = t.Transport.Flush(); err != nil { 70 | return 71 | } 72 | 73 | b = append(b, t.Transport.Bytes()...) 74 | return 75 | } 76 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/serializer_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "errors" 24 | "fmt" 25 | "testing" 26 | ) 27 | 28 | type ProtocolFactory interface { 29 | GetProtocol(t TTransport) TProtocol 30 | } 31 | 32 | func compareStructs(m, m1 MyTestStruct) (bool, error) { 33 | switch { 34 | case m.On != m1.On: 35 | return false, errors.New("Boolean not equal") 36 | case m.B != m1.B: 37 | return false, errors.New("Byte not equal") 38 | case m.Int16 != m1.Int16: 39 | return false, errors.New("Int16 not equal") 40 | case m.Int32 != m1.Int32: 41 | return false, errors.New("Int32 not equal") 42 | case m.Int64 != m1.Int64: 43 | return false, errors.New("Int64 not equal") 44 | case m.D != m1.D: 45 | return false, errors.New("Double not equal") 46 | case m.St != m1.St: 47 | return false, errors.New("String not equal") 48 | 49 | case len(m.Bin) != len(m1.Bin): 50 | return false, errors.New("Binary size not equal") 51 | case len(m.Bin) == len(m1.Bin): 52 | for i := range m.Bin { 53 | if m.Bin[i] != m1.Bin[i] { 54 | return false, errors.New("Binary not equal") 55 | } 56 | } 57 | case len(m.StringMap) != len(m1.StringMap): 58 | return false, errors.New("StringMap size not equal") 59 | case len(m.StringList) != len(m1.StringList): 60 | return false, errors.New("StringList size not equal") 61 | case len(m.StringSet) != len(m1.StringSet): 62 | return false, errors.New("StringSet size not equal") 63 | 64 | case m.E != m1.E: 65 | return false, errors.New("MyTestEnum not equal") 66 | 67 | default: 68 | return true, nil 69 | 70 | } 71 | return true, nil 72 | } 73 | 74 | func ProtocolTest1(test *testing.T, pf ProtocolFactory) (bool, error) { 75 | t := NewTSerializer() 76 | t.Protocol = pf.GetProtocol(t.Transport) 77 | var m = MyTestStruct{} 78 | m.On = true 79 | m.B = int8(0) 80 | m.Int16 = 1 81 | m.Int32 = 2 82 | m.Int64 = 3 83 | m.D = 4.1 84 | m.St = "Test" 85 | m.Bin = make([]byte, 10) 86 | m.StringMap = make(map[string]string, 5) 87 | m.StringList = make([]string, 5) 88 | m.StringSet = make(map[string]bool, 5) 89 | m.E = 2 90 | 91 | s, err := t.WriteString(&m) 92 | if err != nil { 93 | return false, errors.New(fmt.Sprintf("Unable to Serialize struct\n\t %s", err)) 94 | } 95 | 96 | t1 := NewTDeserializer() 97 | t1.Protocol = pf.GetProtocol(t1.Transport) 98 | var m1 = MyTestStruct{} 99 | if err = t1.ReadString(&m1, s); err != nil { 100 | return false, errors.New(fmt.Sprintf("Unable to Deserialize struct\n\t %s", err)) 101 | 102 | } 103 | 104 | return compareStructs(m, m1) 105 | 106 | } 107 | 108 | func ProtocolTest2(test *testing.T, pf ProtocolFactory) (bool, error) { 109 | t := NewTSerializer() 110 | t.Protocol = pf.GetProtocol(t.Transport) 111 | var m = MyTestStruct{} 112 | m.On = false 113 | m.B = int8(0) 114 | m.Int16 = 1 115 | m.Int32 = 2 116 | m.Int64 = 3 117 | m.D = 4.1 118 | m.St = "Test" 119 | m.Bin = make([]byte, 10) 120 | m.StringMap = make(map[string]string, 5) 121 | m.StringList = make([]string, 5) 122 | m.StringSet = make(map[string]bool, 5) 123 | m.E = 2 124 | 125 | s, err := t.WriteString(&m) 126 | if err != nil { 127 | return false, errors.New(fmt.Sprintf("Unable to Serialize struct\n\t %s", err)) 128 | 129 | } 130 | 131 | t1 := NewTDeserializer() 132 | t1.Protocol = pf.GetProtocol(t1.Transport) 133 | var m1 = MyTestStruct{} 134 | if err = t1.ReadString(&m1, s); err != nil { 135 | return false, errors.New(fmt.Sprintf("Unable to Deserialize struct\n\t %s", err)) 136 | 137 | } 138 | 139 | return compareStructs(m, m1) 140 | 141 | } 142 | 143 | func TestSerializer(t *testing.T) { 144 | 145 | var protocol_factories map[string]ProtocolFactory 146 | protocol_factories = make(map[string]ProtocolFactory) 147 | protocol_factories["Binary"] = NewTBinaryProtocolFactoryDefault() 148 | protocol_factories["Compact"] = NewTCompactProtocolFactory() 149 | //protocol_factories["SimpleJSON"] = NewTSimpleJSONProtocolFactory() - write only, can't be read back by design 150 | protocol_factories["JSON"] = NewTJSONProtocolFactory() 151 | 152 | var tests map[string]func(*testing.T, ProtocolFactory) (bool, error) 153 | tests = make(map[string]func(*testing.T, ProtocolFactory) (bool, error)) 154 | tests["Test 1"] = ProtocolTest1 155 | tests["Test 2"] = ProtocolTest2 156 | //tests["Test 3"] = ProtocolTest3 // Example of how to add additional tests 157 | 158 | for name, pf := range protocol_factories { 159 | 160 | for test, f := range tests { 161 | 162 | if s, err := f(t, pf); !s || err != nil { 163 | t.Errorf("%s Failed for %s protocol\n\t %s", test, name, err) 164 | } 165 | 166 | } 167 | } 168 | 169 | } 170 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/server.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | type TServer interface { 23 | ProcessorFactory() TProcessorFactory 24 | ServerTransport() TServerTransport 25 | InputTransportFactory() TTransportFactory 26 | OutputTransportFactory() TTransportFactory 27 | InputProtocolFactory() TProtocolFactory 28 | OutputProtocolFactory() TProtocolFactory 29 | 30 | // Starts the server 31 | Serve() error 32 | // Stops the server. This is optional on a per-implementation basis. Not 33 | // all servers are required to be cleanly stoppable. 34 | Stop() error 35 | } 36 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/server_socket.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "net" 24 | "sync" 25 | "time" 26 | ) 27 | 28 | type TServerSocket struct { 29 | listener net.Listener 30 | addr net.Addr 31 | clientTimeout time.Duration 32 | 33 | // Protects the interrupted value to make it thread safe. 34 | mu sync.RWMutex 35 | interrupted bool 36 | } 37 | 38 | func NewTServerSocket(listenAddr string) (*TServerSocket, error) { 39 | return NewTServerSocketTimeout(listenAddr, 0) 40 | } 41 | 42 | func NewTServerSocketTimeout(listenAddr string, clientTimeout time.Duration) (*TServerSocket, error) { 43 | addr, err := net.ResolveTCPAddr("tcp", listenAddr) 44 | if err != nil { 45 | return nil, err 46 | } 47 | return &TServerSocket{addr: addr, clientTimeout: clientTimeout}, nil 48 | } 49 | 50 | func (p *TServerSocket) Listen() error { 51 | if p.IsListening() { 52 | return nil 53 | } 54 | l, err := net.Listen(p.addr.Network(), p.addr.String()) 55 | if err != nil { 56 | return err 57 | } 58 | p.listener = l 59 | return nil 60 | } 61 | 62 | func (p *TServerSocket) Accept() (TTransport, error) { 63 | p.mu.RLock() 64 | interrupted := p.interrupted 65 | p.mu.RUnlock() 66 | 67 | if interrupted { 68 | return nil, errTransportInterrupted 69 | } 70 | if p.listener == nil { 71 | return nil, NewTTransportException(NOT_OPEN, "No underlying server socket") 72 | } 73 | conn, err := p.listener.Accept() 74 | if err != nil { 75 | return nil, NewTTransportExceptionFromError(err) 76 | } 77 | return NewTSocketFromConnTimeout(conn, p.clientTimeout), nil 78 | } 79 | 80 | // Checks whether the socket is listening. 81 | func (p *TServerSocket) IsListening() bool { 82 | return p.listener != nil 83 | } 84 | 85 | // Connects the socket, creating a new socket object if necessary. 86 | func (p *TServerSocket) Open() error { 87 | if p.IsListening() { 88 | return NewTTransportException(ALREADY_OPEN, "Server socket already open") 89 | } 90 | if l, err := net.Listen(p.addr.Network(), p.addr.String()); err != nil { 91 | return err 92 | } else { 93 | p.listener = l 94 | } 95 | return nil 96 | } 97 | 98 | func (p *TServerSocket) Addr() net.Addr { 99 | if p.listener != nil { 100 | return p.listener.Addr() 101 | } 102 | return p.addr 103 | } 104 | 105 | func (p *TServerSocket) Close() error { 106 | defer func() { 107 | p.listener = nil 108 | }() 109 | if p.IsListening() { 110 | return p.listener.Close() 111 | } 112 | return nil 113 | } 114 | 115 | func (p *TServerSocket) Interrupt() error { 116 | p.mu.Lock() 117 | p.interrupted = true 118 | p.mu.Unlock() 119 | 120 | return nil 121 | } 122 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/server_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "testing" 24 | ) 25 | 26 | func TestNothing(t *testing.T) { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/server_transport.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | // Server transport. Object which provides client transports. 23 | type TServerTransport interface { 24 | Listen() error 25 | Accept() (TTransport, error) 26 | Close() error 27 | 28 | // Optional method implementation. This signals to the server transport 29 | // that it should break out of any accept() or listen() that it is currently 30 | // blocked on. This method, if implemented, MUST be thread safe, as it may 31 | // be called from a different thread context than the other TServerTransport 32 | // methods. 33 | Interrupt() error 34 | } 35 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/simple_server.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "log" 24 | "runtime/debug" 25 | ) 26 | 27 | // Simple, non-concurrent server for testing. 28 | type TSimpleServer struct { 29 | quit chan struct{} 30 | 31 | processorFactory TProcessorFactory 32 | serverTransport TServerTransport 33 | inputTransportFactory TTransportFactory 34 | outputTransportFactory TTransportFactory 35 | inputProtocolFactory TProtocolFactory 36 | outputProtocolFactory TProtocolFactory 37 | } 38 | 39 | func NewTSimpleServer2(processor TProcessor, serverTransport TServerTransport) *TSimpleServer { 40 | return NewTSimpleServerFactory2(NewTProcessorFactory(processor), serverTransport) 41 | } 42 | 43 | func NewTSimpleServer4(processor TProcessor, serverTransport TServerTransport, transportFactory TTransportFactory, protocolFactory TProtocolFactory) *TSimpleServer { 44 | return NewTSimpleServerFactory4(NewTProcessorFactory(processor), 45 | serverTransport, 46 | transportFactory, 47 | protocolFactory, 48 | ) 49 | } 50 | 51 | func NewTSimpleServer6(processor TProcessor, serverTransport TServerTransport, inputTransportFactory TTransportFactory, outputTransportFactory TTransportFactory, inputProtocolFactory TProtocolFactory, outputProtocolFactory TProtocolFactory) *TSimpleServer { 52 | return NewTSimpleServerFactory6(NewTProcessorFactory(processor), 53 | serverTransport, 54 | inputTransportFactory, 55 | outputTransportFactory, 56 | inputProtocolFactory, 57 | outputProtocolFactory, 58 | ) 59 | } 60 | 61 | func NewTSimpleServerFactory2(processorFactory TProcessorFactory, serverTransport TServerTransport) *TSimpleServer { 62 | return NewTSimpleServerFactory6(processorFactory, 63 | serverTransport, 64 | NewTTransportFactory(), 65 | NewTTransportFactory(), 66 | NewTBinaryProtocolFactoryDefault(), 67 | NewTBinaryProtocolFactoryDefault(), 68 | ) 69 | } 70 | 71 | func NewTSimpleServerFactory4(processorFactory TProcessorFactory, serverTransport TServerTransport, transportFactory TTransportFactory, protocolFactory TProtocolFactory) *TSimpleServer { 72 | return NewTSimpleServerFactory6(processorFactory, 73 | serverTransport, 74 | transportFactory, 75 | transportFactory, 76 | protocolFactory, 77 | protocolFactory, 78 | ) 79 | } 80 | 81 | func NewTSimpleServerFactory6(processorFactory TProcessorFactory, serverTransport TServerTransport, inputTransportFactory TTransportFactory, outputTransportFactory TTransportFactory, inputProtocolFactory TProtocolFactory, outputProtocolFactory TProtocolFactory) *TSimpleServer { 82 | return &TSimpleServer{ 83 | processorFactory: processorFactory, 84 | serverTransport: serverTransport, 85 | inputTransportFactory: inputTransportFactory, 86 | outputTransportFactory: outputTransportFactory, 87 | inputProtocolFactory: inputProtocolFactory, 88 | outputProtocolFactory: outputProtocolFactory, 89 | quit: make(chan struct{}, 1), 90 | } 91 | } 92 | 93 | func (p *TSimpleServer) ProcessorFactory() TProcessorFactory { 94 | return p.processorFactory 95 | } 96 | 97 | func (p *TSimpleServer) ServerTransport() TServerTransport { 98 | return p.serverTransport 99 | } 100 | 101 | func (p *TSimpleServer) InputTransportFactory() TTransportFactory { 102 | return p.inputTransportFactory 103 | } 104 | 105 | func (p *TSimpleServer) OutputTransportFactory() TTransportFactory { 106 | return p.outputTransportFactory 107 | } 108 | 109 | func (p *TSimpleServer) InputProtocolFactory() TProtocolFactory { 110 | return p.inputProtocolFactory 111 | } 112 | 113 | func (p *TSimpleServer) OutputProtocolFactory() TProtocolFactory { 114 | return p.outputProtocolFactory 115 | } 116 | 117 | func (p *TSimpleServer) Listen() error { 118 | return p.serverTransport.Listen() 119 | } 120 | 121 | func (p *TSimpleServer) AcceptLoop() error { 122 | for { 123 | client, err := p.serverTransport.Accept() 124 | if err != nil { 125 | select { 126 | case <-p.quit: 127 | return nil 128 | default: 129 | } 130 | return err 131 | } 132 | if client != nil { 133 | go func() { 134 | if err := p.processRequests(client); err != nil { 135 | log.Println("error processing request:", err) 136 | } 137 | }() 138 | } 139 | } 140 | } 141 | 142 | func (p *TSimpleServer) Serve() error { 143 | err := p.Listen() 144 | if err != nil { 145 | return err 146 | } 147 | p.AcceptLoop() 148 | return nil 149 | } 150 | 151 | func (p *TSimpleServer) Stop() error { 152 | p.quit <- struct{}{} 153 | p.serverTransport.Interrupt() 154 | return nil 155 | } 156 | 157 | func (p *TSimpleServer) processRequests(client TTransport) error { 158 | processor := p.processorFactory.GetProcessor(client) 159 | inputTransport := p.inputTransportFactory.GetTransport(client) 160 | outputTransport := p.outputTransportFactory.GetTransport(client) 161 | inputProtocol := p.inputProtocolFactory.GetProtocol(inputTransport) 162 | outputProtocol := p.outputProtocolFactory.GetProtocol(outputTransport) 163 | defer func() { 164 | if e := recover(); e != nil { 165 | log.Printf("panic in processor: %s: %s", e, debug.Stack()) 166 | } 167 | }() 168 | if inputTransport != nil { 169 | defer inputTransport.Close() 170 | } 171 | if outputTransport != nil { 172 | defer outputTransport.Close() 173 | } 174 | for { 175 | ok, err := processor.Process(inputProtocol, outputProtocol) 176 | if err, ok := err.(TTransportException); ok && err.TypeId() == END_OF_FILE { 177 | return nil 178 | } else if err != nil { 179 | log.Printf("error processing request: %s", err) 180 | return err 181 | } 182 | if !ok { 183 | break 184 | } 185 | } 186 | return nil 187 | } 188 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/socket.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "net" 24 | "time" 25 | ) 26 | 27 | type TSocket struct { 28 | conn net.Conn 29 | addr net.Addr 30 | timeout time.Duration 31 | } 32 | 33 | // NewTSocket creates a net.Conn-backed TTransport, given a host and port 34 | // 35 | // Example: 36 | // trans, err := thrift.NewTSocket("localhost:9090") 37 | func NewTSocket(hostPort string) (*TSocket, error) { 38 | return NewTSocketTimeout(hostPort, 0) 39 | } 40 | 41 | // NewTSocketTimeout creates a net.Conn-backed TTransport, given a host and port 42 | // it also accepts a timeout as a time.Duration 43 | func NewTSocketTimeout(hostPort string, timeout time.Duration) (*TSocket, error) { 44 | //conn, err := net.DialTimeout(network, address, timeout) 45 | addr, err := net.ResolveTCPAddr("tcp", hostPort) 46 | if err != nil { 47 | return nil, err 48 | } 49 | return NewTSocketFromAddrTimeout(addr, timeout), nil 50 | } 51 | 52 | // Creates a TSocket from a net.Addr 53 | func NewTSocketFromAddrTimeout(addr net.Addr, timeout time.Duration) *TSocket { 54 | return &TSocket{addr: addr, timeout: timeout} 55 | } 56 | 57 | // Creates a TSocket from an existing net.Conn 58 | func NewTSocketFromConnTimeout(conn net.Conn, timeout time.Duration) *TSocket { 59 | return &TSocket{conn: conn, addr: conn.RemoteAddr(), timeout: timeout} 60 | } 61 | 62 | // Sets the socket timeout 63 | func (p *TSocket) SetTimeout(timeout time.Duration) error { 64 | p.timeout = timeout 65 | return nil 66 | } 67 | 68 | func (p *TSocket) pushDeadline(read, write bool) { 69 | var t time.Time 70 | if p.timeout > 0 { 71 | t = time.Now().Add(time.Duration(p.timeout)) 72 | } 73 | if read && write { 74 | p.conn.SetDeadline(t) 75 | } else if read { 76 | p.conn.SetReadDeadline(t) 77 | } else if write { 78 | p.conn.SetWriteDeadline(t) 79 | } 80 | } 81 | 82 | // Connects the socket, creating a new socket object if necessary. 83 | func (p *TSocket) Open() error { 84 | if p.IsOpen() { 85 | return NewTTransportException(ALREADY_OPEN, "Socket already connected.") 86 | } 87 | if p.addr == nil { 88 | return NewTTransportException(NOT_OPEN, "Cannot open nil address.") 89 | } 90 | if len(p.addr.Network()) == 0 { 91 | return NewTTransportException(NOT_OPEN, "Cannot open bad network name.") 92 | } 93 | if len(p.addr.String()) == 0 { 94 | return NewTTransportException(NOT_OPEN, "Cannot open bad address.") 95 | } 96 | var err error 97 | if p.conn, err = net.DialTimeout(p.addr.Network(), p.addr.String(), p.timeout); err != nil { 98 | return NewTTransportException(NOT_OPEN, err.Error()) 99 | } 100 | return nil 101 | } 102 | 103 | // Retrieve the underlying net.Conn 104 | func (p *TSocket) Conn() net.Conn { 105 | return p.conn 106 | } 107 | 108 | // Returns true if the connection is open 109 | func (p *TSocket) IsOpen() bool { 110 | if p.conn == nil { 111 | return false 112 | } 113 | return true 114 | } 115 | 116 | // Closes the socket. 117 | func (p *TSocket) Close() error { 118 | // Close the socket 119 | if p.conn != nil { 120 | err := p.conn.Close() 121 | if err != nil { 122 | return err 123 | } 124 | p.conn = nil 125 | } 126 | return nil 127 | } 128 | 129 | //Returns the remote address of the socket. 130 | func (p *TSocket) Addr() net.Addr { 131 | return p.addr 132 | } 133 | 134 | func (p *TSocket) Read(buf []byte) (int, error) { 135 | if !p.IsOpen() { 136 | return 0, NewTTransportException(NOT_OPEN, "Connection not open") 137 | } 138 | p.pushDeadline(true, false) 139 | n, err := p.conn.Read(buf) 140 | return n, NewTTransportExceptionFromError(err) 141 | } 142 | 143 | func (p *TSocket) Write(buf []byte) (int, error) { 144 | if !p.IsOpen() { 145 | return 0, NewTTransportException(NOT_OPEN, "Connection not open") 146 | } 147 | p.pushDeadline(false, true) 148 | return p.conn.Write(buf) 149 | } 150 | 151 | func (p *TSocket) Flush() error { 152 | return nil 153 | } 154 | 155 | func (p *TSocket) Interrupt() error { 156 | if !p.IsOpen() { 157 | return nil 158 | } 159 | return p.conn.Close() 160 | } 161 | 162 | func (p *TSocket) RemainingBytes() (num_bytes uint64) { 163 | const maxSize = ^uint64(0) 164 | return maxSize // the thruth is, we just don't know unless framed is used 165 | } 166 | 167 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/ssl_server_socket.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "net" 24 | "time" 25 | "crypto/tls" 26 | ) 27 | 28 | type TSSLServerSocket struct { 29 | listener net.Listener 30 | addr net.Addr 31 | clientTimeout time.Duration 32 | interrupted bool 33 | cfg *tls.Config 34 | } 35 | 36 | func NewTSSLServerSocket(listenAddr string, cfg *tls.Config) (*TSSLServerSocket, error) { 37 | return NewTSSLServerSocketTimeout(listenAddr, cfg, 0) 38 | } 39 | 40 | func NewTSSLServerSocketTimeout(listenAddr string, cfg *tls.Config, clientTimeout time.Duration) (*TSSLServerSocket, error) { 41 | addr, err := net.ResolveTCPAddr("tcp", listenAddr) 42 | if err != nil { 43 | return nil, err 44 | } 45 | return &TSSLServerSocket{addr: addr, clientTimeout: clientTimeout, cfg: cfg}, nil 46 | } 47 | 48 | func (p *TSSLServerSocket) Listen() error { 49 | if p.IsListening() { 50 | return nil 51 | } 52 | l, err := tls.Listen(p.addr.Network(), p.addr.String(), p.cfg) 53 | if err != nil { 54 | return err 55 | } 56 | p.listener = l 57 | return nil 58 | } 59 | 60 | func (p *TSSLServerSocket) Accept() (TTransport, error) { 61 | if p.interrupted { 62 | return nil, errTransportInterrupted 63 | } 64 | if p.listener == nil { 65 | return nil, NewTTransportException(NOT_OPEN, "No underlying server socket") 66 | } 67 | conn, err := p.listener.Accept() 68 | if err != nil { 69 | return nil, NewTTransportExceptionFromError(err) 70 | } 71 | return NewTSSLSocketFromConnTimeout(conn, p.cfg, p.clientTimeout), nil 72 | } 73 | 74 | // Checks whether the socket is listening. 75 | func (p *TSSLServerSocket) IsListening() bool { 76 | return p.listener != nil 77 | } 78 | 79 | // Connects the socket, creating a new socket object if necessary. 80 | func (p *TSSLServerSocket) Open() error { 81 | if p.IsListening() { 82 | return NewTTransportException(ALREADY_OPEN, "Server socket already open") 83 | } 84 | if l, err := tls.Listen(p.addr.Network(), p.addr.String(), p.cfg); err != nil { 85 | return err 86 | } else { 87 | p.listener = l 88 | } 89 | return nil 90 | } 91 | 92 | func (p *TSSLServerSocket) Addr() net.Addr { 93 | return p.addr 94 | } 95 | 96 | func (p *TSSLServerSocket) Close() error { 97 | defer func() { 98 | p.listener = nil 99 | }() 100 | if p.IsListening() { 101 | return p.listener.Close() 102 | } 103 | return nil 104 | } 105 | 106 | func (p *TSSLServerSocket) Interrupt() error { 107 | p.interrupted = true 108 | return nil 109 | } 110 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/ssl_socket.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "crypto/tls" 24 | "net" 25 | "time" 26 | ) 27 | 28 | type TSSLSocket struct { 29 | conn net.Conn 30 | // hostPort contains host:port (e.g. "asdf.com:12345"). The field is 31 | // only valid if addr is nil. 32 | hostPort string 33 | // addr is nil when hostPort is not "", and is only used when the 34 | // TSSLSocket is constructed from a net.Addr. 35 | addr net.Addr 36 | timeout time.Duration 37 | cfg *tls.Config 38 | } 39 | 40 | // NewTSSLSocket creates a net.Conn-backed TTransport, given a host and port and tls Configuration 41 | // 42 | // Example: 43 | // trans, err := thrift.NewTSSLSocket("localhost:9090", nil) 44 | func NewTSSLSocket(hostPort string, cfg *tls.Config) (*TSSLSocket, error) { 45 | return NewTSSLSocketTimeout(hostPort, cfg, 0) 46 | } 47 | 48 | // NewTSSLSocketTimeout creates a net.Conn-backed TTransport, given a host and port 49 | // it also accepts a tls Configuration and a timeout as a time.Duration 50 | func NewTSSLSocketTimeout(hostPort string, cfg *tls.Config, timeout time.Duration) (*TSSLSocket, error) { 51 | return &TSSLSocket{hostPort: hostPort, timeout: timeout, cfg: cfg}, nil 52 | } 53 | 54 | // Creates a TSSLSocket from a net.Addr 55 | func NewTSSLSocketFromAddrTimeout(addr net.Addr, cfg *tls.Config, timeout time.Duration) *TSSLSocket { 56 | return &TSSLSocket{addr: addr, timeout: timeout, cfg: cfg} 57 | } 58 | 59 | // Creates a TSSLSocket from an existing net.Conn 60 | func NewTSSLSocketFromConnTimeout(conn net.Conn, cfg *tls.Config, timeout time.Duration) *TSSLSocket { 61 | return &TSSLSocket{conn: conn, addr: conn.RemoteAddr(), timeout: timeout, cfg: cfg} 62 | } 63 | 64 | // Sets the socket timeout 65 | func (p *TSSLSocket) SetTimeout(timeout time.Duration) error { 66 | p.timeout = timeout 67 | return nil 68 | } 69 | 70 | func (p *TSSLSocket) pushDeadline(read, write bool) { 71 | var t time.Time 72 | if p.timeout > 0 { 73 | t = time.Now().Add(time.Duration(p.timeout)) 74 | } 75 | if read && write { 76 | p.conn.SetDeadline(t) 77 | } else if read { 78 | p.conn.SetReadDeadline(t) 79 | } else if write { 80 | p.conn.SetWriteDeadline(t) 81 | } 82 | } 83 | 84 | // Connects the socket, creating a new socket object if necessary. 85 | func (p *TSSLSocket) Open() error { 86 | var err error 87 | // If we have a hostname, we need to pass the hostname to tls.Dial for 88 | // certificate hostname checks. 89 | if p.hostPort != "" { 90 | if p.conn, err = tls.Dial("tcp", p.hostPort, p.cfg); err != nil { 91 | return NewTTransportException(NOT_OPEN, err.Error()) 92 | } 93 | } else { 94 | if p.IsOpen() { 95 | return NewTTransportException(ALREADY_OPEN, "Socket already connected.") 96 | } 97 | if p.addr == nil { 98 | return NewTTransportException(NOT_OPEN, "Cannot open nil address.") 99 | } 100 | if len(p.addr.Network()) == 0 { 101 | return NewTTransportException(NOT_OPEN, "Cannot open bad network name.") 102 | } 103 | if len(p.addr.String()) == 0 { 104 | return NewTTransportException(NOT_OPEN, "Cannot open bad address.") 105 | } 106 | if p.conn, err = tls.Dial(p.addr.Network(), p.addr.String(), p.cfg); err != nil { 107 | return NewTTransportException(NOT_OPEN, err.Error()) 108 | } 109 | } 110 | return nil 111 | } 112 | 113 | // Retrieve the underlying net.Conn 114 | func (p *TSSLSocket) Conn() net.Conn { 115 | return p.conn 116 | } 117 | 118 | // Returns true if the connection is open 119 | func (p *TSSLSocket) IsOpen() bool { 120 | if p.conn == nil { 121 | return false 122 | } 123 | return true 124 | } 125 | 126 | // Closes the socket. 127 | func (p *TSSLSocket) Close() error { 128 | // Close the socket 129 | if p.conn != nil { 130 | err := p.conn.Close() 131 | if err != nil { 132 | return err 133 | } 134 | p.conn = nil 135 | } 136 | return nil 137 | } 138 | 139 | func (p *TSSLSocket) Read(buf []byte) (int, error) { 140 | if !p.IsOpen() { 141 | return 0, NewTTransportException(NOT_OPEN, "Connection not open") 142 | } 143 | p.pushDeadline(true, false) 144 | n, err := p.conn.Read(buf) 145 | return n, NewTTransportExceptionFromError(err) 146 | } 147 | 148 | func (p *TSSLSocket) Write(buf []byte) (int, error) { 149 | if !p.IsOpen() { 150 | return 0, NewTTransportException(NOT_OPEN, "Connection not open") 151 | } 152 | p.pushDeadline(false, true) 153 | return p.conn.Write(buf) 154 | } 155 | 156 | func (p *TSSLSocket) Flush() error { 157 | return nil 158 | } 159 | 160 | func (p *TSSLSocket) Interrupt() error { 161 | if !p.IsOpen() { 162 | return nil 163 | } 164 | return p.conn.Close() 165 | } 166 | 167 | func (p *TSSLSocket) RemainingBytes() (num_bytes uint64) { 168 | const maxSize = ^uint64(0) 169 | return maxSize // the thruth is, we just don't know unless framed is used 170 | } 171 | 172 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/transport.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "errors" 24 | "io" 25 | ) 26 | 27 | var errTransportInterrupted = errors.New("Transport Interrupted") 28 | 29 | type Flusher interface { 30 | Flush() (err error) 31 | } 32 | 33 | type ReadSizeProvider interface { 34 | RemainingBytes() (num_bytes uint64) 35 | } 36 | 37 | 38 | // Encapsulates the I/O layer 39 | type TTransport interface { 40 | io.ReadWriteCloser 41 | Flusher 42 | ReadSizeProvider 43 | 44 | // Opens the transport for communication 45 | Open() error 46 | 47 | // Returns true if the transport is open 48 | IsOpen() bool 49 | } 50 | 51 | type stringWriter interface { 52 | WriteString(s string) (n int, err error) 53 | } 54 | 55 | 56 | // This is "enchanced" transport with extra capabilities. You need to use one of these 57 | // to construct protocol. 58 | // Notably, TSocket does not implement this interface, and it is always a mistake to use 59 | // TSocket directly in protocol. 60 | type TRichTransport interface { 61 | io.ReadWriter 62 | io.ByteReader 63 | io.ByteWriter 64 | stringWriter 65 | Flusher 66 | ReadSizeProvider 67 | } 68 | 69 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/transport_exception.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "errors" 24 | "io" 25 | ) 26 | 27 | type timeoutable interface { 28 | Timeout() bool 29 | } 30 | 31 | // Thrift Transport exception 32 | type TTransportException interface { 33 | TException 34 | TypeId() int 35 | Err() error 36 | } 37 | 38 | const ( 39 | UNKNOWN_TRANSPORT_EXCEPTION = 0 40 | NOT_OPEN = 1 41 | ALREADY_OPEN = 2 42 | TIMED_OUT = 3 43 | END_OF_FILE = 4 44 | ) 45 | 46 | type tTransportException struct { 47 | typeId int 48 | err error 49 | } 50 | 51 | func (p *tTransportException) TypeId() int { 52 | return p.typeId 53 | } 54 | 55 | func (p *tTransportException) Error() string { 56 | return p.err.Error() 57 | } 58 | 59 | func (p *tTransportException) Err() error { 60 | return p.err 61 | } 62 | 63 | func NewTTransportException(t int, e string) TTransportException { 64 | return &tTransportException{typeId: t, err: errors.New(e)} 65 | } 66 | 67 | func NewTTransportExceptionFromError(e error) TTransportException { 68 | if e == nil { 69 | return nil 70 | } 71 | 72 | if t, ok := e.(TTransportException); ok { 73 | return t 74 | } 75 | 76 | switch v := e.(type) { 77 | case TTransportException: 78 | return v 79 | case timeoutable: 80 | if v.Timeout() { 81 | return &tTransportException{typeId: TIMED_OUT, err: e} 82 | } 83 | } 84 | 85 | if e == io.EOF { 86 | return &tTransportException{typeId: END_OF_FILE, err: e} 87 | } 88 | 89 | return &tTransportException{typeId: UNKNOWN_TRANSPORT_EXCEPTION, err: e} 90 | } 91 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/transport_exception_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "fmt" 24 | "io" 25 | 26 | "testing" 27 | ) 28 | 29 | type timeout struct{ timedout bool } 30 | 31 | func (t *timeout) Timeout() bool { 32 | return t.timedout 33 | } 34 | 35 | func (t *timeout) Error() string { 36 | return fmt.Sprintf("Timeout: %v", t.timedout) 37 | } 38 | 39 | func TestTExceptionTimeout(t *testing.T) { 40 | timeout := &timeout{true} 41 | exception := NewTTransportExceptionFromError(timeout) 42 | if timeout.Error() != exception.Error() { 43 | t.Fatalf("Error did not match: expected %q, got %q", timeout.Error(), exception.Error()) 44 | } 45 | 46 | if exception.TypeId() != TIMED_OUT { 47 | t.Fatalf("TypeId was not TIMED_OUT: expected %v, got %v", TIMED_OUT, exception.TypeId()) 48 | } 49 | } 50 | 51 | func TestTExceptionEOF(t *testing.T) { 52 | exception := NewTTransportExceptionFromError(io.EOF) 53 | if io.EOF.Error() != exception.Error() { 54 | t.Fatalf("Error did not match: expected %q, got %q", io.EOF.Error(), exception.Error()) 55 | } 56 | 57 | if exception.TypeId() != END_OF_FILE { 58 | t.Fatalf("TypeId was not END_OF_FILE: expected %v, got %v", END_OF_FILE, exception.TypeId()) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/transport_factory.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | // Factory class used to create wrapped instance of Transports. 23 | // This is used primarily in servers, which get Transports from 24 | // a ServerTransport and then may want to mutate them (i.e. create 25 | // a BufferedTransport from the underlying base transport) 26 | type TTransportFactory interface { 27 | GetTransport(trans TTransport) TTransport 28 | } 29 | 30 | type tTransportFactory struct{} 31 | 32 | // Return a wrapped instance of the base Transport. 33 | func (p *tTransportFactory) GetTransport(trans TTransport) TTransport { 34 | return trans 35 | } 36 | 37 | func NewTTransportFactory() TTransportFactory { 38 | return &tTransportFactory{} 39 | } 40 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/transport_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "io" 24 | "net" 25 | "strconv" 26 | "testing" 27 | ) 28 | 29 | const TRANSPORT_BINARY_DATA_SIZE = 4096 30 | 31 | var ( 32 | transport_bdata []byte // test data for writing; same as data 33 | transport_header map[string]string 34 | ) 35 | 36 | func init() { 37 | transport_bdata = make([]byte, TRANSPORT_BINARY_DATA_SIZE) 38 | for i := 0; i < TRANSPORT_BINARY_DATA_SIZE; i++ { 39 | transport_bdata[i] = byte((i + 'a') % 255) 40 | } 41 | transport_header = map[string]string{"key": "User-Agent", 42 | "value": "Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36"} 43 | } 44 | 45 | func TransportTest(t *testing.T, writeTrans TTransport, readTrans TTransport) { 46 | buf := make([]byte, TRANSPORT_BINARY_DATA_SIZE) 47 | if !writeTrans.IsOpen() { 48 | t.Fatalf("Transport %T not open: %s", writeTrans, writeTrans) 49 | } 50 | if !readTrans.IsOpen() { 51 | t.Fatalf("Transport %T not open: %s", readTrans, readTrans) 52 | } 53 | _, err := writeTrans.Write(transport_bdata) 54 | if err != nil { 55 | t.Fatalf("Transport %T cannot write binary data of length %d: %s", writeTrans, len(transport_bdata), err) 56 | } 57 | err = writeTrans.Flush() 58 | if err != nil { 59 | t.Fatalf("Transport %T cannot flush write of binary data: %s", writeTrans, err) 60 | } 61 | n, err := io.ReadFull(readTrans, buf) 62 | if err != nil { 63 | t.Errorf("Transport %T cannot read binary data of length %d: %s", readTrans, TRANSPORT_BINARY_DATA_SIZE, err) 64 | } 65 | if n != TRANSPORT_BINARY_DATA_SIZE { 66 | t.Errorf("Transport %T read only %d instead of %d bytes of binary data", readTrans, n, TRANSPORT_BINARY_DATA_SIZE) 67 | } 68 | for k, v := range buf { 69 | if v != transport_bdata[k] { 70 | t.Fatalf("Transport %T read %d instead of %d for index %d of binary data 2", readTrans, v, transport_bdata[k], k) 71 | } 72 | } 73 | _, err = writeTrans.Write(transport_bdata) 74 | if err != nil { 75 | t.Fatalf("Transport %T cannot write binary data 2 of length %d: %s", writeTrans, len(transport_bdata), err) 76 | } 77 | err = writeTrans.Flush() 78 | if err != nil { 79 | t.Fatalf("Transport %T cannot flush write binary data 2: %s", writeTrans, err) 80 | } 81 | buf = make([]byte, TRANSPORT_BINARY_DATA_SIZE) 82 | read := 1 83 | for n = 0; n < TRANSPORT_BINARY_DATA_SIZE && read != 0; { 84 | read, err = readTrans.Read(buf[n:]) 85 | if err != nil { 86 | t.Errorf("Transport %T cannot read binary data 2 of total length %d from offset %d: %s", readTrans, TRANSPORT_BINARY_DATA_SIZE, n, err) 87 | } 88 | n += read 89 | } 90 | if n != TRANSPORT_BINARY_DATA_SIZE { 91 | t.Errorf("Transport %T read only %d instead of %d bytes of binary data 2", readTrans, n, TRANSPORT_BINARY_DATA_SIZE) 92 | } 93 | for k, v := range buf { 94 | if v != transport_bdata[k] { 95 | t.Fatalf("Transport %T read %d instead of %d for index %d of binary data 2", readTrans, v, transport_bdata[k], k) 96 | } 97 | } 98 | } 99 | 100 | func TransportHeaderTest(t *testing.T, writeTrans TTransport, readTrans TTransport) { 101 | buf := make([]byte, TRANSPORT_BINARY_DATA_SIZE) 102 | if !writeTrans.IsOpen() { 103 | t.Fatalf("Transport %T not open: %s", writeTrans, writeTrans) 104 | } 105 | if !readTrans.IsOpen() { 106 | t.Fatalf("Transport %T not open: %s", readTrans, readTrans) 107 | } 108 | // Need to assert type of TTransport to THttpClient to expose the Setter 109 | httpWPostTrans := writeTrans.(*THttpClient) 110 | httpWPostTrans.SetHeader(transport_header["key"], transport_header["value"]) 111 | 112 | _, err := writeTrans.Write(transport_bdata) 113 | if err != nil { 114 | t.Fatalf("Transport %T cannot write binary data of length %d: %s", writeTrans, len(transport_bdata), err) 115 | } 116 | err = writeTrans.Flush() 117 | if err != nil { 118 | t.Fatalf("Transport %T cannot flush write of binary data: %s", writeTrans, err) 119 | } 120 | // Need to assert type of TTransport to THttpClient to expose the Getter 121 | httpRPostTrans := readTrans.(*THttpClient) 122 | readHeader := httpRPostTrans.GetHeader(transport_header["key"]) 123 | if err != nil { 124 | t.Errorf("Transport %T cannot read HTTP Header Value", httpRPostTrans) 125 | } 126 | 127 | if transport_header["value"] != readHeader { 128 | t.Errorf("Expected HTTP Header Value %s, got %s", transport_header["value"], readHeader) 129 | } 130 | n, err := io.ReadFull(readTrans, buf) 131 | if err != nil { 132 | t.Errorf("Transport %T cannot read binary data of length %d: %s", readTrans, TRANSPORT_BINARY_DATA_SIZE, err) 133 | } 134 | if n != TRANSPORT_BINARY_DATA_SIZE { 135 | t.Errorf("Transport %T read only %d instead of %d bytes of binary data", readTrans, n, TRANSPORT_BINARY_DATA_SIZE) 136 | } 137 | for k, v := range buf { 138 | if v != transport_bdata[k] { 139 | t.Fatalf("Transport %T read %d instead of %d for index %d of binary data 2", readTrans, v, transport_bdata[k], k) 140 | } 141 | } 142 | } 143 | 144 | func CloseTransports(t *testing.T, readTrans TTransport, writeTrans TTransport) { 145 | err := readTrans.Close() 146 | if err != nil { 147 | t.Errorf("Transport %T cannot close read transport: %s", readTrans, err) 148 | } 149 | if writeTrans != readTrans { 150 | err = writeTrans.Close() 151 | if err != nil { 152 | t.Errorf("Transport %T cannot close write transport: %s", writeTrans, err) 153 | } 154 | } 155 | } 156 | 157 | func FindAvailableTCPServerPort(startPort int) (net.Addr, error) { 158 | for i := startPort; i < 65535; i++ { 159 | s := "127.0.0.1:" + strconv.Itoa(i) 160 | l, err := net.Listen("tcp", s) 161 | if err == nil { 162 | l.Close() 163 | return net.ResolveTCPAddr("tcp", s) 164 | } 165 | } 166 | return nil, NewTTransportException(UNKNOWN_TRANSPORT_EXCEPTION, "Could not find available server port") 167 | } 168 | 169 | func valueInSlice(value string, slice []string) bool { 170 | for _, v := range slice { 171 | if value == v { 172 | return true 173 | } 174 | } 175 | return false 176 | } 177 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/type.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | // Type constants in the Thrift protocol 23 | type TType byte 24 | 25 | const ( 26 | STOP = 0 27 | VOID = 1 28 | BOOL = 2 29 | BYTE = 3 30 | I08 = 3 31 | DOUBLE = 4 32 | I16 = 6 33 | I32 = 8 34 | I64 = 10 35 | STRING = 11 36 | UTF7 = 11 37 | STRUCT = 12 38 | MAP = 13 39 | SET = 14 40 | LIST = 15 41 | UTF8 = 16 42 | UTF16 = 17 43 | BINARY = 18 44 | ) 45 | 46 | var typeNames = map[int]string{ 47 | STOP: "STOP", 48 | VOID: "VOID", 49 | BOOL: "BOOL", 50 | BYTE: "BYTE", 51 | I16: "I16", 52 | I32: "I32", 53 | I64: "I64", 54 | STRING: "STRING", 55 | STRUCT: "STRUCT", 56 | MAP: "MAP", 57 | SET: "SET", 58 | LIST: "LIST", 59 | UTF8: "UTF8", 60 | UTF16: "UTF16", 61 | } 62 | 63 | func (p TType) String() string { 64 | if s, ok := typeNames[int(p)]; ok { 65 | return s 66 | } 67 | return "Unknown" 68 | } 69 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/zlib_transport.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "compress/zlib" 24 | "io" 25 | "log" 26 | ) 27 | 28 | // TZlibTransportFactory is a factory for TZlibTransport instances 29 | type TZlibTransportFactory struct { 30 | level int 31 | } 32 | 33 | // TZlibTransport is a TTransport implementation that makes use of zlib compression. 34 | type TZlibTransport struct { 35 | reader io.ReadCloser 36 | transport TTransport 37 | writer *zlib.Writer 38 | } 39 | 40 | // GetTransport constructs a new instance of NewTZlibTransport 41 | func (p *TZlibTransportFactory) GetTransport(trans TTransport) TTransport { 42 | t, _ := NewTZlibTransport(trans, p.level) 43 | return t 44 | } 45 | 46 | // NewTZlibTransportFactory constructs a new instance of NewTZlibTransportFactory 47 | func NewTZlibTransportFactory(level int) *TZlibTransportFactory { 48 | return &TZlibTransportFactory{level: level} 49 | } 50 | 51 | // NewTZlibTransport constructs a new instance of TZlibTransport 52 | func NewTZlibTransport(trans TTransport, level int) (*TZlibTransport, error) { 53 | w, err := zlib.NewWriterLevel(trans, level) 54 | if err != nil { 55 | log.Println(err) 56 | return nil, err 57 | } 58 | 59 | return &TZlibTransport{ 60 | writer: w, 61 | transport: trans, 62 | }, nil 63 | } 64 | 65 | // Close closes the reader and writer (flushing any unwritten data) and closes 66 | // the underlying transport. 67 | func (z *TZlibTransport) Close() error { 68 | if z.reader != nil { 69 | if err := z.reader.Close(); err != nil { 70 | return err 71 | } 72 | } 73 | if err := z.writer.Close(); err != nil { 74 | return err 75 | } 76 | return z.transport.Close() 77 | } 78 | 79 | // Flush flushes the writer and its underlying transport. 80 | func (z *TZlibTransport) Flush() error { 81 | if err := z.writer.Flush(); err != nil { 82 | return err 83 | } 84 | return z.transport.Flush() 85 | } 86 | 87 | // IsOpen returns true if the transport is open 88 | func (z *TZlibTransport) IsOpen() bool { 89 | return z.transport.IsOpen() 90 | } 91 | 92 | // Open opens the transport for communication 93 | func (z *TZlibTransport) Open() error { 94 | return z.transport.Open() 95 | } 96 | 97 | func (z *TZlibTransport) Read(p []byte) (int, error) { 98 | if z.reader == nil { 99 | r, err := zlib.NewReader(z.transport) 100 | if err != nil { 101 | return 0, NewTTransportExceptionFromError(err) 102 | } 103 | z.reader = r 104 | } 105 | 106 | return z.reader.Read(p) 107 | } 108 | 109 | // RemainingBytes returns the size in bytes of the data that is still to be 110 | // read. 111 | func (z *TZlibTransport) RemainingBytes() uint64 { 112 | return z.transport.RemainingBytes() 113 | } 114 | 115 | func (z *TZlibTransport) Write(p []byte) (int, error) { 116 | return z.writer.Write(p) 117 | } 118 | -------------------------------------------------------------------------------- /vendor/git.apache.org/thrift.git/lib/go/thrift/zlib_transport_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import ( 23 | "compress/zlib" 24 | "testing" 25 | ) 26 | 27 | func TestZlibTransport(t *testing.T) { 28 | trans, err := NewTZlibTransport(NewTMemoryBuffer(), zlib.BestCompression) 29 | if err != nil { 30 | t.Fatal(err) 31 | } 32 | TransportTest(t, trans, trans) 33 | } 34 | -------------------------------------------------------------------------------- /vendor/shared/constants.go: -------------------------------------------------------------------------------- 1 | // Autogenerated by Thrift Compiler (1.0.0-dev) 2 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 3 | 4 | package shared 5 | 6 | import ( 7 | "bytes" 8 | "fmt" 9 | "git.apache.org/thrift.git/lib/go/thrift" 10 | ) 11 | 12 | // (needed to ensure safety because of naive import list construction.) 13 | var _ = thrift.ZERO 14 | var _ = fmt.Printf 15 | var _ = bytes.Equal 16 | 17 | func init() { 18 | } 19 | -------------------------------------------------------------------------------- /vendor/shared/shared_service-remote/shared_service-remote.go: -------------------------------------------------------------------------------- 1 | // Autogenerated by Thrift Compiler (1.0.0-dev) 2 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 3 | 4 | package main 5 | 6 | import ( 7 | "flag" 8 | "fmt" 9 | "git.apache.org/thrift.git/lib/go/thrift" 10 | "math" 11 | "net" 12 | "net/url" 13 | "os" 14 | "shared" 15 | "strconv" 16 | "strings" 17 | ) 18 | 19 | func Usage() { 20 | fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:") 21 | flag.PrintDefaults() 22 | fmt.Fprintln(os.Stderr, "\nFunctions:") 23 | fmt.Fprintln(os.Stderr, " SharedStruct getStruct(i32 key)") 24 | fmt.Fprintln(os.Stderr) 25 | os.Exit(0) 26 | } 27 | 28 | func main() { 29 | flag.Usage = Usage 30 | var host string 31 | var port int 32 | var protocol string 33 | var urlString string 34 | var framed bool 35 | var useHttp bool 36 | var parsedUrl url.URL 37 | var trans thrift.TTransport 38 | _ = strconv.Atoi 39 | _ = math.Abs 40 | flag.Usage = Usage 41 | flag.StringVar(&host, "h", "localhost", "Specify host and port") 42 | flag.IntVar(&port, "p", 9090, "Specify port") 43 | flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)") 44 | flag.StringVar(&urlString, "u", "", "Specify the url") 45 | flag.BoolVar(&framed, "framed", false, "Use framed transport") 46 | flag.BoolVar(&useHttp, "http", false, "Use http") 47 | flag.Parse() 48 | 49 | if len(urlString) > 0 { 50 | parsedUrl, err := url.Parse(urlString) 51 | if err != nil { 52 | fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) 53 | flag.Usage() 54 | } 55 | host = parsedUrl.Host 56 | useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http" 57 | } else if useHttp { 58 | _, err := url.Parse(fmt.Sprint("http://", host, ":", port)) 59 | if err != nil { 60 | fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) 61 | flag.Usage() 62 | } 63 | } 64 | 65 | cmd := flag.Arg(0) 66 | var err error 67 | if useHttp { 68 | trans, err = thrift.NewTHttpClient(parsedUrl.String()) 69 | } else { 70 | portStr := fmt.Sprint(port) 71 | if strings.Contains(host, ":") { 72 | host, portStr, err = net.SplitHostPort(host) 73 | if err != nil { 74 | fmt.Fprintln(os.Stderr, "error with host:", err) 75 | os.Exit(1) 76 | } 77 | } 78 | trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr)) 79 | if err != nil { 80 | fmt.Fprintln(os.Stderr, "error resolving address:", err) 81 | os.Exit(1) 82 | } 83 | if framed { 84 | trans = thrift.NewTFramedTransport(trans) 85 | } 86 | } 87 | if err != nil { 88 | fmt.Fprintln(os.Stderr, "Error creating transport", err) 89 | os.Exit(1) 90 | } 91 | defer trans.Close() 92 | var protocolFactory thrift.TProtocolFactory 93 | switch protocol { 94 | case "compact": 95 | protocolFactory = thrift.NewTCompactProtocolFactory() 96 | break 97 | case "simplejson": 98 | protocolFactory = thrift.NewTSimpleJSONProtocolFactory() 99 | break 100 | case "json": 101 | protocolFactory = thrift.NewTJSONProtocolFactory() 102 | break 103 | case "binary", "": 104 | protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() 105 | break 106 | default: 107 | fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol) 108 | Usage() 109 | os.Exit(1) 110 | } 111 | client := shared.NewSharedServiceClientFactory(trans, protocolFactory) 112 | if err := trans.Open(); err != nil { 113 | fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err) 114 | os.Exit(1) 115 | } 116 | 117 | switch cmd { 118 | case "getStruct": 119 | if flag.NArg()-1 != 1 { 120 | fmt.Fprintln(os.Stderr, "GetStruct requires 1 args") 121 | flag.Usage() 122 | } 123 | tmp0, err4 := (strconv.Atoi(flag.Arg(1))) 124 | if err4 != nil { 125 | Usage() 126 | return 127 | } 128 | argvalue0 := int32(tmp0) 129 | value0 := argvalue0 130 | fmt.Print(client.GetStruct(value0)) 131 | fmt.Print("\n") 132 | break 133 | case "": 134 | Usage() 135 | break 136 | default: 137 | fmt.Fprintln(os.Stderr, "Invalid function ", cmd) 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /vendor/shared/ttypes.go: -------------------------------------------------------------------------------- 1 | // Autogenerated by Thrift Compiler (1.0.0-dev) 2 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 3 | 4 | package shared 5 | 6 | import ( 7 | "bytes" 8 | "fmt" 9 | "git.apache.org/thrift.git/lib/go/thrift" 10 | ) 11 | 12 | // (needed to ensure safety because of naive import list construction.) 13 | var _ = thrift.ZERO 14 | var _ = fmt.Printf 15 | var _ = bytes.Equal 16 | 17 | var GoUnusedProtection__ int 18 | 19 | // Attributes: 20 | // - Key 21 | // - Value 22 | type SharedStruct struct { 23 | Key int32 `thrift:"key,1" db:"key" json:"key"` 24 | Value string `thrift:"value,2" db:"value" json:"value"` 25 | } 26 | 27 | func NewSharedStruct() *SharedStruct { 28 | return &SharedStruct{} 29 | } 30 | 31 | func (p *SharedStruct) GetKey() int32 { 32 | return p.Key 33 | } 34 | 35 | func (p *SharedStruct) GetValue() string { 36 | return p.Value 37 | } 38 | func (p *SharedStruct) Read(iprot thrift.TProtocol) error { 39 | if _, err := iprot.ReadStructBegin(); err != nil { 40 | return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) 41 | } 42 | 43 | for { 44 | _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() 45 | if err != nil { 46 | return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) 47 | } 48 | if fieldTypeId == thrift.STOP { 49 | break 50 | } 51 | switch fieldId { 52 | case 1: 53 | if err := p.readField1(iprot); err != nil { 54 | return err 55 | } 56 | case 2: 57 | if err := p.readField2(iprot); err != nil { 58 | return err 59 | } 60 | default: 61 | if err := iprot.Skip(fieldTypeId); err != nil { 62 | return err 63 | } 64 | } 65 | if err := iprot.ReadFieldEnd(); err != nil { 66 | return err 67 | } 68 | } 69 | if err := iprot.ReadStructEnd(); err != nil { 70 | return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 71 | } 72 | return nil 73 | } 74 | 75 | func (p *SharedStruct) readField1(iprot thrift.TProtocol) error { 76 | if v, err := iprot.ReadI32(); err != nil { 77 | return thrift.PrependError("error reading field 1: ", err) 78 | } else { 79 | p.Key = v 80 | } 81 | return nil 82 | } 83 | 84 | func (p *SharedStruct) readField2(iprot thrift.TProtocol) error { 85 | if v, err := iprot.ReadString(); err != nil { 86 | return thrift.PrependError("error reading field 2: ", err) 87 | } else { 88 | p.Value = v 89 | } 90 | return nil 91 | } 92 | 93 | func (p *SharedStruct) Write(oprot thrift.TProtocol) error { 94 | if err := oprot.WriteStructBegin("SharedStruct"); err != nil { 95 | return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) 96 | } 97 | if err := p.writeField1(oprot); err != nil { 98 | return err 99 | } 100 | if err := p.writeField2(oprot); err != nil { 101 | return err 102 | } 103 | if err := oprot.WriteFieldStop(); err != nil { 104 | return thrift.PrependError("write field stop error: ", err) 105 | } 106 | if err := oprot.WriteStructEnd(); err != nil { 107 | return thrift.PrependError("write struct stop error: ", err) 108 | } 109 | return nil 110 | } 111 | 112 | func (p *SharedStruct) writeField1(oprot thrift.TProtocol) (err error) { 113 | if err := oprot.WriteFieldBegin("key", thrift.I32, 1); err != nil { 114 | return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:key: ", p), err) 115 | } 116 | if err := oprot.WriteI32(int32(p.Key)); err != nil { 117 | return thrift.PrependError(fmt.Sprintf("%T.key (1) field write error: ", p), err) 118 | } 119 | if err := oprot.WriteFieldEnd(); err != nil { 120 | return thrift.PrependError(fmt.Sprintf("%T write field end error 1:key: ", p), err) 121 | } 122 | return err 123 | } 124 | 125 | func (p *SharedStruct) writeField2(oprot thrift.TProtocol) (err error) { 126 | if err := oprot.WriteFieldBegin("value", thrift.STRING, 2); err != nil { 127 | return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:value: ", p), err) 128 | } 129 | if err := oprot.WriteString(string(p.Value)); err != nil { 130 | return thrift.PrependError(fmt.Sprintf("%T.value (2) field write error: ", p), err) 131 | } 132 | if err := oprot.WriteFieldEnd(); err != nil { 133 | return thrift.PrependError(fmt.Sprintf("%T write field end error 2:value: ", p), err) 134 | } 135 | return err 136 | } 137 | 138 | func (p *SharedStruct) String() string { 139 | if p == nil { 140 | return "" 141 | } 142 | return fmt.Sprintf("SharedStruct(%+v)", *p) 143 | } 144 | -------------------------------------------------------------------------------- /vendor/tutorial/calculator-remote/calculator-remote.go: -------------------------------------------------------------------------------- 1 | // Autogenerated by Thrift Compiler (1.0.0-dev) 2 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 3 | 4 | package main 5 | 6 | import ( 7 | "flag" 8 | "fmt" 9 | "git.apache.org/thrift.git/lib/go/thrift" 10 | "math" 11 | "net" 12 | "net/url" 13 | "os" 14 | "strconv" 15 | "strings" 16 | "tutorial" 17 | ) 18 | 19 | func Usage() { 20 | fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:") 21 | flag.PrintDefaults() 22 | fmt.Fprintln(os.Stderr, "\nFunctions:") 23 | fmt.Fprintln(os.Stderr, " void ping()") 24 | fmt.Fprintln(os.Stderr, " i32 add(i32 num1, i32 num2)") 25 | fmt.Fprintln(os.Stderr, " i32 calculate(i32 logid, Work w)") 26 | fmt.Fprintln(os.Stderr, " void zip()") 27 | fmt.Fprintln(os.Stderr, " SharedStruct getStruct(i32 key)") 28 | fmt.Fprintln(os.Stderr) 29 | os.Exit(0) 30 | } 31 | 32 | func main() { 33 | flag.Usage = Usage 34 | var host string 35 | var port int 36 | var protocol string 37 | var urlString string 38 | var framed bool 39 | var useHttp bool 40 | var parsedUrl url.URL 41 | var trans thrift.TTransport 42 | _ = strconv.Atoi 43 | _ = math.Abs 44 | flag.Usage = Usage 45 | flag.StringVar(&host, "h", "localhost", "Specify host and port") 46 | flag.IntVar(&port, "p", 9090, "Specify port") 47 | flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)") 48 | flag.StringVar(&urlString, "u", "", "Specify the url") 49 | flag.BoolVar(&framed, "framed", false, "Use framed transport") 50 | flag.BoolVar(&useHttp, "http", false, "Use http") 51 | flag.Parse() 52 | 53 | if len(urlString) > 0 { 54 | parsedUrl, err := url.Parse(urlString) 55 | if err != nil { 56 | fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) 57 | flag.Usage() 58 | } 59 | host = parsedUrl.Host 60 | useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http" 61 | } else if useHttp { 62 | _, err := url.Parse(fmt.Sprint("http://", host, ":", port)) 63 | if err != nil { 64 | fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) 65 | flag.Usage() 66 | } 67 | } 68 | 69 | cmd := flag.Arg(0) 70 | var err error 71 | if useHttp { 72 | trans, err = thrift.NewTHttpClient(parsedUrl.String()) 73 | } else { 74 | portStr := fmt.Sprint(port) 75 | if strings.Contains(host, ":") { 76 | host, portStr, err = net.SplitHostPort(host) 77 | if err != nil { 78 | fmt.Fprintln(os.Stderr, "error with host:", err) 79 | os.Exit(1) 80 | } 81 | } 82 | trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr)) 83 | if err != nil { 84 | fmt.Fprintln(os.Stderr, "error resolving address:", err) 85 | os.Exit(1) 86 | } 87 | if framed { 88 | trans = thrift.NewTFramedTransport(trans) 89 | } 90 | } 91 | if err != nil { 92 | fmt.Fprintln(os.Stderr, "Error creating transport", err) 93 | os.Exit(1) 94 | } 95 | defer trans.Close() 96 | var protocolFactory thrift.TProtocolFactory 97 | switch protocol { 98 | case "compact": 99 | protocolFactory = thrift.NewTCompactProtocolFactory() 100 | break 101 | case "simplejson": 102 | protocolFactory = thrift.NewTSimpleJSONProtocolFactory() 103 | break 104 | case "json": 105 | protocolFactory = thrift.NewTJSONProtocolFactory() 106 | break 107 | case "binary", "": 108 | protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() 109 | break 110 | default: 111 | fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol) 112 | Usage() 113 | os.Exit(1) 114 | } 115 | client := tutorial.NewCalculatorClientFactory(trans, protocolFactory) 116 | if err := trans.Open(); err != nil { 117 | fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err) 118 | os.Exit(1) 119 | } 120 | 121 | switch cmd { 122 | case "ping": 123 | if flag.NArg()-1 != 0 { 124 | fmt.Fprintln(os.Stderr, "Ping requires 0 args") 125 | flag.Usage() 126 | } 127 | fmt.Print(client.Ping()) 128 | fmt.Print("\n") 129 | break 130 | case "add": 131 | if flag.NArg()-1 != 2 { 132 | fmt.Fprintln(os.Stderr, "Add requires 2 args") 133 | flag.Usage() 134 | } 135 | tmp0, err7 := (strconv.Atoi(flag.Arg(1))) 136 | if err7 != nil { 137 | Usage() 138 | return 139 | } 140 | argvalue0 := int32(tmp0) 141 | value0 := argvalue0 142 | tmp1, err8 := (strconv.Atoi(flag.Arg(2))) 143 | if err8 != nil { 144 | Usage() 145 | return 146 | } 147 | argvalue1 := int32(tmp1) 148 | value1 := argvalue1 149 | fmt.Print(client.Add(value0, value1)) 150 | fmt.Print("\n") 151 | break 152 | case "calculate": 153 | if flag.NArg()-1 != 2 { 154 | fmt.Fprintln(os.Stderr, "Calculate requires 2 args") 155 | flag.Usage() 156 | } 157 | tmp0, err9 := (strconv.Atoi(flag.Arg(1))) 158 | if err9 != nil { 159 | Usage() 160 | return 161 | } 162 | argvalue0 := int32(tmp0) 163 | value0 := argvalue0 164 | arg10 := flag.Arg(2) 165 | mbTrans11 := thrift.NewTMemoryBufferLen(len(arg10)) 166 | defer mbTrans11.Close() 167 | _, err12 := mbTrans11.WriteString(arg10) 168 | if err12 != nil { 169 | Usage() 170 | return 171 | } 172 | factory13 := thrift.NewTSimpleJSONProtocolFactory() 173 | jsProt14 := factory13.GetProtocol(mbTrans11) 174 | argvalue1 := tutorial.NewWork() 175 | err15 := argvalue1.Read(jsProt14) 176 | if err15 != nil { 177 | Usage() 178 | return 179 | } 180 | value1 := argvalue1 181 | fmt.Print(client.Calculate(value0, value1)) 182 | fmt.Print("\n") 183 | break 184 | case "zip": 185 | if flag.NArg()-1 != 0 { 186 | fmt.Fprintln(os.Stderr, "Zip requires 0 args") 187 | flag.Usage() 188 | } 189 | fmt.Print(client.Zip()) 190 | fmt.Print("\n") 191 | break 192 | case "getStruct": 193 | if flag.NArg()-1 != 1 { 194 | fmt.Fprintln(os.Stderr, "GetStruct requires 1 args") 195 | flag.Usage() 196 | } 197 | tmp0, err16 := (strconv.Atoi(flag.Arg(1))) 198 | if err16 != nil { 199 | Usage() 200 | return 201 | } 202 | argvalue0 := int32(tmp0) 203 | value0 := argvalue0 204 | fmt.Print(client.GetStruct(value0)) 205 | fmt.Print("\n") 206 | break 207 | case "": 208 | Usage() 209 | break 210 | default: 211 | fmt.Fprintln(os.Stderr, "Invalid function ", cmd) 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /vendor/tutorial/constants.go: -------------------------------------------------------------------------------- 1 | // Autogenerated by Thrift Compiler (1.0.0-dev) 2 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 3 | 4 | package tutorial 5 | 6 | import ( 7 | "bytes" 8 | "fmt" 9 | "git.apache.org/thrift.git/lib/go/thrift" 10 | "shared" 11 | ) 12 | 13 | // (needed to ensure safety because of naive import list construction.) 14 | var _ = thrift.ZERO 15 | var _ = fmt.Printf 16 | var _ = bytes.Equal 17 | 18 | var _ = shared.GoUnusedProtection__ 19 | 20 | const INT32CONSTANT = 9853 21 | 22 | var MAPCONSTANT map[string]string 23 | 24 | func init() { 25 | MAPCONSTANT = map[string]string{ 26 | "hello": "world", 27 | "goodnight": "moon", 28 | } 29 | 30 | } 31 | --------------------------------------------------------------------------------