int main() { char pb_1[] = {0x12, 0x07, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67}; char pb_2[] = {0x08, 0x96, 0x01}; decode_protobuf(pb_1, pb_1+sizeof(pb_1), yield_cb); decode_protobuf(pb_2, pb_2+sizeof(pb_2), yield_cb); }
/** * Decodes protobuf message from givent FFI pointer. * * @param [#address] pointer pointer to the protobuf data * @param [Integer] offset buffer offset * @param [Integer] length buffer size (wo/ offset) * @return [Array] array of decoded fields */ VALUE protobuf_coder_decode_from_pointer( VALUE module, VALUE pointer, VALUE offset, VALUE length ) { char *ptr = (char *) NUM2ULL( rb_funcall( pointer, rb_intern_const( "address" ), 0 )); return decode_protobuf( (uint8_t *) ptr + NUM2LONG( offset ), NUM2LONG( length )); }
/** * Decodes protobuf message from given string. * * @param [String] string string with protobuf data * @return [Array] array of decoded fields */ VALUE protobuf_coder_decode( VALUE module, VALUE string ) { Check_Type( string, T_STRING ); return decode_protobuf( (uint8_t *) RSTRING_PTR( string ), RSTRING_LEN( string )); }