NanoMs...Message(3pm)

πŸ’– NanoMsg::Raw::Message β€” the tea β˜•

ok so bestie, welcome to NanoMsg::Raw::Message(3pm) β€” that's the User Contributed Perl Documentation corner of the universe, and today we're talking about the literal message buffer for NanoMsg::Raw. no cap.


✨ NAME ✨

NanoMsg::Raw::Message β€” the message buffer for NanoMsg::Raw. she's the whole moment. πŸ‘‘


🌸 SYNOPSIS 🌸

here's the vibe, fr fr:

use NanoMsg::Raw;

{
    my $msg = nn_allocmsg(3, 0);
    $msg->copy('foo');
    nn_send($sock, $msg);
}

{
    nn_recv($sock, my $buf);
    warn $buf;
}

like... allocate, copy, send, receive, warn. iconic behaviour. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

ok so every instance of this class is a message buffer that nanomsg itself allocated. you don't just ~manifest~ one out of thin air β€” brand-new empty buffers get allocated with nn_allocmsg, periodt.

and it's not just that one function doing the work either. both nn_recv and nn_recvmsg can be used to allocate buffers that come pre-loaded with the contents of a received message. so yeah, receiving is basically just "the universe handed me a buffer, and it's already full." 🎁

NanoMsg::Raw::Messages can be used to send and receive data in a zero-copy fashion β€” meaning no unnecessary duplication of your precious bytes, which is giving efficiency, lowkey main character energy. ✨

when you use a message instance as a string, its overloading kicks in and hands you a string containing a copy of the buffer content. cute, but it's a copy, bestie. πŸ™ˆ

BUT β€” and this is the good part β€” if you want a string that points to the actual buffer content, no copying involved at all, you can get one by dereferencing the message instance as a scalar. chef's kiss. 🫢


πŸ“ copy($data)

$msg->copy('foo');

copies $data to the beginning of the buffer.

⚠️ but listen β€” if the data is larger than the space allocated for the buffer, an exception will be thrown. so if you try to shove more into her than she can hold, she WILL make it everybody's problem. πŸ’€

🌈 SEE ALSO 🌈

  • NanoMsg::Raw β€” go read her too, she's the parent vibe iykyk 🧚

and that's the whole page, bestie!! we ate and left zero crumbs. πŸ’…βœ¨ this was perl v5.42.3 energy, dated 2026-08-19 β€” mwah, go forth and allocate responsibly πŸŽ€πŸ’œπŸŒΈ

πŸ“¦ where this page comes from