List of usage examples for com.google.common.io.protocol ProtoBuf outputTo
public void outputTo(OutputStream os) throws IOException
From source file:com.codetastrophe.cellfinder.LocationFetcher.java
public void getLocationFromCell(int lac, int cid, int mcc, int mnc, final LocationCallback callback) { Log.d(TAG, String.format("looking for location for %d %d %d %d", mcc, mnc, lac, cid)); ProtoBuf requestElement = new ProtoBuf(LocserverMessageTypes.GLOC_REQUEST_ELEMENT); ProtoBuf cellularProfile = getCellularProfile(lac, cid, mcc, mnc); requestElement.setProtoBuf(GLocRequestElement.CELLULAR_PROFILE, cellularProfile); // Request to send over wire ProtoBuf request = new ProtoBuf(LocserverMessageTypes.GLOC_REQUEST); request.addProtoBuf(GLocRequest.REQUEST_ELEMENTS, requestElement); // Create a Platform Profile ProtoBuf platformProfile = createPlatformProfile(); request.setProtoBuf(GLocRequest.PLATFORM_PROFILE, platformProfile); ByteArrayOutputStream payload = new ByteArrayOutputStream(); try {// w w w.j av a 2s. c o m request.outputTo(payload); } catch (IOException e) { Log.e(TAG, "getNetworkLocation(): unable to write request to payload", e); return; } // Creates request and a listener with a call back function ProtoBuf reply = new ProtoBuf(LocserverMessageTypes.GLOC_REPLY); Request plainRequest = new PlainRequest(REQUEST_QUERY_LOC, (short) 0, payload.toByteArray()); ProtoRequestListener listener = new ProtoRequestListener(reply, new ServiceCallback() { public void onRequestComplete(Object result) { ProtoBuf response = (ProtoBuf) result; parseNetworkLocationReply(response, callback); } }); plainRequest.setListener(listener); // Send request MobileServiceMux serviceMux = MobileServiceMux.getSingleton(); serviceMux.submitRequest(plainRequest, true); }