user35534: I know this is simple basic C stuff, but I can't quite figure it out or find a solution when searching and reading.
I have a method I want to call from a library that wants a const char pointer
someclass::send(const char *data)

And the value I want to send is actually an unsigned integer:
enum messageTypeEnum
{
  REGISTER_CLIENT = 0x04,
  CLIENT_REGISTERED,
  UPDATE_CREDENTIALS,
  ADD_BRICK,
  GAME_FRAME,
  ERROR
};

enum clientTypeEnum
{
  GAMEBOARD = 0x01,
  BRICK_CONTROLLER,
  PLAYER_CONTROLLER,
  TOUCH_CONTROLLER
};

uint16_t message = GAMEBOARD;
message <<= 8;
message += REGISTER_CLIENT;

So I want to convert it, but I can't quite figure it out.
I know fundamentally the char pointer is just a pointer to a memory address and that c strings are null terminated, so I should be able to create the pointer, add the enum's underlying bytes to the pointer array, and then add a 0 at the end to terminate it, but I don't know how I would do that exactly.
I tried doing it via casting:
const char *data = (char *)&message;

So here I'm saying (if I'm thinking about it correctly), is:

&message take the memory address of message, our uint16
`(char *) interpret it as a pointer for a character string
const char * store that address in this const pointer

Even typing that out I feel like I'm misunderstanding parts.
This compiles, but it crashes my esp32 and I'm sure it's because I don't have a null terminator at the end, but I'm not sure how to add it (I tried to add it via array index but that failed).
What's the proper way of doing this (I'm sure there's a non-casting way that's probably easier)?
Update
More detail re: PMF and Edgar's comments.
I definitely want to send the binary numbers behind the enums up. I'm building a websocket based interactive project where "controller" websocket clients can drive interactions on "gameboards". Websockets don't have a concept of differentiating between client types (I know socket.io does, but I'm wanting to write it all with regular websockets), so I built a registration system into the server that looks at the first two bytes of an array buffer or blob message to determine the client and message type (it seems overly complicated, but I'm building this to give a talk on binary operations and I'm doing it give functional examples of data parsing).
So yeah, all of that to say I definitely want to send the underlying number values from the enums.
The library I'm using is ArduinoWebsockets and they do have a client method called sendBinary that does have a signature like the Serial.write:

Though when I tried this with a non-null terminated c-string my esp32 crashed. That said, I was fumbling around in the code so it may have been something else that caused the crash.
When I follow the method calls down, the library ultimately uses std::string to pull the data out of the passed in c string and takes in the length (meaning it doesn't need to be null terminated(?)):

So maybe I can use the casting to turn my two byte number into a c string and pass in the length of 16?

user35534: CORRECTED ANSWER
I dug back into my code after a comment from  Edgar and figured out some needed adjustments. My original solution was mostly correct, but there were some inaccuracies that I want to correct so I'm not goofing up anyone else in the future that may find this answer useful.

So I was overthinking things a bit. I still don't know that this is the best way of handling it, but it is working on the client side.
So, c-strings are just arrays of 8bit values with a null terminator at the end.
I want to end up my enum values, and my enums are define with byte enum-bases:
enum messageTypeEnum
{
  REGISTER_CLIENT = 0x04,
  CLIENT_REGISTERED,
  UPDATE_CREDENTIALS,
  ADD_BRICK,
  GAME_FRAME,
  ERROR
};

enum clientTypeEnum
{
  GAMEBOARD = 0x01,
  BRICK_CONTROLLER,
  PLAYER_CONTROLLER,
  TOUCH_CONTROLLER
};

So, to send up my bytes, I can just build a character array, set each byte in little endian order, and manually terminate it:
NOTE: this is the original assembly that was incorrect.
I put the null terminator at the beginning of the buffer thinking "oh, it's little endian so the terminator needs to be at the beginning". Classic sleepy brain mistake :|

void registerAsAGameBoard()
{
  char buffer[3] = {0, GAMEBOARD, REGISTER_CLIENT};
client.sendBinary((const char *)buffer, 3);
}

void registerAsAGameBoard()
{
  char data[3] = {GAMEBOARD, REGISTER_CLIENT, 0};

  const char *buffer = data; 
  size_t size = strlen(buffer);

  client.sendBinary(buffer, size);
}


Now when I call sendBinary with my byte array and the length of the buffer my esp32 doesn't crash (hurray!) and the server receives the buffer correctly!!

I need to make a couple of adjustments on either the client and/or server side to account for the fact that the ESP32 is little endian and the server is already coded to receive payloads in big endian, but that shouldn't be too much of a lift.

35534: <p>I know this is simple basic C stuff, but I can't quite figure it out or find a solution when searching and reading.</p>
<p>I have a method I want to call from a library that wants a const char pointer</p>
<pre><code>someclass::send(const char *data)
</code></pre>
<p>And the value I want to send is actually an unsigned integer:</p>
<pre><code>enum messageTypeEnum
{
  REGISTER_CLIENT = 0x04,
  CLIENT_REGISTERED,
  UPDATE_CREDENTIALS,
  ADD_BRICK,
  GAME_FRAME,
  ERROR
};

enum clientTypeEnum
{
  GAMEBOARD = 0x01,
  BRICK_CONTROLLER,
  PLAYER_CONTROLLER,
  TOUCH_CONTROLLER
};

uint16_t message = GAMEBOARD;
message &lt;&lt;= 8;
message += REGISTER_CLIENT;
</code></pre>
<p>So I want to convert it, but I can't quite figure it out.</p>
<p>I know fundamentally the char pointer is just a pointer to a memory address and that c strings are null terminated, so I should be able to create the pointer, add the enum's underlying bytes to the pointer array, and then add a 0 at the end to terminate it, but I don't know how I would do that exactly.</p>
<p>I tried doing it via casting:</p>
<pre><code>const char *data = (char *)&amp;message;
</code></pre>
<p>So here I'm saying (if I'm thinking about it correctly), is:</p>
<ul>
<li><code>&amp;message</code> take the memory address of <code>message</code>, our uint16</li>
<li>`(char *) interpret it as a pointer for a character string</li>
<li><code>const char *</code> store that address in this const pointer</li>
</ul>
<p>Even typing that out I feel like I'm misunderstanding parts.</p>
<p>This compiles, but it crashes my esp32 and I'm sure it's because I don't have a null terminator at the end, but I'm not sure how to add it (I tried to add it via array index but that failed).</p>
<p>What's the proper way of doing this (I'm sure there's a non-casting way that's probably easier)?</p>
<h1>Update</h1>
<p>More detail re: PMF and Edgar's comments.</p>
<p>I definitely want to send the binary numbers behind the enums up. I'm building a websocket based interactive project where &quot;controller&quot; websocket clients can drive interactions on &quot;gameboards&quot;. Websockets don't have a concept of differentiating between client types (I know socket.io does, but I'm wanting to write it all with regular websockets), so I built a registration system into the server that looks at the first two bytes of an array buffer or blob message to determine the client and message type (it seems overly complicated, but I'm building this to give a talk on binary operations and I'm doing it give functional examples of data parsing).</p>
<p>So yeah, all of that to say I definitely want to send the underlying number values from the enums.</p>
<p>The library I'm using is <a href="https://github.com/gilmaimon/ArduinoWebsockets" rel="nofollow noreferrer">ArduinoWebsockets</a> and they do have a client method called <code>sendBinary</code> that does have a signature like the <code>Serial.write</code>:</p>
<p><a href="https://i.stack.imgur.com/DDJZp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DDJZp.png" alt="sendBinary signature" /></a></p>
<p>Though when I tried this with a non-null terminated c-string my esp32 crashed. That said, I was fumbling around in the code so it may have been something else that caused the crash.</p>
<p>When I follow the method calls down, the library ultimately uses <code>std::string</code> to pull the data out of the passed in c string and takes in the length (meaning it doesn't need to be null terminated(?)):</p>
<p><a href="https://i.stack.imgur.com/rqE5Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rqE5Y.png" alt="enter image description here" /></a></p>
<p>So maybe I can use the casting to turn my two byte number into a c string and pass in the length of 16?</p>
 35534: <h1>CORRECTED ANSWER</h1>
<p>I dug back into my code after a comment from  Edgar and figured out some needed adjustments. My original solution was mostly correct, but there were some inaccuracies that I want to correct so I'm not goofing up anyone else in the future that may find this answer useful.</p>
<hr />
<p>So I was overthinking things a bit. I still don't know that this is the best way of handling it, but it is working on the client side.</p>
<p>So, c-strings are just arrays of 8bit values with a null terminator at the end.</p>
<p>I want to end up my enum values, and my enums are define with byte enum-bases:</p>
<pre><code>enum messageTypeEnum
{
  REGISTER_CLIENT = 0x04,
  CLIENT_REGISTERED,
  UPDATE_CREDENTIALS,
  ADD_BRICK,
  GAME_FRAME,
  ERROR
};

enum clientTypeEnum
{
  GAMEBOARD = 0x01,
  BRICK_CONTROLLER,
  PLAYER_CONTROLLER,
  TOUCH_CONTROLLER
};
</code></pre>
<p>So, to send up my bytes, I can just build a character array, set each byte in little endian order, and manually terminate it:</p>
<p><em>NOTE: this is the original assembly that was incorrect.</em>
I put the null terminator at the beginning of the buffer thinking &quot;oh, it's little endian so the terminator needs to be at the beginning&quot;. Classic sleepy brain mistake :|</p>
<strike>
void registerAsAGameBoard()
{
  char buffer[3] = {0, GAMEBOARD, REGISTER_CLIENT};
<p>client.sendBinary((const char *)buffer, 3);
}
</strike></p>
<pre><code>void registerAsAGameBoard()
{
  char data[3] = {GAMEBOARD, REGISTER_CLIENT, 0};

  const char *buffer = data; 
  size_t size = strlen(buffer);

  client.sendBinary(buffer, size);
}

</code></pre>
<p>Now when I call sendBinary with my byte array and the length of the buffer my esp32 doesn't crash (hurray!) and the server receives the buffer correctly!!</p>
<p><a href="https://i.stack.imgur.com/W0yds.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W0yds.jpg" alt="success!" /></a></p>
<p>I need to make a couple of adjustments on either the client and/or server side to account for the fact that the ESP32 is little endian and the server is already coded to receive payloads in big endian, but that shouldn't be too much of a lift.</p>
