All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xiaomi.infra.galaxy.talos.client.serialization.MessageSerialization Maven / Gradle / Ivy

There is a newer version: 2.6.1.4
Show newest version
/**
 * Copyright 2016, Xiaomi.
 * All rights reserved.
 * Author: [email protected]
 */

package com.xiaomi.infra.galaxy.talos.client.serialization;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

import com.google.common.base.Preconditions;

import com.xiaomi.infra.galaxy.talos.thrift.Message;

public class MessageSerialization  {
  public static void serializeMessage(Message message,
      DataOutputStream dataOutputStream,
      MessageVersion messageVersion) throws IOException {
    MessageSerializationFactory.getMessageSerializer(messageVersion).serialize(message, dataOutputStream);
  }

  public static Message deserializeMessage(DataInputStream dataInputStream) throws IOException {
    byte[] header = new byte[MessageSerializer.VERSION_NUMBER_LENGTH];
    dataInputStream.readFully(header);
    MessageVersion messageVersion = MessageSerializer.decodeMessageVersionNumber(header);

    return MessageSerializationFactory.getMessageSerializer(messageVersion)
        .deserialize(header, dataInputStream);
  }

  public static int getMessageSize(Message message, MessageVersion messageVersion) {
    return MessageSerializationFactory.getMessageSerializer(messageVersion).getMessageSize(message);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy