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

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

Introduction

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

Prototype

public void addProtoBuf(int tag, ProtoBuf value) 

Source Link

Document

Appends the given (repeated) tag with the given group or message value.

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 w  w w  .  ja v  a  2  s.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);
}