Search in sources :

Example 6 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project druid by druid-io.

the class ProtoBufInputRowParser method buildStringKeyMap.

private Map<String, Object> buildStringKeyMap(ByteBuffer input) {
    final Descriptors.Descriptor descriptor = getDescriptor(descriptorFileInClasspath);
    final Map<String, Object> theMap = Maps.newHashMap();
    try {
        DynamicMessage message = DynamicMessage.parseFrom(descriptor, ByteString.copyFrom(input));
        Map<Descriptors.FieldDescriptor, Object> allFields = message.getAllFields();
        for (Map.Entry<Descriptors.FieldDescriptor, Object> entry : allFields.entrySet()) {
            String name = entry.getKey().getName();
            if (theMap.containsKey(name)) {
                continue;
            // Perhaps throw an exception here?
            // throw new RuntimeException("dupicate key " + name + " in " + message);
            }
            Object value = entry.getValue();
            if (value instanceof Descriptors.EnumValueDescriptor) {
                Descriptors.EnumValueDescriptor desc = (Descriptors.EnumValueDescriptor) value;
                value = desc.getName();
            }
            theMap.put(name, value);
        }
    } catch (InvalidProtocolBufferException e) {
        log.warn(e, "Problem with protobuf something");
    }
    return theMap;
}
Also used : InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ByteString(com.google.protobuf.ByteString) DynamicMessage(com.google.protobuf.DynamicMessage) Descriptors(com.google.protobuf.Descriptors) Map(java.util.Map)

Example 7 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project MSEC by Tencent.

the class RequestDecoder method deserializeProtobufPackage.

private RpcRequest deserializeProtobufPackage(byte[] headBytes, byte[] bodyBytes) {
    Head.CRpcHead pbHead = null;
    RpcRequest rpcRequest = new RpcRequest();
    try {
        pbHead = Head.CRpcHead.parseFrom(headBytes);
        rpcRequest.setSeq(pbHead.getSequence());
    } catch (InvalidProtocolBufferException e) {
        log.error("Parse protobuf head failed.");
        rpcRequest.setException(new IllegalArgumentException("Parse protobuf head failed."));
        return rpcRequest;
    }
    String serviceMethodName = pbHead.getMethodName().toStringUtf8();
    int pos = serviceMethodName.lastIndexOf('.');
    if (pos == -1 || pos == 0 || pos == serviceMethodName.length() - 1) {
        log.error("Invalid serviceMethodName (" + serviceMethodName + "). Must be in format like *.*");
        rpcRequest.setException(new IllegalArgumentException("Invalid serviceMethodName (" + serviceMethodName + "). Must be in format like *.*"));
        return rpcRequest;
    }
    String serviceName = serviceMethodName.substring(0, pos);
    String methodName = serviceMethodName.substring(pos + 1);
    rpcRequest.setServiceName(serviceName);
    rpcRequest.setMethodName(methodName);
    rpcRequest.setFlowid(pbHead.getFlowId());
    if (pbHead.getCaller() != null && !pbHead.getCaller().isEmpty()) {
        rpcRequest.setFromModule(pbHead.getCaller().toStringUtf8());
    } else {
        rpcRequest.setFromModule("UnknownModule");
    }
    //If flowid == 0, we must generate one
    if (rpcRequest.getFlowid() == 0) {
        rpcRequest.setFlowid(rpcRequest.getSeq() ^ NettyCodecUtils.generateColorId(serviceMethodName));
    }
    AccessMonitor.add("frm.rpc request incoming: " + methodName);
    ServiceFactory.ServiceMethodEntry serviceMethodEntry = ServiceFactory.getServiceMethodEntry(serviceName, methodName);
    if (serviceMethodEntry == null) {
        log.error("No service method registered: " + rpcRequest.getServiceName() + "/" + rpcRequest.getMethodName());
        rpcRequest.setException(new IllegalArgumentException("No service method registered: " + rpcRequest.getServiceName() + "/" + rpcRequest.getMethodName()));
        return rpcRequest;
    }
    MessageLite param = null;
    try {
        param = (MessageLite) serviceMethodEntry.getParamTypeParser().parseFrom(bodyBytes);
    } catch (InvalidProtocolBufferException ex) {
        log.error("Parse protobuf body failed.");
        rpcRequest.setException(new IllegalArgumentException("RParse protobuf body failed." + ex.getMessage()));
        return rpcRequest;
    }
    rpcRequest.setParameter(param);
    log.info("RPC Request received. ServiceMethodName: " + rpcRequest.getServiceName() + "/" + rpcRequest.getMethodName() + "\tSeq: " + rpcRequest.getSeq() + "\tParameter: " + rpcRequest.getParameter());
    return rpcRequest;
}
Also used : Head(srpc.Head) ServiceFactory(org.msec.rpc.ServiceFactory) RpcRequest(org.msec.rpc.RpcRequest) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) MessageLite(com.google.protobuf.MessageLite)

Example 8 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project Signal-Android by WhisperSystems.

the class WebRtcCallService method onMessage.

@Override
public void onMessage(DataChannel.Buffer buffer) {
    Log.w(TAG, "onMessage...");
    try {
        byte[] data = new byte[buffer.data.remaining()];
        buffer.data.get(data);
        Data dataMessage = Data.parseFrom(data);
        if (dataMessage.hasConnected()) {
            Log.w(TAG, "hasConnected...");
            Intent intent = new Intent(this, WebRtcCallService.class);
            intent.setAction(ACTION_CALL_CONNECTED);
            intent.putExtra(EXTRA_CALL_ID, dataMessage.getConnected().getId());
            startService(intent);
        } else if (dataMessage.hasHangup()) {
            Log.w(TAG, "hasHangup...");
            Intent intent = new Intent(this, WebRtcCallService.class);
            intent.setAction(ACTION_REMOTE_HANGUP);
            intent.putExtra(EXTRA_CALL_ID, dataMessage.getHangup().getId());
            startService(intent);
        } else if (dataMessage.hasVideoStreamingStatus()) {
            Log.w(TAG, "hasVideoStreamingStatus...");
            Intent intent = new Intent(this, WebRtcCallService.class);
            intent.setAction(ACTION_REMOTE_VIDEO_MUTE);
            intent.putExtra(EXTRA_CALL_ID, dataMessage.getVideoStreamingStatus().getId());
            intent.putExtra(EXTRA_MUTE, !dataMessage.getVideoStreamingStatus().getEnabled());
            startService(intent);
        }
    } catch (InvalidProtocolBufferException e) {
        Log.w(TAG, e);
    }
}
Also used : InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Data(org.thoughtcrime.securesms.webrtc.WebRtcDataProtos.Data) Intent(android.content.Intent)

Example 9 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project canal by alibaba.

the class AbstractCanalClientTest method printEntry.

protected void printEntry(List<Entry> entrys) {
    for (Entry entry : entrys) {
        long executeTime = entry.getHeader().getExecuteTime();
        long delayTime = new Date().getTime() - executeTime;
        if (entry.getEntryType() == EntryType.TRANSACTIONBEGIN || entry.getEntryType() == EntryType.TRANSACTIONEND) {
            if (entry.getEntryType() == EntryType.TRANSACTIONBEGIN) {
                TransactionBegin begin = null;
                try {
                    begin = TransactionBegin.parseFrom(entry.getStoreValue());
                } catch (InvalidProtocolBufferException e) {
                    throw new RuntimeException("parse event has an error , data:" + entry.toString(), e);
                }
                // 打印事务头信息,执行的线程id,事务耗时
                logger.info(transaction_format, new Object[] { entry.getHeader().getLogfileName(), String.valueOf(entry.getHeader().getLogfileOffset()), String.valueOf(entry.getHeader().getExecuteTime()), String.valueOf(delayTime) });
                logger.info(" BEGIN ----> Thread id: {}", begin.getThreadId());
            } else if (entry.getEntryType() == EntryType.TRANSACTIONEND) {
                TransactionEnd end = null;
                try {
                    end = TransactionEnd.parseFrom(entry.getStoreValue());
                } catch (InvalidProtocolBufferException e) {
                    throw new RuntimeException("parse event has an error , data:" + entry.toString(), e);
                }
                // 打印事务提交信息,事务id
                logger.info("----------------\n");
                logger.info(" END ----> transaction id: {}", end.getTransactionId());
                logger.info(transaction_format, new Object[] { entry.getHeader().getLogfileName(), String.valueOf(entry.getHeader().getLogfileOffset()), String.valueOf(entry.getHeader().getExecuteTime()), String.valueOf(delayTime) });
            }
            continue;
        }
        if (entry.getEntryType() == EntryType.ROWDATA) {
            RowChange rowChage = null;
            try {
                rowChage = RowChange.parseFrom(entry.getStoreValue());
            } catch (Exception e) {
                throw new RuntimeException("parse event has an error , data:" + entry.toString(), e);
            }
            EventType eventType = rowChage.getEventType();
            logger.info(row_format, new Object[] { entry.getHeader().getLogfileName(), String.valueOf(entry.getHeader().getLogfileOffset()), entry.getHeader().getSchemaName(), entry.getHeader().getTableName(), eventType, String.valueOf(entry.getHeader().getExecuteTime()), String.valueOf(delayTime) });
            if (eventType == EventType.QUERY || rowChage.getIsDdl()) {
                logger.info(" sql ----> " + rowChage.getSql() + SEP);
                continue;
            }
            for (RowData rowData : rowChage.getRowDatasList()) {
                if (eventType == EventType.DELETE) {
                    printColumn(rowData.getBeforeColumnsList());
                } else if (eventType == EventType.INSERT) {
                    printColumn(rowData.getAfterColumnsList());
                } else {
                    printColumn(rowData.getAfterColumnsList());
                }
            }
        }
    }
}
Also used : Entry(com.alibaba.otter.canal.protocol.CanalEntry.Entry) RowData(com.alibaba.otter.canal.protocol.CanalEntry.RowData) RowChange(com.alibaba.otter.canal.protocol.CanalEntry.RowChange) EventType(com.alibaba.otter.canal.protocol.CanalEntry.EventType) TransactionBegin(com.alibaba.otter.canal.protocol.CanalEntry.TransactionBegin) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Date(java.util.Date) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) TransactionEnd(com.alibaba.otter.canal.protocol.CanalEntry.TransactionEnd)

Example 10 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project bagheera by mozilla-metrics.

the class KafkaConsumer method poll.

@Override
public void poll() {
    final CountDownLatch latch = new CountDownLatch(streams.size());
    for (final KafkaStream<Message> stream : streams) {
        workers.add(executor.submit(new Callable<Void>() {

            @Override
            public Void call() {
                try {
                    for (MessageAndMetadata<Message> mam : stream) {
                        BagheeraMessage bmsg = BagheeraMessage.parseFrom(ByteString.copyFrom(mam.message().payload()));
                        // get the sink for this message's namespace 
                        // (typically only one sink unless a regex pattern was used to listen to multiple topics)
                        KeyValueSink sink = sinkFactory.getSink(bmsg.getNamespace());
                        if (sink == null) {
                            LOG.error("Could not obtain sink for namespace: " + bmsg.getNamespace());
                            break;
                        }
                        if (bmsg.getOperation() == Operation.CREATE_UPDATE && bmsg.hasId() && bmsg.hasPayload()) {
                            if (validationPipeline == null || validationPipeline.isValid(bmsg.getPayload().toByteArray())) {
                                if (bmsg.hasTimestamp()) {
                                    sink.store(bmsg.getId(), bmsg.getPayload().toByteArray(), bmsg.getTimestamp());
                                } else {
                                    sink.store(bmsg.getId(), bmsg.getPayload().toByteArray());
                                }
                            } else {
                                invalidMessageMeter.mark();
                                // TODO: sample out an example payload
                                LOG.warn("Invalid payload for namespace: " + bmsg.getNamespace());
                            }
                        } else if (bmsg.getOperation() == Operation.DELETE && bmsg.hasId()) {
                            sink.delete(bmsg.getId());
                        }
                        consumed.mark();
                    }
                } catch (InvalidProtocolBufferException e) {
                    LOG.error("Invalid protocol buffer in data stream", e);
                } catch (UnsupportedEncodingException e) {
                    LOG.error("Message ID was not in UTF-8 encoding", e);
                } catch (IOException e) {
                    LOG.error("IO error while storing to data sink", e);
                } finally {
                    latch.countDown();
                }
                return null;
            }
        }));
    }
    // run indefinitely unless we detect that a thread exited
    try {
        while (true) {
            latch.await(10, TimeUnit.SECONDS);
            if (latch.getCount() != streams.size()) {
                // we have a dead thread and should exit
                break;
            }
        }
    } catch (InterruptedException e) {
        LOG.info("Interrupted during polling", e);
    }
    // Spit out errors if there were any
    for (Future<Void> worker : workers) {
        try {
            if (worker.isDone() && !worker.isCancelled()) {
                worker.get(1, TimeUnit.SECONDS);
            }
        } catch (InterruptedException e) {
            LOG.error("Thread was interrupted:", e);
        } catch (ExecutionException e) {
            LOG.error("Exception occured in thread:", e);
        } catch (TimeoutException e) {
            LOG.error("Timed out waiting for thread result:", e);
        } catch (CancellationException e) {
            LOG.error("Thread has been canceled: ", e);
        }
    }
}
Also used : BagheeraMessage(com.mozilla.bagheera.BagheeraProto.BagheeraMessage) Message(kafka.message.Message) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) Callable(java.util.concurrent.Callable) KeyValueSink(com.mozilla.bagheera.sink.KeyValueSink) CancellationException(java.util.concurrent.CancellationException) BagheeraMessage(com.mozilla.bagheera.BagheeraProto.BagheeraMessage) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)87 ServerRequest (com.pokegoapi.main.ServerRequest)42 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)37 ByteString (com.google.protobuf.ByteString)21 IOException (java.io.IOException)12 CodedInputStream (com.google.protobuf.CodedInputStream)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 TypicalData (protos.TypicalData)4 GetPlayerMessage (POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage)3 Item (com.pokegoapi.api.inventory.Item)3 ItemBag (com.pokegoapi.api.inventory.ItemBag)3 TutorialListener (com.pokegoapi.api.listener.TutorialListener)3 BytesWritable (org.apache.hadoop.io.BytesWritable)3 Text (org.apache.hadoop.io.Text)3 FortDeployPokemonMessage (POGOProtos.Networking.Requests.Messages.FortDeployPokemonMessageOuterClass.FortDeployPokemonMessage)2 LevelUpRewardsMessage (POGOProtos.Networking.Requests.Messages.LevelUpRewardsMessageOuterClass.LevelUpRewardsMessage)2 ReleasePokemonMessage (POGOProtos.Networking.Requests.Messages.ReleasePokemonMessageOuterClass.ReleasePokemonMessage)2 UseItemEncounterMessage (POGOProtos.Networking.Requests.Messages.UseItemEncounterMessageOuterClass.UseItemEncounterMessage)2 LevelUpRewardsResponse (POGOProtos.Networking.Responses.LevelUpRewardsResponseOuterClass.LevelUpRewardsResponse)2 UseItemEncounterResponse (POGOProtos.Networking.Responses.UseItemEncounterResponseOuterClass.UseItemEncounterResponse)2