#ifdef __cplusplus extern "C" { #endif #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #ifdef __cplusplus } #endif #ifdef do_open #undef do_open #endif #ifdef do_close #undef do_close #endif #ifdef New #undef New #endif #include #include #include #include #include "person.pb.h" using namespace std; class person_OutputStream : public google::protobuf::io::ZeroCopyOutputStream { public: explicit person_OutputStream(SV * sv) : sv_(sv), len_(0) {} ~person_OutputStream() {} bool Next(void** data, int* size) { STRLEN nlen = len_ << 1; if ( nlen < 16 ) nlen = 16; SvGROW(sv_, nlen); *data = SvEND(sv_) + len_; *size = SvLEN(sv_) - len_; len_ = nlen; return true; } void BackUp(int count) { SvCUR_set(sv_, SvLEN(sv_) - count); } void Sync() { if ( SvCUR(sv_) == 0 ) { SvCUR_set(sv_, len_); } } int64_t ByteCount() const { return (int64_t)SvCUR(sv_); } private: SV * sv_; STRLEN len_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(person_OutputStream); }; typedef ::Person __Person; static ::Person * __Person_from_hashref ( SV * sv0 ) { ::Person * msg0 = new ::Person; if ( SvROK(sv0) && SvTYPE(SvRV(sv0)) == SVt_PVHV ) { HV * hv0 = (HV *)SvRV(sv0); SV ** sv1; if ( (sv1 = hv_fetch(hv0, "id", sizeof("id") - 1, 0)) != NULL ) { msg0->set_id(SvIV(*sv1)); } if ( (sv1 = hv_fetch(hv0, "name", sizeof("name") - 1, 0)) != NULL ) { STRLEN len; char * str; string sval; str = SvPV(*sv1, len); sval.assign(str, len); msg0->set_name(sval); } if ( (sv1 = hv_fetch(hv0, "email", sizeof("email") - 1, 0)) != NULL ) { STRLEN len; char * str; string sval; str = SvPV(*sv1, len); sval.assign(str, len); msg0->set_email(sval); } } return msg0; } MODULE = Person PACKAGE = Person PROTOTYPES: ENABLE SV * ::Person::new (...) PREINIT: ::Person * rv = NULL; CODE: if ( strcmp(CLASS,"Person") ) { croak("invalid class %s",CLASS); } if ( items == 2 && ST(1) != Nullsv ) { if ( SvROK(ST(1)) && SvTYPE(SvRV(ST(1))) == SVt_PVHV ) { rv = __Person_from_hashref(ST(1)); } else { STRLEN len; char * str; rv = new ::Person; str = SvPV(ST(1), len); if ( str != NULL ) { rv->ParseFromArray(str, len); } } } else { rv = new ::Person; } RETVAL = newSV(0); sv_setref_pv(RETVAL, "Person", (void *)rv); OUTPUT: RETVAL void DESTROY(svTHIS) SV * svTHIS; CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } if ( THIS != NULL ) { delete THIS; } void copy_from(svTHIS, sv) SV * svTHIS SV * sv CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } if ( THIS != NULL && sv != NULL ) { if ( sv_derived_from(sv, "Person") ) { IV tmp = SvIV((SV *)SvRV(sv)); ::Person * other = INT2PTR(__Person *, tmp); THIS->CopyFrom(*other); } else if ( SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVHV ) { ::Person * other = __Person_from_hashref(sv); THIS->CopyFrom(*other); delete other; } } void merge_from(svTHIS, sv) SV * svTHIS SV * sv CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } if ( THIS != NULL && sv != NULL ) { if ( sv_derived_from(sv, "Person") ) { IV tmp = SvIV((SV *)SvRV(sv)); ::Person * other = INT2PTR(__Person *, tmp); THIS->MergeFrom(*other); } else if ( SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVHV ) { ::Person * other = __Person_from_hashref(sv); THIS->MergeFrom(*other); delete other; } } void clear(svTHIS) SV * svTHIS CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } if ( THIS != NULL ) { THIS->Clear(); } int is_initialized(svTHIS) SV * svTHIS CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } if ( THIS != NULL ) { RETVAL = THIS->IsInitialized(); } else { RETVAL = 0; } OUTPUT: RETVAL SV * error_string(svTHIS) SV * svTHIS PREINIT: string estr; CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } if ( THIS != NULL ) { estr = THIS->InitializationErrorString(); } RETVAL = newSVpv(estr.c_str(), estr.length()); OUTPUT: RETVAL void discard_unkown_fields(svTHIS) SV * svTHIS CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } if ( THIS != NULL ) { THIS->DiscardUnknownFields(); } SV * debug_string(svTHIS) SV * svTHIS PREINIT: string dstr; CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } if ( THIS != NULL ) { dstr = THIS->DebugString(); } RETVAL = newSVpv(dstr.c_str(), dstr.length()); OUTPUT: RETVAL SV * short_debug_string(svTHIS) SV * svTHIS PREINIT: string dstr; CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } if ( THIS != NULL ) { dstr = THIS->ShortDebugString(); } RETVAL = newSVpv(dstr.c_str(), dstr.length()); OUTPUT: RETVAL int unpack(svTHIS, arg) SV * svTHIS SV * arg PREINIT: STRLEN len; char * str; CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } if ( THIS != NULL ) { str = SvPV(arg, len); if ( str != NULL ) { RETVAL = THIS->ParseFromArray(str, len); } else { RETVAL = 0; } } else { RETVAL = 0; } OUTPUT: RETVAL SV * pack(svTHIS) SV * svTHIS CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } if ( THIS != NULL ) { RETVAL = newSVpvn("", 0); person_OutputStream os(RETVAL); if ( THIS->IsInitialized() ) { if ( THIS->SerializePartialToZeroCopyStream(&os)!= true ) { SvREFCNT_dec(RETVAL); RETVAL = Nullsv; } else { os.Sync(); } } else { croak("Can't serialize message of type 'Person' because it is missing required fields: %s", THIS->InitializationErrorString().c_str()); } } else { RETVAL = Nullsv; } OUTPUT: RETVAL int length(svTHIS) SV * svTHIS CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } if ( THIS != NULL ) { RETVAL = THIS->ByteSize(); } else { RETVAL = 0; } OUTPUT: RETVAL void fields(svTHIS) SV * svTHIS PPCODE: (void)svTHIS; EXTEND(SP, 3); PUSHs(sv_2mortal(newSVpv("id",0))); PUSHs(sv_2mortal(newSVpv("name",0))); PUSHs(sv_2mortal(newSVpv("email",0))); SV * to_hashref(svTHIS) SV * svTHIS CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } if ( THIS != NULL ) { HV * hv0 = newHV(); ::Person * msg0 = THIS; if ( msg0->has_id() ) { SV * sv0 = newSViv(msg0->id()); hv_store(hv0, "id", sizeof("id") - 1, sv0, 0); } if ( msg0->has_name() ) { SV * sv0 = newSVpv(msg0->name().c_str(), msg0->name().length()); hv_store(hv0, "name", sizeof("name") - 1, sv0, 0); } if ( msg0->has_email() ) { SV * sv0 = newSVpv(msg0->email().c_str(), msg0->email().length()); hv_store(hv0, "email", sizeof("email") - 1, sv0, 0); } RETVAL = newRV_noinc((SV *)hv0); } else { RETVAL = Nullsv; } OUTPUT: RETVAL I32 has_id(svTHIS) SV * svTHIS; CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } RETVAL = THIS->has_id(); OUTPUT: RETVAL void clear_id(svTHIS) SV * svTHIS; CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } THIS->clear_id(); void id(svTHIS) SV * svTHIS; PREINIT: SV * sv; PPCODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } if ( THIS != NULL ) { EXTEND(SP,1); sv = sv_2mortal(newSViv(THIS->id())); PUSHs(sv); } void set_id(svTHIS, svVAL) SV * svTHIS IV svVAL CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } THIS->set_id(svVAL); I32 has_name(svTHIS) SV * svTHIS; CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } RETVAL = THIS->has_name(); OUTPUT: RETVAL void clear_name(svTHIS) SV * svTHIS; CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } THIS->clear_name(); void name(svTHIS) SV * svTHIS; PREINIT: SV * sv; PPCODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } if ( THIS != NULL ) { EXTEND(SP,1); sv = sv_2mortal(newSVpv(THIS->name().c_str(), THIS->name().length())); PUSHs(sv); } void set_name(svTHIS, svVAL) SV * svTHIS SV *svVAL PREINIT: char * str; STRLEN len; string sval; CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } str = SvPV(svVAL, len); sval.assign(str, len); THIS->set_name(sval); I32 has_email(svTHIS) SV * svTHIS; CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } RETVAL = THIS->has_email(); OUTPUT: RETVAL void clear_email(svTHIS) SV * svTHIS; CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } THIS->clear_email(); void email(svTHIS) SV * svTHIS; PREINIT: SV * sv; PPCODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } if ( THIS != NULL ) { EXTEND(SP,1); sv = sv_2mortal(newSVpv(THIS->email().c_str(), THIS->email().length())); PUSHs(sv); } void set_email(svTHIS, svVAL) SV * svTHIS SV *svVAL PREINIT: char * str; STRLEN len; string sval; CODE: ::Person * THIS; if ( sv_derived_from(svTHIS, "Person") ) { IV tmp = SvIV((SV *)SvRV(svTHIS)); THIS = INT2PTR(__Person *, tmp); } else { croak("THIS is not of type Person"); } str = SvPV(svVAL, len); sval.assign(str, len); THIS->set_email(sval);