Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
thrift
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tufengqi
thrift
Commits
bbe21d02
Commit
bbe21d02
authored
Apr 19, 2018
by
tufengqi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finish
parent
94250140
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
684 additions
and
1 deletion
+684
-1
.gitignore
.gitignore
+0
-1
SharedService.php
tutorial/gen-php/shared/SharedService.php
+250
-0
Types.php
tutorial/gen-php/shared/Types.php
+119
-0
Calculator.php
tutorial/gen-php/tutorial/Calculator.php
+0
-0
Types.php
tutorial/gen-php/tutorial/Types.php
+315
-0
No files found.
.gitignore
View file @
bbe21d02
...
...
@@ -32,7 +32,6 @@ junit*.properties
*.iml
*.ipr
*.iws
gen-*
Makefile
Makefile.in
aclocal.m4
...
...
tutorial/gen-php/shared/SharedService.php
0 → 100644
View file @
bbe21d02
<?php
namespace
shared
;
/**
* Autogenerated by Thrift Compiler (0.11.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
use
Thrift\Base\TBase
;
use
Thrift\Type\TType
;
use
Thrift\Type\TMessageType
;
use
Thrift\Exception\TException
;
use
Thrift\Exception\TProtocolException
;
use
Thrift\Protocol\TProtocol
;
use
Thrift\Protocol\TBinaryProtocolAccelerated
;
use
Thrift\Exception\TApplicationException
;
interface
SharedServiceIf
{
/**
* @param int $key
* @return \shared\SharedStruct
*/
public
function
getStruct
(
$key
);
}
class
SharedServiceClient
implements
\shared\SharedServiceIf
{
protected
$input_
=
null
;
protected
$output_
=
null
;
protected
$seqid_
=
0
;
public
function
__construct
(
$input
,
$output
=
null
)
{
$this
->
input_
=
$input
;
$this
->
output_
=
$output
?
$output
:
$input
;
}
public
function
getStruct
(
$key
)
{
$this
->
send_getStruct
(
$key
);
return
$this
->
recv_getStruct
();
}
public
function
send_getStruct
(
$key
)
{
$args
=
new
\shared\SharedService_getStruct_args
();
$args
->
key
=
$key
;
$bin_accel
=
(
$this
->
output_
instanceof
TBinaryProtocolAccelerated
)
&&
function_exists
(
'thrift_protocol_write_binary'
);
if
(
$bin_accel
)
{
thrift_protocol_write_binary
(
$this
->
output_
,
'getStruct'
,
TMessageType
::
CALL
,
$args
,
$this
->
seqid_
,
$this
->
output_
->
isStrictWrite
());
}
else
{
$this
->
output_
->
writeMessageBegin
(
'getStruct'
,
TMessageType
::
CALL
,
$this
->
seqid_
);
$args
->
write
(
$this
->
output_
);
$this
->
output_
->
writeMessageEnd
();
$this
->
output_
->
getTransport
()
->
flush
();
}
}
public
function
recv_getStruct
()
{
$bin_accel
=
(
$this
->
input_
instanceof
TBinaryProtocolAccelerated
)
&&
function_exists
(
'thrift_protocol_read_binary'
);
if
(
$bin_accel
)
$result
=
thrift_protocol_read_binary
(
$this
->
input_
,
'\shared\SharedService_getStruct_result'
,
$this
->
input_
->
isStrictRead
());
else
{
$rseqid
=
0
;
$fname
=
null
;
$mtype
=
0
;
$this
->
input_
->
readMessageBegin
(
$fname
,
$mtype
,
$rseqid
);
if
(
$mtype
==
TMessageType
::
EXCEPTION
)
{
$x
=
new
TApplicationException
();
$x
->
read
(
$this
->
input_
);
$this
->
input_
->
readMessageEnd
();
throw
$x
;
}
$result
=
new
\shared\SharedService_getStruct_result
();
$result
->
read
(
$this
->
input_
);
$this
->
input_
->
readMessageEnd
();
}
if
(
$result
->
success
!==
null
)
{
return
$result
->
success
;
}
throw
new
\Exception
(
"getStruct failed: unknown result"
);
}
}
// HELPER FUNCTIONS AND STRUCTURES
class
SharedService_getStruct_args
{
static
$isValidate
=
false
;
static
$_TSPEC
=
array
(
1
=>
array
(
'var'
=>
'key'
,
'isRequired'
=>
false
,
'type'
=>
TType
::
I32
,
),
);
/**
* @var int
*/
public
$key
=
null
;
public
function
__construct
(
$vals
=
null
)
{
if
(
is_array
(
$vals
))
{
if
(
isset
(
$vals
[
'key'
]))
{
$this
->
key
=
$vals
[
'key'
];
}
}
}
public
function
getName
()
{
return
'SharedService_getStruct_args'
;
}
public
function
read
(
$input
)
{
$xfer
=
0
;
$fname
=
null
;
$ftype
=
0
;
$fid
=
0
;
$xfer
+=
$input
->
readStructBegin
(
$fname
);
while
(
true
)
{
$xfer
+=
$input
->
readFieldBegin
(
$fname
,
$ftype
,
$fid
);
if
(
$ftype
==
TType
::
STOP
)
{
break
;
}
switch
(
$fid
)
{
case
1
:
if
(
$ftype
==
TType
::
I32
)
{
$xfer
+=
$input
->
readI32
(
$this
->
key
);
}
else
{
$xfer
+=
$input
->
skip
(
$ftype
);
}
break
;
default
:
$xfer
+=
$input
->
skip
(
$ftype
);
break
;
}
$xfer
+=
$input
->
readFieldEnd
();
}
$xfer
+=
$input
->
readStructEnd
();
return
$xfer
;
}
public
function
write
(
$output
)
{
$xfer
=
0
;
$xfer
+=
$output
->
writeStructBegin
(
'SharedService_getStruct_args'
);
if
(
$this
->
key
!==
null
)
{
$xfer
+=
$output
->
writeFieldBegin
(
'key'
,
TType
::
I32
,
1
);
$xfer
+=
$output
->
writeI32
(
$this
->
key
);
$xfer
+=
$output
->
writeFieldEnd
();
}
$xfer
+=
$output
->
writeFieldStop
();
$xfer
+=
$output
->
writeStructEnd
();
return
$xfer
;
}
}
class
SharedService_getStruct_result
{
static
$isValidate
=
false
;
static
$_TSPEC
=
array
(
0
=>
array
(
'var'
=>
'success'
,
'isRequired'
=>
false
,
'type'
=>
TType
::
STRUCT
,
'class'
=>
'\shared\SharedStruct'
,
),
);
/**
* @var \shared\SharedStruct
*/
public
$success
=
null
;
public
function
__construct
(
$vals
=
null
)
{
if
(
is_array
(
$vals
))
{
if
(
isset
(
$vals
[
'success'
]))
{
$this
->
success
=
$vals
[
'success'
];
}
}
}
public
function
getName
()
{
return
'SharedService_getStruct_result'
;
}
public
function
read
(
$input
)
{
$xfer
=
0
;
$fname
=
null
;
$ftype
=
0
;
$fid
=
0
;
$xfer
+=
$input
->
readStructBegin
(
$fname
);
while
(
true
)
{
$xfer
+=
$input
->
readFieldBegin
(
$fname
,
$ftype
,
$fid
);
if
(
$ftype
==
TType
::
STOP
)
{
break
;
}
switch
(
$fid
)
{
case
0
:
if
(
$ftype
==
TType
::
STRUCT
)
{
$this
->
success
=
new
\shared\SharedStruct
();
$xfer
+=
$this
->
success
->
read
(
$input
);
}
else
{
$xfer
+=
$input
->
skip
(
$ftype
);
}
break
;
default
:
$xfer
+=
$input
->
skip
(
$ftype
);
break
;
}
$xfer
+=
$input
->
readFieldEnd
();
}
$xfer
+=
$input
->
readStructEnd
();
return
$xfer
;
}
public
function
write
(
$output
)
{
$xfer
=
0
;
$xfer
+=
$output
->
writeStructBegin
(
'SharedService_getStruct_result'
);
if
(
$this
->
success
!==
null
)
{
if
(
!
is_object
(
$this
->
success
))
{
throw
new
TProtocolException
(
'Bad type in structure.'
,
TProtocolException
::
INVALID_DATA
);
}
$xfer
+=
$output
->
writeFieldBegin
(
'success'
,
TType
::
STRUCT
,
0
);
$xfer
+=
$this
->
success
->
write
(
$output
);
$xfer
+=
$output
->
writeFieldEnd
();
}
$xfer
+=
$output
->
writeFieldStop
();
$xfer
+=
$output
->
writeStructEnd
();
return
$xfer
;
}
}
tutorial/gen-php/shared/Types.php
0 → 100644
View file @
bbe21d02
<?php
namespace
shared
;
/**
* Autogenerated by Thrift Compiler (0.11.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
use
Thrift\Base\TBase
;
use
Thrift\Type\TType
;
use
Thrift\Type\TMessageType
;
use
Thrift\Exception\TException
;
use
Thrift\Exception\TProtocolException
;
use
Thrift\Protocol\TProtocol
;
use
Thrift\Protocol\TBinaryProtocolAccelerated
;
use
Thrift\Exception\TApplicationException
;
class
SharedStruct
{
static
$isValidate
=
false
;
static
$_TSPEC
=
array
(
1
=>
array
(
'var'
=>
'key'
,
'isRequired'
=>
false
,
'type'
=>
TType
::
I32
,
),
2
=>
array
(
'var'
=>
'value'
,
'isRequired'
=>
false
,
'type'
=>
TType
::
STRING
,
),
);
/**
* @var int
*/
public
$key
=
null
;
/**
* @var string
*/
public
$value
=
null
;
public
function
__construct
(
$vals
=
null
)
{
if
(
is_array
(
$vals
))
{
if
(
isset
(
$vals
[
'key'
]))
{
$this
->
key
=
$vals
[
'key'
];
}
if
(
isset
(
$vals
[
'value'
]))
{
$this
->
value
=
$vals
[
'value'
];
}
}
}
public
function
getName
()
{
return
'SharedStruct'
;
}
public
function
read
(
$input
)
{
$xfer
=
0
;
$fname
=
null
;
$ftype
=
0
;
$fid
=
0
;
$xfer
+=
$input
->
readStructBegin
(
$fname
);
while
(
true
)
{
$xfer
+=
$input
->
readFieldBegin
(
$fname
,
$ftype
,
$fid
);
if
(
$ftype
==
TType
::
STOP
)
{
break
;
}
switch
(
$fid
)
{
case
1
:
if
(
$ftype
==
TType
::
I32
)
{
$xfer
+=
$input
->
readI32
(
$this
->
key
);
}
else
{
$xfer
+=
$input
->
skip
(
$ftype
);
}
break
;
case
2
:
if
(
$ftype
==
TType
::
STRING
)
{
$xfer
+=
$input
->
readString
(
$this
->
value
);
}
else
{
$xfer
+=
$input
->
skip
(
$ftype
);
}
break
;
default
:
$xfer
+=
$input
->
skip
(
$ftype
);
break
;
}
$xfer
+=
$input
->
readFieldEnd
();
}
$xfer
+=
$input
->
readStructEnd
();
return
$xfer
;
}
public
function
write
(
$output
)
{
$xfer
=
0
;
$xfer
+=
$output
->
writeStructBegin
(
'SharedStruct'
);
if
(
$this
->
key
!==
null
)
{
$xfer
+=
$output
->
writeFieldBegin
(
'key'
,
TType
::
I32
,
1
);
$xfer
+=
$output
->
writeI32
(
$this
->
key
);
$xfer
+=
$output
->
writeFieldEnd
();
}
if
(
$this
->
value
!==
null
)
{
$xfer
+=
$output
->
writeFieldBegin
(
'value'
,
TType
::
STRING
,
2
);
$xfer
+=
$output
->
writeString
(
$this
->
value
);
$xfer
+=
$output
->
writeFieldEnd
();
}
$xfer
+=
$output
->
writeFieldStop
();
$xfer
+=
$output
->
writeStructEnd
();
return
$xfer
;
}
}
tutorial/gen-php/tutorial/Calculator.php
0 → 100644
View file @
bbe21d02
This diff is collapsed.
Click to expand it.
tutorial/gen-php/tutorial/Types.php
0 → 100644
View file @
bbe21d02
<?php
namespace
tutorial
;
/**
* Autogenerated by Thrift Compiler (0.11.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
use
Thrift\Base\TBase
;
use
Thrift\Type\TType
;
use
Thrift\Type\TMessageType
;
use
Thrift\Exception\TException
;
use
Thrift\Exception\TProtocolException
;
use
Thrift\Protocol\TProtocol
;
use
Thrift\Protocol\TBinaryProtocolAccelerated
;
use
Thrift\Exception\TApplicationException
;
/**
* You can define enums, which are just 32 bit integers. Values are optional
* and start at 1 if not supplied, C style again.
*/
final
class
Operation
{
const
ADD
=
1
;
const
SUBTRACT
=
2
;
const
MULTIPLY
=
3
;
const
DIVIDE
=
4
;
static
public
$__names
=
array
(
1
=>
'ADD'
,
2
=>
'SUBTRACT'
,
3
=>
'MULTIPLY'
,
4
=>
'DIVIDE'
,
);
}
/**
* Structs are the basic complex data structures. They are comprised of fields
* which each have an integer identifier, a type, a symbolic name, and an
* optional default value.
*
* Fields can be declared "optional", which ensures they will not be included
* in the serialized output if they aren't set. Note that this requires some
* manual management in some languages.
*/
class
Work
{
static
$isValidate
=
false
;
static
$_TSPEC
=
array
(
1
=>
array
(
'var'
=>
'num1'
,
'isRequired'
=>
false
,
'type'
=>
TType
::
I32
,
),
2
=>
array
(
'var'
=>
'num2'
,
'isRequired'
=>
false
,
'type'
=>
TType
::
I32
,
),
3
=>
array
(
'var'
=>
'op'
,
'isRequired'
=>
false
,
'type'
=>
TType
::
I32
,
),
4
=>
array
(
'var'
=>
'comment'
,
'isRequired'
=>
false
,
'type'
=>
TType
::
STRING
,
),
);
/**
* @var int
*/
public
$num1
=
0
;
/**
* @var int
*/
public
$num2
=
null
;
/**
* @var int
*/
public
$op
=
null
;
/**
* @var string
*/
public
$comment
=
null
;
public
function
__construct
(
$vals
=
null
)
{
if
(
is_array
(
$vals
))
{
if
(
isset
(
$vals
[
'num1'
]))
{
$this
->
num1
=
$vals
[
'num1'
];
}
if
(
isset
(
$vals
[
'num2'
]))
{
$this
->
num2
=
$vals
[
'num2'
];
}
if
(
isset
(
$vals
[
'op'
]))
{
$this
->
op
=
$vals
[
'op'
];
}
if
(
isset
(
$vals
[
'comment'
]))
{
$this
->
comment
=
$vals
[
'comment'
];
}
}
}
public
function
getName
()
{
return
'Work'
;
}
public
function
read
(
$input
)
{
$xfer
=
0
;
$fname
=
null
;
$ftype
=
0
;
$fid
=
0
;
$xfer
+=
$input
->
readStructBegin
(
$fname
);
while
(
true
)
{
$xfer
+=
$input
->
readFieldBegin
(
$fname
,
$ftype
,
$fid
);
if
(
$ftype
==
TType
::
STOP
)
{
break
;
}
switch
(
$fid
)
{
case
1
:
if
(
$ftype
==
TType
::
I32
)
{
$xfer
+=
$input
->
readI32
(
$this
->
num1
);
}
else
{
$xfer
+=
$input
->
skip
(
$ftype
);
}
break
;
case
2
:
if
(
$ftype
==
TType
::
I32
)
{
$xfer
+=
$input
->
readI32
(
$this
->
num2
);
}
else
{
$xfer
+=
$input
->
skip
(
$ftype
);
}
break
;
case
3
:
if
(
$ftype
==
TType
::
I32
)
{
$xfer
+=
$input
->
readI32
(
$this
->
op
);
}
else
{
$xfer
+=
$input
->
skip
(
$ftype
);
}
break
;
case
4
:
if
(
$ftype
==
TType
::
STRING
)
{
$xfer
+=
$input
->
readString
(
$this
->
comment
);
}
else
{
$xfer
+=
$input
->
skip
(
$ftype
);
}
break
;
default
:
$xfer
+=
$input
->
skip
(
$ftype
);
break
;
}
$xfer
+=
$input
->
readFieldEnd
();
}
$xfer
+=
$input
->
readStructEnd
();
return
$xfer
;
}
public
function
write
(
$output
)
{
$xfer
=
0
;
$xfer
+=
$output
->
writeStructBegin
(
'Work'
);
if
(
$this
->
num1
!==
null
)
{
$xfer
+=
$output
->
writeFieldBegin
(
'num1'
,
TType
::
I32
,
1
);
$xfer
+=
$output
->
writeI32
(
$this
->
num1
);
$xfer
+=
$output
->
writeFieldEnd
();
}
if
(
$this
->
num2
!==
null
)
{
$xfer
+=
$output
->
writeFieldBegin
(
'num2'
,
TType
::
I32
,
2
);
$xfer
+=
$output
->
writeI32
(
$this
->
num2
);
$xfer
+=
$output
->
writeFieldEnd
();
}
if
(
$this
->
op
!==
null
)
{
$xfer
+=
$output
->
writeFieldBegin
(
'op'
,
TType
::
I32
,
3
);
$xfer
+=
$output
->
writeI32
(
$this
->
op
);
$xfer
+=
$output
->
writeFieldEnd
();
}
if
(
$this
->
comment
!==
null
)
{
$xfer
+=
$output
->
writeFieldBegin
(
'comment'
,
TType
::
STRING
,
4
);
$xfer
+=
$output
->
writeString
(
$this
->
comment
);
$xfer
+=
$output
->
writeFieldEnd
();
}
$xfer
+=
$output
->
writeFieldStop
();
$xfer
+=
$output
->
writeStructEnd
();
return
$xfer
;
}
}
/**
* Structs can also be exceptions, if they are nasty.
*/
class
InvalidOperation
extends
TException
{
static
$isValidate
=
false
;
static
$_TSPEC
=
array
(
1
=>
array
(
'var'
=>
'whatOp'
,
'isRequired'
=>
false
,
'type'
=>
TType
::
I32
,
),
2
=>
array
(
'var'
=>
'why'
,
'isRequired'
=>
false
,
'type'
=>
TType
::
STRING
,
),
);
/**
* @var int
*/
public
$whatOp
=
null
;
/**
* @var string
*/
public
$why
=
null
;
public
function
__construct
(
$vals
=
null
)
{
if
(
is_array
(
$vals
))
{
if
(
isset
(
$vals
[
'whatOp'
]))
{
$this
->
whatOp
=
$vals
[
'whatOp'
];
}
if
(
isset
(
$vals
[
'why'
]))
{
$this
->
why
=
$vals
[
'why'
];
}
}
}
public
function
getName
()
{
return
'InvalidOperation'
;
}
public
function
read
(
$input
)
{
$xfer
=
0
;
$fname
=
null
;
$ftype
=
0
;
$fid
=
0
;
$xfer
+=
$input
->
readStructBegin
(
$fname
);
while
(
true
)
{
$xfer
+=
$input
->
readFieldBegin
(
$fname
,
$ftype
,
$fid
);
if
(
$ftype
==
TType
::
STOP
)
{
break
;
}
switch
(
$fid
)
{
case
1
:
if
(
$ftype
==
TType
::
I32
)
{
$xfer
+=
$input
->
readI32
(
$this
->
whatOp
);
}
else
{
$xfer
+=
$input
->
skip
(
$ftype
);
}
break
;
case
2
:
if
(
$ftype
==
TType
::
STRING
)
{
$xfer
+=
$input
->
readString
(
$this
->
why
);
}
else
{
$xfer
+=
$input
->
skip
(
$ftype
);
}
break
;
default
:
$xfer
+=
$input
->
skip
(
$ftype
);
break
;
}
$xfer
+=
$input
->
readFieldEnd
();
}
$xfer
+=
$input
->
readStructEnd
();
return
$xfer
;
}
public
function
write
(
$output
)
{
$xfer
=
0
;
$xfer
+=
$output
->
writeStructBegin
(
'InvalidOperation'
);
if
(
$this
->
whatOp
!==
null
)
{
$xfer
+=
$output
->
writeFieldBegin
(
'whatOp'
,
TType
::
I32
,
1
);
$xfer
+=
$output
->
writeI32
(
$this
->
whatOp
);
$xfer
+=
$output
->
writeFieldEnd
();
}
if
(
$this
->
why
!==
null
)
{
$xfer
+=
$output
->
writeFieldBegin
(
'why'
,
TType
::
STRING
,
2
);
$xfer
+=
$output
->
writeString
(
$this
->
why
);
$xfer
+=
$output
->
writeFieldEnd
();
}
$xfer
+=
$output
->
writeFieldStop
();
$xfer
+=
$output
->
writeStructEnd
();
return
$xfer
;
}
}
final
class
Constant
extends
\Thrift\Type\TConstant
{
static
protected
$INT32CONSTANT
;
static
protected
$MAPCONSTANT
;
static
protected
function
init_INT32CONSTANT
()
{
return
/**
* Thrift also lets you define constants for use across languages. Complex
* types and structs are specified using JSON notation.
*/
9853
;
}
static
protected
function
init_MAPCONSTANT
()
{
return
array
(
"hello"
=>
"world"
,
"goodnight"
=>
"moon"
,
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment