Serialize a queue message to bytes.

@param queueMsg
@return
@since 0.7.0
480380
protected byte[] serialize(IQueueMessage<ID, DATA> queueMsg) {
        return queueMsg != null ? SerializationUtils.toByteArray(queueMsg) : null;
    }
254858
public JMFMessage copy() {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) JmfTr.entry(this, tc, "copy");
    JMFMessage copy;

    synchronized (getMessageLockArtefact()) {
      if (map == null) {
        // If there is no map, then this is already become just a delegator, so
        // the copy does not need to include the compatibility wrapper.
        copy = ((JMFMessage)encoding).copy();
      }
      else {
        // In the usual case, we maintain a compatibility layer
        copy = new JSCompatibleMessageImpl(this);
      }
    }
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) JmfTr.exit(this, tc, "copy", copy);
    return copy;
  }
603299
def mime_to_bytes(msg, header_len):
    
    fp = BytesIO()
    g = BytesGenerator(fp, maxheaderlen=header_len)
    g.flatten(msg)
    return fp.getvalue()
494324
public BaseMessage getMessageObject()
    {
        if (m_message == null)
        {
            Map<String,Object> properties = new Hashtable<String,Object>();
            m_message = new MapMessage(new BaseMessageHeader(BACKUP_QUEUE_NAME, BACKUP_QUEUE_TYPE, this, null), properties);
        }
        return m_message;
    }
187247
protected boolean putToQueue(IQueueMessage<ID, DATA> msg) {
        try {
            BytesMessage message = getProducerSession().createBytesMessage();
            message.writeBytes(serialize(msg));
            getMessageProducer().send(message);
            return true;
        } catch (Exception e) {
            throw e instanceof QueueException ? (QueueException) e : new QueueException(e);
        }
    }
890578
public static byte[] serialize(Object obj, String errorMessage) {
    try {
      return serialize(obj);
    } catch (IOException e) {
      throw new RuntimeException(errorMessage, e);
    }
  }
224234
public byte[] getMessageBuffer() {
		ByteArrayOutputStream resultByteBuffer = new ByteArrayOutputStream();
		byte[] result;
		resultByteBuffer.write((byte)0x01);
		int messageLength = messagePayload.length + 
				(this.messageClass == SerialMessageClass.SendData && 
				this.messageType == SerialMessageType.Request ? 5 : 3); // calculate and set length
		
		resultByteBuffer.write((byte) messageLength);
		resultByteBuffer.write((byte) messageType.ordinal());
		resultByteBuffer.write((byte) messageClass.getKey());
		
		try {
			resultByteBuffer.write(messagePayload);
		} catch (IOException e) {
			
		}

		// callback ID and transmit options for a Send Data message.
		if (this.messageClass == SerialMessageClass.SendData && this.messageType == SerialMessageType.Request) {
			resultByteBuffer.write(transmitOptions);
			resultByteBuffer.write(callbackId);
		}
		
		resultByteBuffer.write((byte) 0x00);
		result = resultByteBuffer.toByteArray();
		result[result.length - 1] = 0x01;
		result[result.length - 1] = calculateChecksum(result);
		logger.debug("Assembled message buffer = " + SerialMessage.bb2hex(result));
		return result;
	}
149454
public static String csv(String... msgs) {
		StringBuffer buf = new StringBuffer();
		for (String msg : msgs) {
			buf.append(msg);
			buf.append("; ");
		}
		return buf.toString();
	}
903605
private byte[] encode(Message msg, String apiVersion, String kind) {
    // It is unfortunate that we have to include apiVersion and kind,
    // since we should be able to extract it from the Message, but
    // for now at least, those fields are missing from the proto-buffer.
    Unknown u =
        Unknown.newBuilder()
            .setTypeMeta(TypeMeta.newBuilder().setApiVersion(apiVersion).setKind(kind))
            .setRaw(msg.toByteString())
            .build();
    return Bytes.concat(MAGIC, u.toByteArray());
  }
47039
public static Message deserialize(byte[] bytes) throws ServiceLocationException
    {
        try
        {
            int offset = 0;
            byte version = bytes[offset];
            if (version != SLP_VERSION)
                throw new ServiceLocationException("Unsupported SLP version " + version + ", only version " + SLP_VERSION + " is supported", SLPError.VERSION_NOT_SUPPORTED);

            offset += VERSION_BYTES_LENGTH;
            byte messageType = bytes[offset];

            offset += MESSAGE_TYPE_BYTES_LENGTH;
            int length = readInt(bytes, offset, MESSAGE_LENGTH_BYTES_LENGTH);
            if (bytes.length != length)
                throw new ServiceLocationException("Expected message length is " + length + ", got instead " + bytes.length, SLPError.PARSE_ERROR);

            offset += MESSAGE_LENGTH_BYTES_LENGTH;
            int flags = readInt(bytes, offset, FLAGS_BYTES_LENGTH);

            offset += FLAGS_BYTES_LENGTH;
            int extensionOffset = readInt(bytes, offset, EXTENSION_BYTES_LENGTH);

            offset += EXTENSION_BYTES_LENGTH;
            int xid = readInt(bytes, offset, XID_BYTES_LENGTH);

            offset += XID_BYTES_LENGTH;
            int languageLength = readInt(bytes, offset, LANGUAGE_LENGTH_BYTES_LENGTH);

            offset += LANGUAGE_LENGTH_BYTES_LENGTH;
            String language = readString(bytes, offset, languageLength, true);

            Message message = createMessage(messageType);
            message.setOverflow((flags & 0x8000) == 0x8000);
            message.setFresh((flags & 0x4000) == 0x4000);
            message.setMulticast((flags & 0x2000) == 0x2000);
            message.setXID(xid);
            message.setLanguage(language);

            offset += languageLength;
            int bodyLength = extensionOffset == 0 ? length - offset : extensionOffset - offset;
            byte[] bodyBytes = new byte[bodyLength];
            System.arraycopy(bytes, offset, bodyBytes, 0, bodyBytes.length);
            message.deserializeBody(bodyBytes);

            if (extensionOffset > 0)
            {
                byte[] extensionsBytes = new byte[length - extensionOffset];
                System.arraycopy(bytes, extensionOffset, extensionsBytes, 0, extensionsBytes.length);
                message.deserializeExtensions(extensionsBytes, extensionOffset);
            }

            return message;
        }
        catch (IndexOutOfBoundsException x)
        {
            throw new ServiceLocationException(x, SLPError.PARSE_ERROR);
        }
    }
356046
@Override
    public Message createMessage(Session session) throws JMSException {
        Message message = session.createTextMessage(requestMessage);
        if (correlationId != null)
            message.setJMSCorrelationID(correlationId);
        if (replyQueue != null) {
            message.setJMSReplyTo(replyQueue);
        }
        if (delaySeconds >0) {
            ApplicationContext.getJmsProvider().setMessageDelay(null, message, delaySeconds);
        }
        return message;
    }
1166680
public function createMessage($message, $queueId)
    {
        $queueMessage = new QueueMessage();
        $queueMessage->setMessage($message);
        $queueMessage->setQueueId($queueId);
        return $queueMessage;
    }
1176989
function serializeInnerMessage(spec, message, buffer, bufferOffset) {
  spec.fields.forEach(function(field) {
    var fieldValue = message[field.name];

    if (field.isArray) {
      if (field.arrayLen === null) {
        buffer.writeUInt32LE(fieldValue.length, bufferOffset);
        bufferOffset += 4; // only for variable length arrays
      }

      var arrayType = field.baseType;
      fieldValue.forEach(function(value) {
        if (field.isBuiltin) {
          bufferOffset = fieldsUtil.serializePrimitive(
            arrayType, value, buffer, bufferOffset);
        }
        else if (fieldsUtil.isMessage(arrayType)) {
          bufferOffset = serializeInnerMessage(spec.getMsgSpecForType(arrayType), value, buffer, bufferOffset);
        }
      });
    }
    else if (field.isBuiltin) {
      bufferOffset = fieldsUtil.serializePrimitive(
        field.type, fieldValue, buffer, bufferOffset);
    }
    else { // is message
      bufferOffset = serializeInnerMessage(spec.getMsgSpecForType(field.baseType), fieldValue, buffer, bufferOffset);
    }
  });

  return bufferOffset;
}
154948
def SendSerializedMessage(self, message):
        
        try:
            ba = Helper.ToArray(message)
            ba2 = binascii.unhexlify(ba)
            self.bytes_out += len(ba2)
            self.transport.write(ba2)
        except Exception as e:
            logger.debug(f"Could not send serialized message {e}")
572594
public static AbstractMessage makeInternalCopy( Message srcMessage ) throws JMSException
    {
        // Internal type copy
        if (srcMessage instanceof AbstractMessage)
        {
        	AbstractMessage msg = (AbstractMessage)srcMessage;
        	if (msg.isInternalCopy())
        		return msg;
        	
        	AbstractMessage dup = duplicate(srcMessage);
        	dup.setInternalCopy(true);
        	return dup;
        }
        
        AbstractMessage dup = duplicate(srcMessage);
        dup.setInternalCopy(true);
    	return dup;
    }
429353
@Override
    public IQueueMessage<ID, DATA> take() throws QueueException.EphemeralIsFull {
        if (!isEphemeralDisabled()) {
            int ephemeralMaxSize = getEphemeralMaxSize();
            if (ephemeralMaxSize > 0 && ephemeralStorage.size() >= ephemeralMaxSize) {
                throw new QueueException.EphemeralIsFull(ephemeralMaxSize);
            }
        }
        IQueueMessage<ID, DATA> msg = takeFromRingBuffer();
        if (msg != null && !isEphemeralDisabled()) {
            ephemeralStorage.putIfAbsent(msg.getId(), msg);
        }
        return msg;
    }
580364
public byte[] write(final SpecificRecord message, final long sequence) {

    final String classId = getClassId(message.getClass());
    try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {

      LOG.log(Level.FINEST, "Serializing message: {0}", classId);

      final IMessageSerializer serializer = this.nameToSerializerMap.get(classId);
      if (serializer != null) {
        serializer.serialize(outputStream, message, sequence);
      }

      return outputStream.toByteArray();

    } catch (final IOException e) {
      throw new RuntimeException("Failure writing message: " + classId, e);
    }
  }