[libcamera-devel,25/31] libcamera: control_serializer: Simplify serialization of ControlValue

Message ID 20200229164254.23604-26-laurent.pinchart@ideasonboard.com
State Superseded
Headers show
Series
  • libcamera: Add support for array controls
Related show

Commit Message

Laurent Pinchart Feb. 29, 2020, 4:42 p.m. UTC
Use the ControlValue::data() function to access raw data stored in the
control value and simplify serialization.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/libcamera/control_serializer.cpp | 35 +---------------------------
 1 file changed, 1 insertion(+), 34 deletions(-)

Comments

Kieran Bingham March 5, 2020, 4:45 p.m. UTC | #1
On 29/02/2020 16:42, Laurent Pinchart wrote:
> Use the ControlValue::data() function to access raw data stored in the
> control value and simplify serialization.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

That poor overworked buffer.write() call ;)

Reviewed-by: Kieran Bingham <kieran.binghm@ideasonboard.com>

> ---
>  src/libcamera/control_serializer.cpp | 35 +---------------------------
>  1 file changed, 1 insertion(+), 34 deletions(-)
> 
> diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp
> index 5537c5466025..dc87b96f384b 100644
> --- a/src/libcamera/control_serializer.cpp
> +++ b/src/libcamera/control_serializer.cpp
> @@ -146,40 +146,7 @@ size_t ControlSerializer::binarySize(const ControlList &list)
>  void ControlSerializer::store(const ControlValue &value,
>  			      ByteStreamBuffer &buffer)
>  {
> -	switch (value.type()) {
> -	case ControlTypeBool: {
> -		bool data = value.get<bool>();
> -		buffer.write(&data);
> -		break;
> -	}
> -
> -	case ControlTypeInteger8: {
> -		int8_t data = value.get<int8_t>();
> -		buffer.write(&data);
> -		break;
> -	}
> -
> -	case ControlTypeInteger32: {
> -		int32_t data = value.get<int32_t>();
> -		buffer.write(&data);
> -		break;
> -	}
> -
> -	case ControlTypeInteger64: {
> -		uint64_t data = value.get<int64_t>();
> -		buffer.write(&data);
> -		break;
> -	}
> -
> -	case ControlTypeFloat: {
> -		float data = value.get<float>();
> -		buffer.write(&data);
> -		break;
> -	}
> -
> -	default:
> -		break;
> -	}
> +	buffer.write(value.data());

What?

One poor overworked line expected to do all the work of 34? ;-)


>  }
>  
>  void ControlSerializer::store(const ControlRange &range,
>

Patch

diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp
index 5537c5466025..dc87b96f384b 100644
--- a/src/libcamera/control_serializer.cpp
+++ b/src/libcamera/control_serializer.cpp
@@ -146,40 +146,7 @@  size_t ControlSerializer::binarySize(const ControlList &list)
 void ControlSerializer::store(const ControlValue &value,
 			      ByteStreamBuffer &buffer)
 {
-	switch (value.type()) {
-	case ControlTypeBool: {
-		bool data = value.get<bool>();
-		buffer.write(&data);
-		break;
-	}
-
-	case ControlTypeInteger8: {
-		int8_t data = value.get<int8_t>();
-		buffer.write(&data);
-		break;
-	}
-
-	case ControlTypeInteger32: {
-		int32_t data = value.get<int32_t>();
-		buffer.write(&data);
-		break;
-	}
-
-	case ControlTypeInteger64: {
-		uint64_t data = value.get<int64_t>();
-		buffer.write(&data);
-		break;
-	}
-
-	case ControlTypeFloat: {
-		float data = value.get<float>();
-		buffer.write(&data);
-		break;
-	}
-
-	default:
-		break;
-	}
+	buffer.write(value.data());
 }
 
 void ControlSerializer::store(const ControlRange &range,