Skip to content

Instantly share code, notes, and snippets.

@joelreymont
Created March 25, 2011 16:02
Show Gist options
  • Save joelreymont/887088 to your computer and use it in GitHub Desktop.
Save joelreymont/887088 to your computer and use it in GitHub Desktop.
struct Foo
{
1: string foo
}
struct Bar
{
1: i32 bar
}
union FooBar
{
1: Foo foo
2: Bar bar
}
(*
Autogenerated by Thrift
DO NOT EDIT UNLESS YOU ARE SURE YOU KNOW WHAT YOU ARE DOING
*)
open Thrift
open Foo_types
type FooBar =
| Foo of foo_types.foo
| Bar of foo_types.bar
(*
Autogenerated by Thrift
DO NOT EDIT UNLESS YOU ARE SURE YOU KNOW WHAT YOU ARE DOING
*)
open Thrift
class foo =
object (self)
val mutable _foo : string option = None
method get_foo = _foo
method grab_foo = match _foo with None->raise (Field_empty "foo.foo") | Some _x0 -> _x0
method set_foo _x0 = _foo <- Some _x0
method unset_foo = _foo <- None
method reset_foo = _foo <- None
method copy =
let _new = Oo.copy self in
_new
method write (oprot : Protocol.t) =
oprot#writeStructBegin "Foo";
(match _foo with None -> () | Some _v ->
oprot#writeFieldBegin("foo",Protocol.T_STRING,1);
oprot#writeString(_v);
oprot#writeFieldEnd
);
oprot#writeFieldStop;
oprot#writeStructEnd
end
let rec read_foo (iprot : Protocol.t) =
let _str3 = new foo in
ignore(iprot#readStructBegin);
(try while true do
let (_,_t4,_id5) = iprot#readFieldBegin in
if _t4 = Protocol.T_STOP then
raise Break
else ();
(match _id5 with
| 1 -> (if _t4 = Protocol.T_STRING then
_str3#set_foo iprot#readString
else
iprot#skip _t4)
| _ -> iprot#skip _t4);
iprot#readFieldEnd;
done; ()
with Break -> ());
iprot#readStructEnd;
_str3
class bar =
object (self)
val mutable _bar : Int32.t option = None
method get_bar = _bar
method grab_bar = match _bar with None->raise (Field_empty "bar.bar") | Some _x7 -> _x7
method set_bar _x7 = _bar <- Some _x7
method unset_bar = _bar <- None
method reset_bar = _bar <- None
method copy =
let _new = Oo.copy self in
_new
method write (oprot : Protocol.t) =
oprot#writeStructBegin "Bar";
(match _bar with None -> () | Some _v ->
oprot#writeFieldBegin("bar",Protocol.T_I32,1);
oprot#writeI32(_v);
oprot#writeFieldEnd
);
oprot#writeFieldStop;
oprot#writeStructEnd
end
let rec read_bar (iprot : Protocol.t) =
let _str10 = new bar in
ignore(iprot#readStructBegin);
(try while true do
let (_,_t11,_id12) = iprot#readFieldBegin in
if _t11 = Protocol.T_STOP then
raise Break
else ();
(match _id12 with
| 1 -> (if _t11 = Protocol.T_I32 then
_str10#set_bar iprot#readI32
else
iprot#skip _t11)
| _ -> iprot#skip _t11);
iprot#readFieldEnd;
done; ()
with Break -> ());
iprot#readStructEnd;
_str10
class fooBar =
object (self)
val mutable _foo : foo option = None
method get_foo = _foo
method grab_foo = match _foo with None->raise (Field_empty "fooBar.foo") | Some _x14 -> _x14
method set_foo _x14 = _foo <- Some _x14
method unset_foo = _foo <- None
method reset_foo = _foo <- None
val mutable _bar : bar option = None
method get_bar = _bar
method grab_bar = match _bar with None->raise (Field_empty "fooBar.bar") | Some _x15 -> _x15
method set_bar _x15 = _bar <- Some _x15
method unset_bar = _bar <- None
method reset_bar = _bar <- None
method copy =
let _new = Oo.copy self in
if _foo <> None then
_new#set_foo self#grab_foo#copy;
if _bar <> None then
_new#set_bar self#grab_bar#copy;
_new
method write (oprot : Protocol.t) =
oprot#writeStructBegin "FooBar";
(match _foo with None -> () | Some _v ->
oprot#writeFieldBegin("foo",Protocol.T_STRUCT,1);
_v#write(oprot);
oprot#writeFieldEnd
);
(match _bar with None -> () | Some _v ->
oprot#writeFieldBegin("bar",Protocol.T_STRUCT,2);
_v#write(oprot);
oprot#writeFieldEnd
);
oprot#writeFieldStop;
oprot#writeStructEnd
end
let rec read_fooBar (iprot : Protocol.t) =
let _str18 = new fooBar in
ignore(iprot#readStructBegin);
(try while true do
let (_,_t19,_id20) = iprot#readFieldBegin in
if _t19 = Protocol.T_STOP then
raise Break
else ();
(match _id20 with
| 1 -> (if _t19 = Protocol.T_STRUCT then
_str18#set_foo (read_foo iprot)
else
iprot#skip _t19)
| 2 -> (if _t19 = Protocol.T_STRUCT then
_str18#set_bar (read_bar iprot)
else
iprot#skip _t19)
| _ -> iprot#skip _t19);
iprot#readFieldEnd;
done; ()
with Break -> ());
iprot#readStructEnd;
_str18
(*
Autogenerated by Thrift
DO NOT EDIT UNLESS YOU ARE SURE YOU KNOW WHAT YOU ARE DOING
*)
open Thrift
class foo :
object ('a)
method get_foo : string option
method grab_foo : string
method set_foo : string -> unit
method unset_foo : unit
method reset_foo : unit
method copy : 'a
method write : Protocol.t -> unit
end
val read_foo : Protocol.t -> foo
class bar :
object ('a)
method get_bar : Int32.t option
method grab_bar : Int32.t
method set_bar : Int32.t -> unit
method unset_bar : unit
method reset_bar : unit
method copy : 'a
method write : Protocol.t -> unit
end
val read_bar : Protocol.t -> bar
class fooBar :
object ('a)
method get_foo : foo option
method grab_foo : foo
method set_foo : foo -> unit
method unset_foo : unit
method reset_foo : unit
method get_bar : bar option
method grab_bar : bar
method set_bar : bar -> unit
method unset_bar : unit
method reset_bar : unit
method copy : 'a
method write : Protocol.t -> unit
end
val read_fooBar : Protocol.t -> fooBar
thrift -gen ocaml foo.thrift
# no error here
thrift -version
Thrift version 0.7.0-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment