Compression is not a built-in feature of protocol buffers, but it is easy and often useful to apply compression on top of the protobuf encoding.
In Java, write your data to a GZIPOoutputStream, and then read from a GZIPInputStream. These classes are part of the standard Java library, not the protobuf library.
In C++, use the GzipOutputStream and GzipInputStream classes that are provided in the protobuf library (under google/protobuf/io). These simply call zlib to apply compression on top of protocol buffers.