本文整理汇总了Java中com.squareup.wire.Message类的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Message类属于com.squareup.wire包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addTenSamples
import com.squareup.wire.Message; //导入依赖的package包/类
@OnClick(R.id.button_add_ten)
void addTenSamples() {
// Create 10 random entries
List<Message> samples = new ArrayList<>();
for (int i = 0; i < 10; ++i) {
samples.add(new Sample.Builder()
.x(++mRunningX)
.y((int) (Math.random() * 1000))
.build());
}
try {
OutputStream outputStream = new BufferedOutputStream(openFileOutput(FILE_NAME, MODE_APPEND));
WireUtils.writeDelimitedTo(outputStream, samples);
outputStream.close();
// OutputStream outputStreamCobs = new BufferedOutputStream(openFileOutput(FILE_NAME_COBS, MODE_APPEND));
// WireUtils.writeCobsEncodedTo(outputStreamCobs, samples);
// outputStreamCobs.close();
} catch (IOException e) {
e.printStackTrace();
}
refreshChart();
}
示例2: sendMessages
import com.squareup.wire.Message; //导入依赖的package包/类
/**
* Get messages from the MessageStore, encode them as a CleartextMessages protobuf
* object, and write that Message out to the output stream.
*/
private void sendMessages() {
List<RangzenMessage> messages = new ArrayList<RangzenMessage>();
for (int k=0; k<NUM_MESSAGES_TO_SEND; k++) {
MessageStore.Message messageFromStore = messageStore.getKthMessage(k);
if (messageFromStore == null) {
break;
}
messages.add(new RangzenMessage.Builder()
.text(messageFromStore.getMessage())
.priority(messageFromStore.getPriority())
.build());
}
CleartextMessages messagesMessage = new CleartextMessages.Builder()
.messages(messages)
.build();
lengthValueWrite(out, messagesMessage);
}
示例3: run
import com.squareup.wire.Message; //导入依赖的package包/类
@Override
public void run() {
try {
while (!Thread.currentThread().isInterrupted() && !closed) {
android.os.Message msg = read();
if (msg != null) {
mainHandler.dispatchMessage(msg);
} else {
mainHandler.dispatchMessage(mainHandler.obtainMessage(MSG_TEARDOWN, "null message"));
break; // if input is empty, do not continue looping
}
}
} catch (IOException e) {
mainHandler.dispatchMessage(mainHandler.obtainMessage(MSG_INPUT_ERROR, e));
}
try {
is.close();
} catch (IOException ignored) {
}
}
示例4: read
import com.squareup.wire.Message; //导入依赖的package包/类
public synchronized android.os.Message read() throws IOException {
ensureVersionRead();
int mcsTag = is.read();
int mcsSize = readVarint();
if (mcsTag < 0 || mcsSize < 0) {
Log.w(TAG, "mcsTag: " + mcsTag + " mcsSize: " + mcsSize);
return null;
}
byte[] bytes = new byte[mcsSize];
int len = 0, read = 0;
while (len < mcsSize && read >= 0) {
len += (read = is.read(bytes, len, mcsSize - len)) < 0 ? 0 : read;
}
Message message = read(mcsTag, bytes, len);
if (message == null) return null;
Log.d(TAG, "Incoming message: " + message);
streamId++;
return mainHandler.obtainMessage(MSG_INPUT, mcsTag, streamId, message);
}
示例5: requestBodyConverter
import com.squareup.wire.Message; //导入依赖的package包/类
@Override
public Converter<?, RequestBody> requestBodyConverter(Type type,
Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
if (!(type instanceof Class<?>)) {
return null;
}
Class<?> c = (Class<?>) type;
if (!Message.class.isAssignableFrom(c)) {
return null;
}
//noinspection unchecked
ProtoAdapter<? extends Message> adapter = ProtoAdapter.get((Class<? extends Message>) c);
return new WireRequestBodyConverter<>(adapter);
}
示例6: responseBodyConverter
import com.squareup.wire.Message; //导入依赖的package包/类
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations,
Retrofit retrofit) {
if (!(type instanceof Class<?>)) {
return null;
}
Class<?> c = (Class<?>) type;
if (!Message.class.isAssignableFrom(c)) {
return null;
}
//noinspection unchecked
ProtoAdapter<? extends Message> adapter = ProtoAdapter.get((Class<? extends Message>) c);
return new WireResponseBodyConverter<>(adapter);
}
示例7: writeDelimitedTo
import com.squareup.wire.Message; //导入依赖的package包/类
public static void writeDelimitedTo(OutputStream outputStream, Message message) throws IOException {
int size = message.adapter().encodedSize(message);
BufferedSink sink = Okio.buffer(Okio.sink(outputStream));
sink.writeIntLe(size);
message.encode(sink);
sink.emit();
}
示例8: readDelimitedFrom
import com.squareup.wire.Message; //导入依赖的package包/类
public static <M extends Message> List<M> readDelimitedFrom(InputStream inputStream, ProtoAdapter<M> adapter) throws IOException {
List<M> messages = new ArrayList<>();
BufferedSource source = Okio.buffer(Okio.source(inputStream));
while (!source.exhausted()) {
int size = source.readIntLe();
byte[] bytes = source.readByteArray(size);
messages.add(adapter.decode(bytes));
}
return messages;
}
示例9: readCobsEncodedFrom
import com.squareup.wire.Message; //导入依赖的package包/类
public static <M extends Message> List<M> readCobsEncodedFrom(InputStream inputStream, ProtoAdapter<M> adapter) throws IOException {
List<M> messages = new ArrayList<>();
BufferedSource source = Okio.buffer(Okio.source(inputStream));
while (!source.exhausted()) {
long length = source.indexOf((byte) 0);
byte[] decodedBytes = CobsUtils.decode(source.readByteArray(length + 1));
messages.add(adapter.decode(decodedBytes));
}
return messages;
}
示例10: for
import com.squareup.wire.Message; //导入依赖的package包/类
/**
* Retrieve at most NUM_MESSAGES_TO_SEND messages from the message store and
* return them. If no messages, returns a empty list.
*
* @return The top NUM_MESSAGES_TO_SEND in the MessageStore.
* @see NUM_MESSAGES_TO_SEND;
*/
/* package */ List<RangzenMessage> getMessages() {
List<RangzenMessage> messages = new ArrayList<RangzenMessage>();
for (int k=0; k<NUM_MESSAGES_TO_SEND; k++) {
MessageStore.Message messageFromStore = messageStore.getKthMessage(k);
if (messageFromStore == null) {
break;
}
messages.add(new RangzenMessage.Builder()
.text(messageFromStore.getMessage())
.priority(messageFromStore.getPriority())
.build());
}
return messages;
}
示例11: lengthValueWrite
import com.squareup.wire.Message; //导入依赖的package包/类
/**
* Send the given message, encoded as length-value, on the given output stream.
*
* TODO(lerner): I don't like the fact that this returns true/false to signal
* success or failure. I'd rather it threw an IOException that has to be handled
* by the calling code. Would prefer to change this in future.
*
* @param outputStream The output stream to write the Message to.
* @param m A message to write.
* @return True if the write succeeds, false otherwise.
*/
public static boolean lengthValueWrite(OutputStream outputStream, Message m) {
if (outputStream == null || m == null) {
return false;
}
try {
byte[] encodedMessage = Exchange.lengthValueEncode(m).array();
outputStream.write(encodedMessage);
return true;
} catch (IOException e) {
Log.e(TAG, "Length/value write failed with exception: " + e);
return false;
}
}
示例12: putExtra
import com.squareup.wire.Message; //导入依赖的package包/类
public static <T extends Message> void putExtra(Intent intent, String key, T[] messages) {
String[] encodedMessages = new String[messages.length];
for (int i = 0; i < messages.length; i++) {
encodedMessages[i] = WireUtil.encodeToString(messages[i]);
}
intent.putExtra(key, encodedMessages);
}
示例13: getMessageArrayExtra
import com.squareup.wire.Message; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <T extends Message> T[] getMessageArrayExtra(Intent intent, String key,
Class<T> messageClass) {
String[] encodedMessages = intent.getStringArrayExtra(key);
T[] messages = (T[]) Array.newInstance(messageClass, encodedMessages.length);
for (int i = 0; i < encodedMessages.length; i++) {
messages[i] = WireUtil.decodeFromString(encodedMessages[i], messageClass);
}
return messages;
}
示例14: decodeFromString
import com.squareup.wire.Message; //导入依赖的package包/类
/**
* Decode a string created with {@link #encodeToString} back to the original message.
*
* Returns null if the string can't be decoded as the given message type.
*/
public static <T extends Message> T decodeFromString(String str, Class<T> protoClass) {
try {
return WIRE.parseFrom(Base64.decode(str, Base64.DEFAULT), protoClass);
} catch (IOException e) {
FWLog.e(e, "Error decoding proto of type %s", protoClass.getSimpleName());
return null;
}
}
示例15: encode
import com.squareup.wire.Message; //导入依赖的package包/类
@Override
protected void encode(ChannelHandlerContext channelHandlerContext, Message message, List<Object> list) throws Exception {
if (message instanceof Envelope) {
list.add(message);
} else {
final Envelope.Builder builder = new Envelope.Builder().origin(origin).timestamp(Time.timestamp());
if (message instanceof ContainerMetric) {
builder.eventType(Envelope.EventType.ContainerMetric).containerMetric((ContainerMetric) message);
} else if (message instanceof CounterEvent) {
builder.eventType(Envelope.EventType.CounterEvent).counterEvent((CounterEvent) message);
} else if (message instanceof Error) {
builder.eventType(Envelope.EventType.Error).error((Error) message);
} else if (message instanceof HttpStart) {
builder.eventType(Envelope.EventType.HttpStart).httpStart((HttpStart) message);
} else if (message instanceof HttpStartStop) {
builder.eventType(Envelope.EventType.HttpStartStop).httpStartStop((HttpStartStop) message);
} else if (message instanceof HttpStop) {
builder.eventType(Envelope.EventType.HttpStop).httpStop((HttpStop) message);
} else if (message instanceof LogMessage) {
builder.eventType(Envelope.EventType.LogMessage).logMessage((LogMessage) message);
} else if (message instanceof ValueMetric) {
builder.eventType(Envelope.EventType.ValueMetric).valueMetric((ValueMetric) message);
} else {
throw new IllegalArgumentException("Unable to encode message of type: " + message.getClass().getName());
}
list.add(builder.build());
}
}