Serializes the 'type' byte followed by the message itself.
329737
public ByteBuffer toByteBuffer() {
    // Allow room for encoded message, plus the type byte
    ByteBuf buf = Unpooled.buffer(encodedLength() + 1);
    buf.writeByte(type().id);
    encode(buf);
    assert buf.writableBytes() == 0 : "Writable bytes remain: " + buf.writableBytes();
    return buf.nioBuffer();
  }
816732
private static String serializedGraphForMessage(final Message message, final Resource subject) throws IOException {

        // serialize triples
        final ByteArrayOutputStream serializedGraph = new ByteArrayOutputStream();
        final Model model = createDefaultModel();

        // get info from jms message headers
        @SuppressWarnings("unchecked")
        final List<String> eventType = message.getHeader(FCREPO_EVENT_TYPE, emptyList(), List.class);
        final String dateTime = message.getHeader(FCREPO_DATE_TIME, EMPTY_STRING, String.class);
        @SuppressWarnings("unchecked")
        final List<String> agents = message.getHeader(FCREPO_AGENT, emptyList(), List.class);
        @SuppressWarnings("unchecked")
        final List<String> resourceTypes = message.getHeader(FCREPO_RESOURCE_TYPE, emptyList(), List.class);
        final String identifier = message.getHeader(FCREPO_URI, EMPTY_STRING, String.class);
        final Optional<String> premisType = getAuditEventType(eventType, resourceTypes);

        model.add( model.createStatement(subject, type, INTERNAL_EVENT) );
        model.add( model.createStatement(subject, type, PREMIS_EVENT) );
        model.add( model.createStatement(subject, type, PROV_EVENT) );

        // basic event info
        model.add( model.createStatement(subject, PREMIS_TIME, createTypedLiteral(dateTime, XSDdateTime)) );
        model.add( model.createStatement(subject, PREMIS_OBJ, createResource(identifier)) );

        agents.forEach(agent -> {
            model.add( model.createStatement(subject, PREMIS_AGENT, createTypedLiteral(agent, XSDstring)) );
        });

        premisType.ifPresent(rdfType -> {
            model.add(model.createStatement(subject, PREMIS_TYPE, createResource(rdfType)));
        });

        write(serializedGraph, model, NTRIPLES);
        return serializedGraph.toString("UTF-8");
    }
1033951
def serialize(self):
        

        self.data = bytearray()
        r = self.protocols[::-1]
        for i, p in enumerate(r):
            if isinstance(p, packet_base.PacketBase):
                if i == len(r) - 1:
                    prev = None
                else:
                    prev = r[i + 1]
                data = p.serialize(self.data, prev)
            else:
                data = six.binary_type(p)
            self.data = bytearray(data + self.data)
255260
public static String msgType2String(int type) {
        switch (type) {
            case AbstractMessage.CONNECT: return "CONNECT";
            case AbstractMessage.CONNACK: return "CONNACK";
            case AbstractMessage.PUBLISH: return "PUBLISH";
            case AbstractMessage.PUBACK: return "PUBACK";
            case AbstractMessage.PUBREC: return "PUBREC";
            case AbstractMessage.PUBREL: return "PUBREL";
            case AbstractMessage.PUBCOMP: return "PUBCOMP";
            case AbstractMessage.SUBSCRIBE: return "SUBSCRIBE";
            case AbstractMessage.SUBACK: return "SUBACK";
            case AbstractMessage.UNSUBSCRIBE: return "UNSUBSCRIBE";
            case AbstractMessage.UNSUBACK: return "UNSUBACK";
            case AbstractMessage.PINGREQ: return "PINGREQ";
            case AbstractMessage.PINGRESP: return "PINGRESP";
            case AbstractMessage.DISCONNECT: return "DISCONNECT";
            default: throw  new RuntimeException("Can't decode message type " + type);
        }
    }
606026
public static void serializeTo( AbstractPacket packet , RawDataBuffer out )
    {
        out.writeByte(packet.getType());
        packet.serializeTo(out);
    }
988496
protected byte[] serialize(IMessage<ID, DATA> msg) {
        return msg != null ? SerializationUtils.toByteArray(msg) : null;
    }
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());
  }
658548
def wrap_message(msg, type)
      # Wrap it in an envelope
      outer = OuterMessage.new
      outer.protocol_version = 1
      outer.status  = OuterMessage::Status::STATUS_OK
      outer.type    = type
      outer.payload = msg.serialize_to_string

      return outer
    end
240862
def read_message_type(file):
    """"""
    message_byte = file.read(1)
    if message_byte == b'':
        return ConnectionClosed
    message_number = message_byte[0]
    return _message_types.get(message_number, UnknownMessage)
420008
def writeBytes(self, s):
        
        l = len(s)

        if l > 0xffff:
            self.writeType(TYPE_LONGSTRING)
        else:
            self.writeType(TYPE_STRING)

        if l > 0xffff:
            self.stream.write_ulong(l)
        else:
            self.stream.write_ushort(l)

        self.stream.write(s)
573966
private void sendMessage(BeanMessageID type, Message message) {
        Buffer buffer = new Buffer();
        buffer.writeByte((type.getRawValue() >> 8) & 0xff);
        buffer.writeByte(type.getRawValue() & 0xff);
        buffer.write(message.toPayload());
        GattSerialMessage serialMessage = GattSerialMessage.fromPayload(buffer.readByteArray());
        gattClient.getSerialProfile().sendMessage(serialMessage.getBuffer());
    }
951779
async def message(self, msg, msg_type=None):
        
        elem_type = msg_type if msg_type is not None else msg.__class__

        if hasattr(elem_type, 'blob_serialize'):
            msg = elem_type() if msg is None else msg
            return await msg.blob_serialize(self)

        fields = elem_type.f_specs()
        for field in fields:
            await self.message_field(msg=msg, field=field)

        return msg
844525
public static AbstractMessage createInstance( byte type )
    {
        switch (type)
        {
            case EMPTY:  return new EmptyMessageImpl();
            case BYTES:  return new BytesMessageImpl();
            case MAP:    return new MapMessageImpl();
            case OBJECT: return new ObjectMessageImpl();
            case STREAM: return new StreamMessageImpl();
            case TEXT:   return new TextMessageImpl();
                
            default:
                throw new IllegalArgumentException("Unsupported message type : "+type);
        }
    }
542112
def serialiseString(self, s):
        
        if type(s) is unicode:
            s = self.context.getBytesForString(s)

        self.serialiseBytes(s)
1193112
public static function serializeType($type, $value, $byteBuffer)
    {
        if ($type === self::TYPE_STRING) {
            //Writes a UTF8 encoded string prefixed 32bit base 128 variable-length integer.
            $strLength = strlen($value);

            if ($strLength <= 128) {
                $byteBuffer->writeInt8($strLength);
            } elseif ($strLength <= 16511) {
                $strLength = ceil($strLength / 128) * 256
                    + ($strLength - ceil($strLength / 128) * 128);
                $byteBuffer->writeInt16LE($strLength);
            } else {
                $n3 = ceil($strLength / (128 * 128));
                $n2 = ceil(($strLength - $n3 * 128 * 128) / 128);
                $strLength = $n3 * 256 * 256
                    + $n2 * 256
                    + ($strLength - $n3 * 128 * 128 - $n2 * 128);
                $byteBuffer->writeInt32LE($strLength);
                if ($strLength <= 16777215) {
                    $byteBuffer->setCurrentOffset($byteBuffer->getCurrentOffset() - 1);
                }
            }
            $byteBuffer->writeVStringLE($value);
        } elseif ($type === self::TYPE_SET_STRING) {
            $byteBuffer->writeInt8(count($value));
            foreach ($value as $string) {
                self::serializeType(self::TYPE_STRING, $string, $byteBuffer);
            }
        } elseif ($type === self::TYPE_INT16) {
            $byteBuffer->writeInt16LE($value);
        } elseif ($type === self::TYPE_ASSET) {
            list($amount, $symbol) = explode(' ', $value);

            //TODO FIXME have to be writeInt64
            $byteBuffer->writeInt32LE(str_replace('.', '', $amount));
            $byteBuffer->writeInt32LE(0);

            $dot = strpos($amount, '.');
            $precision = $dot === false ? 0 : strlen($amount) - $dot - 1;
            $byteBuffer->writeInt8($precision);

            $byteBuffer->writeVStringLE(strtoupper($symbol));
            for ($i = 0; $i < 7 - strlen($symbol); $i++) {
                $byteBuffer->writeInt8(0);
            }
        } elseif ($type === self::TYPE_SET_EXTENSIONS) {
            $byteBuffer->writeInt8(count($value));
            foreach ($value as $extension) {
                $byteBuffer->writeInt8($extension[0]);
                if ($extension[0] === 0) {
                    self::serializeType(self::TYPE_SET_BENEFICIARIES, $extension[1], $byteBuffer);
                } else {
                    throw new \Exception("There is no serializer logic for '{$extension[0]}' extension");
                }
            }
        } elseif ($type === self::TYPE_SET_BENEFICIARIES) {
            $byteBuffer->writeInt8(count($value['beneficiaries']));
            foreach ($value['beneficiaries'] as $beneficiary) {
                self::serializeType(self::TYPE_BENEFICIARY, $beneficiary, $byteBuffer);
            }
        } elseif ($type === self::TYPE_BENEFICIARY) {
            self::serializeType(self::TYPE_STRING, $value['account'], $byteBuffer);
            self::serializeType(self::TYPE_INT16, $value['weight'], $byteBuffer);
        } elseif ($type === self::TYPE_INT8) {
            $byteBuffer->writeInt8($value);
        } elseif ($type === self::TYPE_BOOL) {
            self::serializeType(self::TYPE_INT8, $value ? 1 : 0, $byteBuffer);
        }

        return $byteBuffer;
    }
364464
private void writeTypedBytes(final int type, final byte[] data, final int offset, final int length)
    {
        int totalLength = 1 + length;
        if (length < 14)
        {
            buffer.writeUInt8(type | length);
        }
        else
        {
            // need to specify length explicitly
            buffer.writeUInt8(type | 0xE);
            final int sizeLength = buffer.writeVarUInt(length);
            totalLength += sizeLength;
        }
        updateLength(totalLength);
        buffer.writeBytes(data, offset, length);
    }
215737
def serialize_message(self, message: SegmentSequence) -> bytes:
        """"""
        if isinstance(message, FinTS3Segment):
            message = SegmentSequence([message])
        if isinstance(message, (list, tuple, Iterable)):
            message = SegmentSequence(list(message))

        result = []

        for segment in message.segments:
            result.append(self.serialize_segment(segment))

        return self.implode_segments(result)