• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Message类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.squareup.wire.Message的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Message类属于com.squareup.wire包,在下文中一共展示了Message类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
    }
 
开发者ID:sureshjoshi,项目名称:android-streaming-protobuf-example,代码行数:26,代码来源:MainActivity.java


示例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); 
}
 
开发者ID:casific,项目名称:murmur,代码行数:22,代码来源:Exchange.java


示例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) {
    }
}
 
开发者ID:microg,项目名称:android_packages_apps_GmsCore,代码行数:21,代码来源:McsInputStream.java


示例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);
}
 
开发者ID:microg,项目名称:android_packages_apps_GmsCore,代码行数:20,代码来源:McsInputStream.java


示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:WireConverterFactory.java


示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:WireConverterFactory.java


示例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();
}
 
开发者ID:sureshjoshi,项目名称:android-streaming-protobuf-example,代码行数:8,代码来源:WireUtils.java


示例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;
}
 
开发者ID:sureshjoshi,项目名称:android-streaming-protobuf-example,代码行数:11,代码来源:WireUtils.java


示例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;
}
 
开发者ID:sureshjoshi,项目名称:android-streaming-protobuf-example,代码行数:11,代码来源:WireUtils.java


示例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;
}
 
开发者ID:casific,项目名称:murmur,代码行数:22,代码来源:Exchange.java


示例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;
  }
}
 
开发者ID:casific,项目名称:murmur,代码行数:25,代码来源:Exchange.java


示例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);
}
 
开发者ID:jpd236,项目名称:fantasywear,代码行数:8,代码来源:IntentExtraUtils.java


示例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;
}
 
开发者ID:jpd236,项目名称:fantasywear,代码行数:11,代码来源:IntentExtraUtils.java


示例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;
    }
}
 
开发者ID:jpd236,项目名称:fantasywear,代码行数:14,代码来源:WireUtil.java


示例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());
	}
}
 
开发者ID:cloudfoundry-community,项目名称:snotel,代码行数:30,代码来源:EventWrapperEncoder.java


示例16: fromResponseBody

import com.squareup.wire.Message; //导入依赖的package包/类
@Override
public Converter<ResponseData, ?> fromResponseBody(Type type, Annotation[] annotations) {
    if (!(type instanceof Class<?>)) {
        return null;
    }
    Class<?> c = (Class<?>) type;
    if (!Message.class.isAssignableFrom(c)) {
        return null;
    }
    //noinspection unchecked
    return new WireResponseBodyConverter<>(wire, (Class<? extends Message>) c);
}
 
开发者ID:ayvazj,项目名称:retrotooth,代码行数:13,代码来源:WireConverterFactory.java


示例17: toRequestBody

import com.squareup.wire.Message; //导入依赖的package包/类
@Override
public Converter<?, RequestData> toRequestBody(Type type, Annotation[] annotations) {
    if (!(type instanceof Class<?>)) {
        return null;
    }
    if (!Message.class.isAssignableFrom((Class<?>) type)) {
        return null;
    }
    return new WireRequestBodyConverter<>();
}
 
开发者ID:ayvazj,项目名称:retrotooth,代码行数:11,代码来源:WireConverterFactory.java


示例18: toProtobufList

import com.squareup.wire.Message; //导入依赖的package包/类
public static <T extends Message, S extends GenericTimestampRecord> List<T> toProtobufList(
        List<S> list, Class<T> clazz) {
    List<T> results = new ArrayList<>();
    if (list == null) {
        return new ArrayList<>();
    }
    for (GenericTimestampRecord record : list) {
        results.add(clazz.cast(record.toProtobuf()));
    }
    return results;
}
 
开发者ID:nightscout,项目名称:lasso,代码行数:12,代码来源:GenericTimestampRecord.java


示例19: filterRecords

import com.squareup.wire.Message; //导入依赖的package包/类
public static <T extends Message> List<T> filterRecords(int numRecords, List<T> records) {
    int recordIndexToStop = Math.max(records.size() - numRecords, 0);
    List<T> results = new ArrayList<>();
    for (int i = records.size(); i > recordIndexToStop; i--) {
        results.add(records.get(i - 1));
    }
    return results;
}
 
开发者ID:nightscout,项目名称:lasso,代码行数:9,代码来源:Utils.java


示例20: filterRecords

import com.squareup.wire.Message; //导入依赖的package包/类
private <T extends Message> List<T> filterRecords(int numRecords, List<T> records) {
    int recordIndexToStop = Math.max(records.size() - numRecords, 0);
    List<T> results = new ArrayList<>();
    for (int i = records.size(); i > recordIndexToStop; i--) {
        results.add(records.get(i - 1));
    }
    return results;
}
 
开发者ID:nightscout,项目名称:android-uploader,代码行数:9,代码来源:Uploader.java



注:本文中的com.squareup.wire.Message类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MushroomCow类代码示例发布时间:2022-05-21
下一篇:
Java SuperCsvCellProcessorException类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap