diff --git a/bacnet-stack/include/bacstr.h b/bacnet-stack/include/bacstr.h index 4ab7fc0c..77732fe7 100644 --- a/bacnet-stack/include/bacstr.h +++ b/bacnet-stack/include/bacstr.h @@ -165,6 +165,10 @@ extern "C" { bool octetstring_copy( BACNET_OCTET_STRING * dest, BACNET_OCTET_STRING * src); + size_t octetstring_copy_value( + uint8_t * dest, + size_t length, + BACNET_OCTET_STRING * src); /* returns false if the string exceeds capacity */ bool octetstring_append( BACNET_OCTET_STRING * octet_string, diff --git a/bacnet-stack/src/bacstr.c b/bacnet-stack/src/bacstr.c index 98d69c28..87e4c544 100644 --- a/bacnet-stack/src/bacstr.c +++ b/bacnet-stack/src/bacstr.c @@ -730,6 +730,28 @@ bool octetstring_copy( octetstring_length(src)); } +/* returns the number of bytes copied, or 0 if the dest + cannot hold entire octetstring value */ +size_t octetstring_copy_value( + uint8_t * dest, + size_t length, + BACNET_OCTET_STRING * src) +{ + size_t bytes_copied = 0; + size_t i; /* counter */ + + if (src && dest) { + if (length <= src->length) { + for (i = 0; i < src->length; i++) { + dest[i]= src->value[i]; + } + bytes_copied = src->length; + } + } + + return bytes_copied; +} + /* returns false if the string exceeds capacity */ bool octetstring_append( BACNET_OCTET_STRING * octet_string,