Java Code Examples for com.google.protobuf.MessageLite
The following examples show how to use
com.google.protobuf.MessageLite.
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: android-chromium Author: eduplus File: ClientProtocolAccessor.java License: BSD 2-Clause "Simplified" License | 6 votes |
/** Returns the {@code field} from {@code message}. */ @Override @SuppressWarnings("unchecked") public Object getField(MessageLite rawMessage, Descriptor field) { Preconditions.checkNotNull(rawMessage); Preconditions.checkNotNull(field); InitializeMessage message = (InitializeMessage) rawMessage; if (field == CLIENT_TYPE) { return message.getClientType(); } if (field == NONCE) { return message.getNonce(); } if (field == APPLICATION_CLIENT_ID) { return message.getApplicationClientId(); } if (field == DIGEST_SERIALIZATION_TYPE) { return message.getDigestSerializationType(); } throw new IllegalArgumentException("Bad descriptor: " + field); }
Example #2
Source Project: android-chromium Author: eduplus File: AndroidServiceAccessor.java License: BSD 2-Clause "Simplified" License | 6 votes |
/** Returns whether {@code field} is present in {@code message}. */ @Override @SuppressWarnings("unchecked") public boolean hasField(MessageLite rawMessage, Descriptor field) { Preconditions.checkNotNull(rawMessage); Preconditions.checkNotNull(field); InternalDowncall message = (InternalDowncall) rawMessage; if (field == VERSION) { return message.hasVersion(); } if (field == SERVER_MESSAGE) { return message.hasServerMessage(); } if (field == NETWORK_STATUS) { return message.hasNetworkStatus(); } if (field == NETWORK_ADDR_CHANGE) { return message.hasNetworkAddrChange(); } if (field == CREATE_CLIENT) { return message.hasCreateClient(); } throw new IllegalArgumentException("Bad descriptor: " + field); }
Example #3
Source Project: FoxTelem Author: ac2cz File: SyncMessageSender.java License: GNU General Public License v3.0 | 6 votes |
public void send(XMessage message) { synchronized (this.waitingAsyncOperationMonitor) { MessageLite msg = message.getMessage(); try { int type = MessageConstants.getTypeForMessageClass(msg.getClass()); int size = 1 + msg.getSerializedSize(); if (this.maxAllowedPacket > 0 && size > this.maxAllowedPacket) { throw new CJPacketTooBigException(Messages.getString("PacketTooBigException.1", new Object[] { size, this.maxAllowedPacket })); } // for debugging // System.err.println("Initiating write of message (size=" + size + ", tag=" + ClientMessages.Type.valueOf(type) + ")"); byte[] sizeHeader = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(size).array(); this.outputStream.write(sizeHeader); this.outputStream.write(type); msg.writeTo(this.outputStream); this.outputStream.flush(); this.previousPacketSentTime = this.lastPacketSentTime; this.lastPacketSentTime = System.currentTimeMillis(); } catch (IOException ex) { throw new CJCommunicationsException("Unable to write message", ex); } } }
Example #4
Source Project: android-chromium Author: kevin-smets File: AndroidServiceAccessor.java License: BSD 2-Clause "Simplified" License | 6 votes |
/** Returns the {@code field} from {@code message}. */ @Override @SuppressWarnings("unchecked") public Object getField(MessageLite rawMessage, Descriptor field) { Preconditions.checkNotNull(rawMessage); Preconditions.checkNotNull(field); InternalDowncall message = (InternalDowncall) rawMessage; if (field == VERSION) { return message.getVersion(); } if (field == SERVER_MESSAGE) { return message.getServerMessage(); } if (field == NETWORK_STATUS) { return message.getNetworkStatus(); } if (field == NETWORK_ADDR_CHANGE) { return message.getNetworkAddrChange(); } if (field == CREATE_CLIENT) { return message.getCreateClient(); } throw new IllegalArgumentException("Bad descriptor: " + field); }
Example #5
Source Project: android-chromium Author: eduplus File: AndroidServiceAccessor.java License: BSD 2-Clause "Simplified" License | 6 votes |
/** Returns whether {@code field} is present in {@code message}. */ @Override @SuppressWarnings("unchecked") public boolean hasField(MessageLite rawMessage, Descriptor field) { Preconditions.checkNotNull(rawMessage); Preconditions.checkNotNull(field); CreateClient message = (CreateClient) rawMessage; if (field == CLIENT_TYPE) { return message.hasClientType(); } if (field == CLIENT_NAME) { return message.hasClientName(); } if (field == CLIENT_CONFIG) { return message.hasClientConfig(); } if (field == SKIP_START_FOR_TEST) { return message.hasSkipStartForTest(); } throw new IllegalArgumentException("Bad descriptor: " + field); }
Example #6
Source Project: sctalk Author: ccfish86 File: MyClusterMessageListener.java License: Apache License 2.0 | 6 votes |
/** * @param commandId * @param clusterMessage * @since 1.0 */ private void doGroup(short commandId, MyClusterMessage clusterMessage) { logger.debug("MyClusterMessageListener#doSwitch"); IMHeader header = clusterMessage.getHeader(); try { MessageLite body = clusterMessage.getMessage(); switch (commandId) { case GroupCmdID.CID_GROUP_CHANGE_MEMBER_NOTIFY_VALUE:// todebug groupChangeMemberNotify(header, body); break; default: logger.warn("Unsupport command id {}", commandId); break; } } catch (IOException e) { logger.error("decode failed.", e); } }
Example #7
Source Project: lams Author: lamsfoundation File: SyncMessageSender.java License: GNU General Public License v2.0 | 6 votes |
/** * Send a message. * * @param msg * the message to send * @throws CJCommunicationsException * to wrap any occurring IOException */ public void send(XMessage message) { MessageLite msg = message.getMessage(); try { int type = MessageConstants.getTypeForMessageClass(msg.getClass()); int size = 1 + msg.getSerializedSize(); if (this.maxAllowedPacket > 0 && size > this.maxAllowedPacket) { throw new CJPacketTooBigException(Messages.getString("PacketTooBigException.1", new Object[] { size, this.maxAllowedPacket })); } // for debugging // System.err.println("Initiating write of message (size=" + size + ", tag=" + ClientMessages.Type.valueOf(type) + ")"); byte[] sizeHeader = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(size).array(); this.outputStream.write(sizeHeader); this.outputStream.write(type); msg.writeTo(this.outputStream); this.outputStream.flush(); this.lastPacketSentTime = System.currentTimeMillis(); } catch (IOException ex) { throw new CJCommunicationsException("Unable to write message", ex); } }
Example #8
Source Project: android-chromium Author: eduplus File: ClientProtocolAccessor.java License: BSD 2-Clause "Simplified" License | 6 votes |
/** Returns whether {@code field} is present in {@code message}. */ @Override @SuppressWarnings("unchecked") public boolean hasField(MessageLite rawMessage, Descriptor field) { Preconditions.checkNotNull(rawMessage); Preconditions.checkNotNull(field); InitializeMessage message = (InitializeMessage) rawMessage; if (field == CLIENT_TYPE) { return message.hasClientType(); } if (field == NONCE) { return message.hasNonce(); } if (field == APPLICATION_CLIENT_ID) { return message.hasApplicationClientId(); } if (field == DIGEST_SERIALIZATION_TYPE) { return message.hasDigestSerializationType(); } throw new IllegalArgumentException("Bad descriptor: " + field); }
Example #9
Source Project: dremio-oss Author: dremio File: RpcCompatibilityEncoder.java License: Apache License 2.0 | 6 votes |
@Override protected void encode(ChannelHandlerContext context, OutboundRpcMessage message, List<Object> out) throws Exception { if (message.mode != RpcMode.RESPONSE_FAILURE) { out.add(message); return; } final MessageLite pBody = message.pBody; if (!(pBody instanceof DremioPBError)) { out.add(message); return; } DremioPBError error = (DremioPBError) pBody; DremioPBError newError = ErrorCompatibility.convertIfNecessary(error); out.add(new OutboundRpcMessage(message.mode, message.rpcType, message.coordinationId, newError, message.dBodies)); }
Example #10
Source Project: android-chromium Author: kevin-smets File: ClientProtocolAccessor.java License: BSD 2-Clause "Simplified" License | 6 votes |
/** Returns whether {@code field} is present in {@code message}. */ @Override @SuppressWarnings("unchecked") public boolean hasField(MessageLite rawMessage, Descriptor field) { Preconditions.checkNotNull(rawMessage); Preconditions.checkNotNull(field); ClientVersion message = (ClientVersion) rawMessage; if (field == VERSION) { return message.hasVersion(); } if (field == PLATFORM) { return message.hasPlatform(); } if (field == LANGUAGE) { return message.hasLanguage(); } if (field == APPLICATION_INFO) { return message.hasApplicationInfo(); } throw new IllegalArgumentException("Bad descriptor: " + field); }
Example #11
Source Project: android-chromium Author: kevin-smets File: AndroidServiceAccessor.java License: BSD 2-Clause "Simplified" License | 6 votes |
/** Returns the {@code field} from {@code message}. */ @Override @SuppressWarnings("unchecked") public Object getField(MessageLite rawMessage, Descriptor field) { Preconditions.checkNotNull(rawMessage); Preconditions.checkNotNull(field); AndroidSchedulerEvent message = (AndroidSchedulerEvent) rawMessage; if (field == VERSION) { return message.getVersion(); } if (field == EVENT_NAME) { return message.getEventName(); } if (field == TICL_ID) { return message.getTiclId(); } throw new IllegalArgumentException("Bad descriptor: " + field); }
Example #12
Source Project: xrpc Author: Nordstrom File: ProtoDecoder.java License: Apache License 2.0 | 6 votes |
/** * Decode a ByteBuf body from protobuf format to an object of designated Class type. * * @param body current http request * @param clazz target class for decoding * @return object of type clazz */ @Override @SuppressWarnings("unchecked") public <T> T decode(ByteBuf body, CharSequence contentType, Class<T> clazz) throws IOException { // TODO (AD): given a Content-Type of application/protobuf; proto=org.some.Message, // we currently ignore the 2nd part, but should at least validate it in the future. if (!MessageLite.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException( String.format("%s does not extend from MessageLite", clazz.getName())); } MessageLite message = protoDefaultInstances.get(clazz); Parser<?> parser = message.getParserForType(); try (ByteBufInputStream stream = new ByteBufInputStream(body)) { return (T) parser.parseFrom(stream); } }
Example #13
Source Project: android-chromium Author: eduplus File: ClientProtocolAccessor.java License: BSD 2-Clause "Simplified" License | 5 votes |
/** Returns whether {@code field} is present in {@code message}. */ @Override @SuppressWarnings("unchecked") public boolean hasField(MessageLite rawMessage, Descriptor field) { Preconditions.checkNotNull(rawMessage); Preconditions.checkNotNull(field); RegistrationSyncMessage message = (RegistrationSyncMessage) rawMessage; if (field == SUBTREE) { return message.getSubtreeCount() > 0; } throw new IllegalArgumentException("Bad descriptor: " + field); }
Example #14
Source Project: grpc-nebula-java Author: grpc-nebula File: AbstractInteropTest.java License: Apache License 2.0 | 5 votes |
/** * Poll the next metrics record and check it against the provided information, including the * message sizes. */ private void assertStatsTrace(String method, Status.Code status, Collection<? extends MessageLite> requests, Collection<? extends MessageLite> responses) { assertClientStatsTrace(method, status, requests, responses); assertServerStatsTrace(method, status, requests, responses); }
Example #15
Source Project: grpc-nebula-java Author: grpc-nebula File: AbstractInteropTest.java License: Apache License 2.0 | 5 votes |
private void assertClientStatsTrace(String method, Status.Code code, Collection<? extends MessageLite> requests, Collection<? extends MessageLite> responses) { // Tracer-based stats TestClientStreamTracer tracer = clientStreamTracers.poll(); assertNotNull(tracer); assertTrue(tracer.getOutboundHeaders()); // assertClientStatsTrace() is called right after application receives status, // but streamClosed() may be called slightly later than that. So we need a timeout. try { assertTrue(tracer.await(5, TimeUnit.SECONDS)); } catch (InterruptedException e) { throw new AssertionError(e); } assertEquals(code, tracer.getStatus().getCode()); if (requests != null && responses != null) { checkTracers(tracer, requests, responses); } if (metricsExpected()) { // CensusStreamTracerModule records final status in interceptor, which is guaranteed to be // done before application receives status. MetricsRecord clientStartRecord = clientStatsRecorder.pollRecord(); checkStartTags(clientStartRecord, method); MetricsRecord clientEndRecord = clientStatsRecorder.pollRecord(); checkEndTags(clientEndRecord, method, code); if (requests != null && responses != null) { checkCensus(clientEndRecord, false, requests, responses); } } }
Example #16
Source Project: android-chromium Author: kevin-smets File: ClientProtocolAccessor.java License: BSD 2-Clause "Simplified" License | 5 votes |
/** Returns whether {@code field} is present in {@code message}. */ @Override @SuppressWarnings("unchecked") public boolean hasField(MessageLite rawMessage, Descriptor field) { Preconditions.checkNotNull(rawMessage); Preconditions.checkNotNull(field); RateLimitP message = (RateLimitP) rawMessage; if (field == WINDOW_MS) { return message.hasWindowMs(); } if (field == COUNT) { return message.hasCount(); } throw new IllegalArgumentException("Bad descriptor: " + field); }
Example #17
Source Project: android-chromium Author: eduplus File: AndroidServiceAccessor.java License: BSD 2-Clause "Simplified" License | 5 votes |
/** Returns whether {@code field} is present in {@code message}. */ @Override @SuppressWarnings("unchecked") public boolean hasField(MessageLite rawMessage, Descriptor field) { Preconditions.checkNotNull(rawMessage); Preconditions.checkNotNull(field); RegistrationDowncall message = (RegistrationDowncall) rawMessage; if (field == REGISTRATIONS) { return message.getRegistrationsCount() > 0; } if (field == UNREGISTRATIONS) { return message.getUnregistrationsCount() > 0; } throw new IllegalArgumentException("Bad descriptor: " + field); }
Example #18
Source Project: android-chromium Author: kevin-smets File: ClientProtocolAccessor.java License: BSD 2-Clause "Simplified" License | 5 votes |
/** Returns the {@code field} from {@code message}. */ @Override @SuppressWarnings("unchecked") public Object getField(MessageLite rawMessage, Descriptor field) { Preconditions.checkNotNull(rawMessage); Preconditions.checkNotNull(field); ApplicationClientIdP message = (ApplicationClientIdP) rawMessage; if (field == CLIENT_TYPE) { return message.getClientType(); } if (field == CLIENT_NAME) { return message.getClientName(); } throw new IllegalArgumentException("Bad descriptor: " + field); }
Example #19
Source Project: android-chromium Author: eduplus File: AndroidServiceAccessor.java License: BSD 2-Clause "Simplified" License | 5 votes |
/** Returns whether {@code field} is present in {@code message}. */ @Override @SuppressWarnings("unchecked") public boolean hasField(MessageLite rawMessage, Descriptor field) { Preconditions.checkNotNull(rawMessage); Preconditions.checkNotNull(field); NetworkStatus message = (NetworkStatus) rawMessage; if (field == IS_ONLINE) { return message.hasIsOnline(); } throw new IllegalArgumentException("Bad descriptor: " + field); }
Example #20
Source Project: android-chromium Author: eduplus File: ClientProtocolAccessor.java License: BSD 2-Clause "Simplified" License | 5 votes |
/** Returns the {@code field} from {@code message}. */ @Override @SuppressWarnings("unchecked") public Object getField(MessageLite rawMessage, Descriptor field) { Preconditions.checkNotNull(rawMessage); Preconditions.checkNotNull(field); InfoRequestMessage message = (InfoRequestMessage) rawMessage; if (field == INFO_TYPE) { return message.getInfoTypeList(); } throw new IllegalArgumentException("Bad descriptor: " + field); }
Example #21
Source Project: android-chromium Author: kevin-smets File: ClientProtocolAccessor.java License: BSD 2-Clause "Simplified" License | 5 votes |
/** Returns the {@code field} from {@code message}. */ @Override @SuppressWarnings("unchecked") public Object getField(MessageLite rawMessage, Descriptor field) { Preconditions.checkNotNull(rawMessage); Preconditions.checkNotNull(field); RegistrationSummary message = (RegistrationSummary) rawMessage; if (field == NUM_REGISTRATIONS) { return message.getNumRegistrations(); } if (field == REGISTRATION_DIGEST) { return message.getRegistrationDigest(); } throw new IllegalArgumentException("Bad descriptor: " + field); }
Example #22
Source Project: android-chromium Author: eduplus File: ClientProtocolAccessor.java License: BSD 2-Clause "Simplified" License | 5 votes |
/** Returns the {@code field} from {@code message}. */ @Override @SuppressWarnings("unchecked") public Object getField(MessageLite rawMessage, Descriptor field) { Preconditions.checkNotNull(rawMessage); Preconditions.checkNotNull(field); RegistrationSummary message = (RegistrationSummary) rawMessage; if (field == NUM_REGISTRATIONS) { return message.getNumRegistrations(); } if (field == REGISTRATION_DIGEST) { return message.getRegistrationDigest(); } throw new IllegalArgumentException("Bad descriptor: " + field); }
Example #23
Source Project: android-chromium Author: eduplus File: ClientProtocolAccessor.java License: BSD 2-Clause "Simplified" License | 5 votes |
/** Returns the {@code field} from {@code message}. */ @Override @SuppressWarnings("unchecked") public Object getField(MessageLite rawMessage, Descriptor field) { Preconditions.checkNotNull(rawMessage); Preconditions.checkNotNull(field); Version message = (Version) rawMessage; if (field == MAJOR_VERSION) { return message.getMajorVersion(); } if (field == MINOR_VERSION) { return message.getMinorVersion(); } throw new IllegalArgumentException("Bad descriptor: " + field); }
Example #24
Source Project: grpc-java Author: grpc File: Util.java License: Apache License 2.0 | 5 votes |
/** Assert that two lists of messages are equal, producing a useful message if not. */ public static void assertEquals(List<? extends MessageLite> expected, List<? extends MessageLite> actual) { if (expected == null || actual == null) { Assert.assertEquals(expected, actual); } else if (expected.size() != actual.size()) { Assert.assertEquals(expected, actual); } else { for (int i = 0; i < expected.size(); i++) { assertEquals(expected.get(i), actual.get(i)); } } }
Example #25
Source Project: gameserver Author: wangqi File: ProtobufDecoder.java License: Apache License 2.0 | 5 votes |
/** * Decode the XinqiMessage from byte array. * @param in * @return * @throws InvalidProtocolBufferException */ public static final XinqiMessage decodeXinqiMessage(IoBuffer in) throws InvalidProtocolBufferException { // Make sure all the header bytes are ready. if ( !in.prefixedDataAvailable(HEADER_LENGTH, MAX_LENGTH) ) { return null; } int length = in.getInt() - 6; int type = in.getShort(); XinqiMessage message = new XinqiMessage(); //XinqiMessage message.type = type; message.index = in.getInt(); byte[] array = new byte[length]; in.get(array); if ( logger.isDebugEnabled() ) { logger.debug("length:"+length+", type:"+message.type+", index:"+message.index); } MessageLite request = IdToMessage.idToMessage(message.type); if ( request == null ) { logger.warn("No id found for message type. return empty message. "); return message; } request = request.newBuilderForType().mergeFrom(array).build(); message.payload = request; return message; }
Example #26
Source Project: dremio-oss Author: dremio File: UserRPCServer.java License: Apache License 2.0 | 5 votes |
@Override protected MessageLite getResponseDefaultInstance(int rpcType) throws RpcException { // a user server only expects acknowledgments on messages it creates. switch (rpcType) { case RpcType.ACK_VALUE: return Ack.getDefaultInstance(); default: throw new UnsupportedOperationException(); } }
Example #27
Source Project: esjc Author: msemys File: ReadStreamEventsForwardOperation.java License: MIT License | 5 votes |
@Override protected MessageLite createRequestMessage() { return ReadStreamEvents.newBuilder() .setEventStreamId(stream) .setFromEventNumber(fromEventNumber) .setMaxCount(maxCount) .setResolveLinkTos(resolveLinkTos) .setRequireMaster(requireMaster) .build(); }
Example #28
Source Project: android-chromium Author: kevin-smets File: ClientProtocolAccessor.java License: BSD 2-Clause "Simplified" License | 5 votes |
/** Returns whether {@code field} is present in {@code message}. */ @Override @SuppressWarnings("unchecked") public boolean hasField(MessageLite rawMessage, Descriptor field) { Preconditions.checkNotNull(rawMessage); Preconditions.checkNotNull(field); ObjectIdP message = (ObjectIdP) rawMessage; if (field == SOURCE) { return message.hasSource(); } if (field == NAME) { return message.hasName(); } throw new IllegalArgumentException("Bad descriptor: " + field); }
Example #29
Source Project: android-chromium Author: kevin-smets File: ClientProtocolAccessor.java License: BSD 2-Clause "Simplified" License | 5 votes |
/** Returns whether {@code field} is present in {@code message}. */ @Override @SuppressWarnings("unchecked") public boolean hasField(MessageLite rawMessage, Descriptor field) { Preconditions.checkNotNull(rawMessage); Preconditions.checkNotNull(field); RegistrationSummary message = (RegistrationSummary) rawMessage; if (field == NUM_REGISTRATIONS) { return message.hasNumRegistrations(); } if (field == REGISTRATION_DIGEST) { return message.hasRegistrationDigest(); } throw new IllegalArgumentException("Bad descriptor: " + field); }
Example #30
Source Project: sctalk Author: ccfish86 File: LogAspect.java License: Apache License 2.0 | 5 votes |
@Around("logPointcut()") public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { // LOG.debug("logPointcut " + joinPoint + "\t"); long start = System.currentTimeMillis(); try { logger.debug("[start] {}#{}", joinPoint.getTarget().getClass().getSimpleName(), joinPoint.getSignature().getName()); // 输出参数 Object[] objs = joinPoint.getArgs(); for (Object obj : objs) { if (obj == null) { continue; } if (obj instanceof IMHeader) { IMHeader header = (IMHeader)obj; logger.debug("[param.header] serviceId:{}, commandId:{}", header.getServiceId(), header.getCommandId()); } else if (obj instanceof MessageLite) { logger.trace("[param.body] :{}", obj); } else { logger.debug("[param.other] :{}", obj); } } Object result = joinPoint.proceed(); return result; } catch (Throwable e) { throw e; } finally { long end = System.currentTimeMillis(); logger.debug("[end] {}ms {}#{}", end - start, joinPoint.getTarget().getClass().getSimpleName(), joinPoint.getSignature().getName()); } }