-
Notifications
You must be signed in to change notification settings - Fork 3
/
README
113 lines (81 loc) · 3.6 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
NAME
Thrift::Parser - A Thrift message (de)serialization OO representation
SYNOPSIS
use Thrift;
use Thrift::Parser;
use Thrift::IDL;
my $parser = Thrift::Parser->new(
idl => Thrift::IDL->parse_thrift_file('tutorial.thrift'),
service => 'Calculator',
);
## Parse a payload
# Obtain a Thrift::Protocol subclass somehow with a loaded buffer
my $buffer = ...;
my $protocol = Thrift::BinaryProtocol->new($buffer);
my $message = $parser->parse_message($protocol);
print "Received method call " . $message->method->name . "\n";
## Use the auto-generated classes to create request/responses
my $request = tutorial::Calculator::add->compose_message_call(
num1 => 15,
num2 => 33,
);
my $response = $request->compose_reply(48);
DESCRIPTION
This module provides strict typing and full object orientation of all
the Thrift types. It allows you, with a Thrift::IDL object, to create a
parser which can parse any Thrift::Protocol object into a message
object, and creates dynamic classes according to the IDL specification,
allowing you to create method calls, objects, and responses.
METHODS
new
my $parser = Thrift::Parser->new(
idl => Thrift::IDL->parse_thrift_file('..'),
service => 'myServiceName',
)
Creates the Parser object and dynamic classes from the IDL file.
parse_message
my $message = $parser->parse_message($transport);
Given a Thrift::Transport object, the parser will create a
Thrift::Parser::Message object.
full_docs_to_dir
$parser->full_docs_to_dir($dir, $format);
Using the dynamically generated classes, this will create 'pod' or 'pm'
files in the target directory in the following format:
$dir/tutorial::Calculator::testVars.pod
(or with format 'pm')
$dir/tutorial/Calculator/testVars.pm
The directory will be created if it doesn't exist.
INTERNAL METHODS
parse_structure
my $fieldset = $parser->parse_structure($transport, $thrift_idl_method->arguments);
Returns a Thrift::Parser::FieldSet. Attempts to read a structure off the
transport, using an array of Thrift::IDL::Field objects to define the
specification of the structure.
parse_type
my $typed_value = $parser->parse_type($transport, { idl => $thrift_idl_type_object || type => 4 });
Reads a single value off the transport and returns it as an object in a
Thrift::Parser::Type subclass.
idl_type_class
my $parser_type_class = $parser->idl_type_class($thrift_idl_type_object);
Maps the given Thrift::IDL::Type object to one in my parser namespace.
If it's a custom type, it'll map into a dynamic class.
resolve_idl_type
my $thrift_idl_type_object = $parser->resolve_idl_type($thrift_idl_custom_type_object);
Returns the base Thrift::IDL::Type object from the given
Thrift::IDL::Type::Custom object
SEE ALSO
Thrift, Thrift::IDL
DEVELOPMENT
This module is being developed via a git repository publicly available
at <http://github.com/ewaters/thrift-parser>. I encourage anyone who is
interested to fork my code and contribute bug fixes or new features, or
just have fun and be creative.
COPYRIGHT
Copyright (c) 2009 Eric Waters and XMission LLC
(http://www.xmission.com/). All rights reserved. This program is free
software; you can redistribute it and/or modify it under the same terms
as Perl itself.
The full text of the license can be found in the LICENSE file included
with this module.
AUTHOR
Eric Waters <[email protected]>