Example usage for com.google.common.io.protocol ProtoBuf ProtoBuf

List of usage examples for com.google.common.io.protocol ProtoBuf ProtoBuf

Introduction

In this page you can find the example usage for com.google.common.io.protocol ProtoBuf ProtoBuf.

Prototype

public ProtoBuf(ProtoBufType type) 

Source Link

Document

Creates a protocol message according to the given description.

Usage

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 www.  j  a  va2s  . c  om*/
        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);// www . j a v a  2 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;
}

From source file:com.codetastrophe.cellfinder.LocationFetcher.java

private ProtoBuf createPlatformProfile() {
    if (mPlatformProfile == null) {
        mPlatformProfile = new ProtoBuf(GlocationMessageTypes.GPLATFORM_PROFILE);
        mPlatformProfile.setString(GPlatformProfile.VERSION, APPLICATION_VERSION);
        mPlatformProfile.setString(GPlatformProfile.PLATFORM, PLATFORM_BUILD);
    }/*from ww w . j  av  a2  s . c  o  m*/

    // Add Locale
    Locale locale = Locale.getDefault();
    if ((locale != null) && (locale.toString() != null)) {
        mPlatformProfile.setString(GPlatformProfile.LOCALE, locale.toString());
    }

    // Add Platform Key
    String platformKey = getPlatformKey();
    if (!TextUtils.isEmpty(platformKey)) {
        mPlatformProfile.setString(GPlatformProfile.PLATFORM_KEY, platformKey);
    }

    // Clear out cellular platform profile
    mPlatformProfile.setProtoBuf(GPlatformProfile.CELLULAR_PLATFORM_PROFILE, null);

    return mPlatformProfile;
}