Cita:  bool SerializeToString(string* output) const;: serializes the message and stores the bytes in the given string.  Note that the bytes are binary, not text; we only use the string class as a convenient container.
    ¿Estás seguro de que buf.length()  te está dando un valor correcto? 
No digo que esté ahí el fallo, pero es por empezar a tirar del hilo. 
Un saludo