Created
November 3, 2012 17:12
-
-
Save diega/4007969 to your computer and use it in GitHub Desktop.
How to generate binary files containing Protobuf serialization from human readable input (Applied to RealtimeBidding)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DEPRECATED_protocol_version: 1 | |
id: "\006\013\230\033\240b\242\310\204\252v\306\354S\0340" | |
ip: "0\217O" | |
user_agent: "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0;)" | |
country: "CA" | |
region: "CA-ON" | |
city: "Toronto" | |
url: "http://www.nytimes.com/pages/technology/index.html" | |
detected_language: "en" | |
detected_vertical { | |
id: 608 | |
weight: 0.641945431083 | |
} | |
detected_vertical { | |
id: 24 | |
weight: 0.615661596479 | |
} | |
detected_vertical { | |
id: 474 | |
weight: 0.421220140846 | |
} | |
detected_vertical { | |
id: 379 | |
weight: 0.494118810167 | |
} | |
detected_vertical { | |
id: 23 | |
weight: 0.196397066403 | |
} | |
adslot { | |
id: 42 | |
width: 180 | |
height: 60 | |
excluded_attribute: 1 | |
excluded_attribute: 3 | |
allowed_vendor_type: 145 | |
allowed_vendor_type: 226 | |
allowed_vendor_type: 316 | |
allowed_vendor_type: 234 | |
allowed_vendor_type: 231 | |
matching_ad_data { | |
adgroup_id: 49162214 | |
} | |
matching_ad_data { | |
adgroup_id: 38217668 | |
} | |
publisher_settings_list_id: "$&O\270hO\005j\333\207!~DJ\277\371\217$\r_" | |
} | |
adslot { | |
id: 91 | |
width: 728 | |
height: 90 | |
excluded_attribute: 1 | |
excluded_attribute: 9 | |
excluded_attribute: 7 | |
allowed_vendor_type: 227 | |
allowed_vendor_type: 198 | |
allowed_vendor_type: 238 | |
allowed_vendor_type: 143 | |
allowed_vendor_type: 312 | |
allowed_vendor_type: 316 | |
matching_ad_data { | |
adgroup_id: 89764029 | |
} | |
publisher_settings_list_id: "\273w&Q\346\306\001=2\271\001\263\364d\375\216`\267\365X" | |
} | |
is_test: true | |
cookie_version: 1 | |
google_user_id: "bR-Rl03r_iQeeeioQSqQS_gA75U" | |
seller_network: "New York Times" | |
publisher_settings_list_id: "~\024^F8\t\352^|(\362\335\361\003I\237\224,\236\243" | |
cookie_age_seconds: 2542923 | |
postal_code_prefix: "M4C" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.adex.rtb.RealtimeBidding; | |
import com.google.protobuf.TextFormat; | |
import java.io.*; | |
public class ProtocolBufferFileGenerator { | |
public void generateBinaryFile() throws IOException { | |
RealtimeBidding.BidRequest.Builder builder = RealtimeBidding.BidRequest.newBuilder(); | |
TextFormat.merge(new InputStreamReader(getClass().getResourceAsStream("/bidRequest.ad")), builder); | |
OutputStream output = new FileOutputStream(new File(System.getProperty("user.home"), "protobuf.bin")); | |
output.write(builder.build().toByteArray()); | |
output.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment