# [−][src]Struct mynewt::encoding::coap_context::CoapContext

    pub struct CoapContext {
        key_buffer: [u8; 32],
        value_buffer: [u8; 32],
    }

CoAP encoder state. Buffers the next key and value to be encoded.

## Fields

`key_buffer: [u8; 32]`

Static buffer for the key to be encoded. Will be passed to Mynewt COAP encoder API. Always null-terminated.

`value_buffer: [u8; 32]`

Static buffer for the string value to be encoded. Will be passed to Mynewt COAP encoder API. Always null-terminated.

## Methods

### `impl CoapContext`[src]

#### `pub fn json_set_text_string(&mut self, key: &Strn, value: &Strn)`[src]

#### `pub fn key_to_cstr(&mut self, s: &[u8]) -> *const u8`[src]

Given a key `s`, return a `*char` pointer that is null-terminated. Used for encoding COAP keys. If `s` is null-terminated, return it as a pointer. Else copy `s` to the static buffer, append null and return the buffer as a pointer.

#### `pub fn value_to_cstr(&mut self, s: &[u8]) -> *const u8`[src]

Given a value `s`, return a `*char` pointer that is null-terminated. Used for encoding COAP values. If `s` is null-terminated, return it as a pointer. Else copy `s` to the static buffer, append null and return the buffer as a pointer.

#### `pub fn cstr_len(&self, s: &[u8]) -> usize`[src]

Compute the byte length of the string in `s`. If `s` is null-terminated, return length of `s` - 1. Else return length of `s`.

#### `pub fn global_encoder(&self) -> *mut CborEncoder`[src]

Return the global CBOR encoder

#### `pub fn new_encoder(&self, key: &str, suffix: &str) -> *mut CborEncoder`[src]

Create a new CBOR encoder for the current map or array, e.g. `key=root, suffix=_map`

#### `pub fn encoder(&self, key: &str, suffix: &str) -> *mut CborEncoder`[src]

Return the CBOR encoder for the current map or array, e.g. `key=root, suffix=_map`

#### `pub fn check_result(&self, res: u32)`[src]

Fail the encoding with an error if `res` is non-zero.

#### `pub fn fail(&mut self, err: CoapError)`[src]

Fail the encoding with an error

#### `pub fn to_void_ptr(&mut self) -> *mut c_void`[src]

Cast itself as a `*mut c_void`

## Trait Implementations

### `impl Default for CoapContext`[src]

#### `fn default() -> CoapContext`[src]

Returns the "default value" for a type. Read more

## Auto Trait Implementations

### `impl Send for CoapContext`

### `impl Sync for CoapContext`

## Blanket Implementations

### `impl<T, U> TryFrom<U> for T where
U: Into<T>,` [src]

#### `type Error = Infallible`

The type returned in the event of a conversion error.

#### `fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>`[src]

Performs the conversion.

### `impl<T> From<T> for T`[src]

#### `fn from(t: T) -> T`[src]

Performs the conversion.

### `impl<T, U> Into<U> for T where
U: From<T>,` [src]

#### `fn into(self) -> U`[src]

Performs the conversion.

### `impl<T, U> TryInto<U> for T where
U: TryFrom<T>,` [src]

#### `type Error = <U as TryFrom<T>>::Error`

The type returned in the event of a conversion error.

#### `fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>`[src]

Performs the conversion.

### `impl<T> Borrow<T> for T where
T: ?Sized,` [src]

#### `fn borrow(&self) -> &T`[src]

Immutably borrows from an owned value. Read more

### `impl<T> BorrowMut<T> for T where
T: ?Sized,` [src]

#### `fn borrow_mut(&mut self) -> &mut T`[src]

Mutably borrows from an owned value. Read more

### `impl<T> Any for T where
T: 'static + ?Sized,` [src]

#### `fn type_id(&self) -> TypeId`[src]

Gets the `TypeId` of `self`. Read more

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)