List of usage examples for com.google.common.io.protocol ProtoBuf setProtoBuf
public void setProtoBuf(int tag, ProtoBuf pb)
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 {/*from w w w . j a va2 s . co 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); }
From source file:com.codetastrophe.cellfinder.LocationFetcher.java
private ProtoBuf getCellularProfile(int lac, int cid, int mcc, int mnc) { Date now = new Date(); ProtoBuf cellularProfile = new ProtoBuf(GcellularMessageTypes.GCELLULAR_PROFILE); cellularProfile.setLong(GCellularProfile.TIMESTAMP, now.getTime()); cellularProfile.setInt(GCellularProfile.PREFETCH_MODE, GPrefetchMode.PREFETCH_MODE_MORE_NEIGHBORS); ProtoBuf primaryCell = new ProtoBuf(GcellularMessageTypes.GCELL); primaryCell.setInt(GCell.LAC, lac);/*from w ww . ja v a2 s.c om*/ primaryCell.setInt(GCell.CELLID, cid); primaryCell.setInt(GCell.MCC, mcc); primaryCell.setInt(GCell.MNC, mnc); cellularProfile.setProtoBuf(GCellularProfile.PRIMARY_CELL, primaryCell); return cellularProfile; }