title: Efficient way of mapping / casting byte array to object
body: <p>I have a list with objects that describe on which offset and length the value is on the byte array, for example I have a object with a property for offset which is 4 and a byte length of 1, so when I receive <code>019 019 016 021 032 024 255 255</code> the value of the object needs to be set to 21.</p>
  
  <p>Anyone have a good solution for doing this on a efficient way?</p>
  
  <p>Sample on how I am doing it right now:</p>
  
  <pre><code> public static void CallBackOnMessage(byte[] msg, int msgLength)
      {
          bool updates = false;
          byte[] Message = msg;
          JArray jso2n = new JArray();
  
          foreach (Tag tag in _tagHandler.tagList)
          {
              if(tag.addressingByteLength == 1)
              {
                  byte value = msg[tag.addressingByte];
                  string tagValue = value.ToString();
  
                  if(tagValue != null)
                  {
                      jso2n.Add(new JObject(
                      new JProperty("meta",
                          new JObject(
                              new JProperty("identifier", tag.id)
                          )
                      ),
                      new JProperty("data",
                          new JObject(
                              new JProperty("value", tagValue)
                          )
                      )));
                      updates = true;
                  }
              }
              else
              {
                  byte[] bytes = new byte[tag.addressingByteLength];
                  Array.Copy(msg, tag.addressingByte, bytes, 0, tag.addressingByteLength);
              }
  
          }
          if (updates)
          {
              var jsonString = jso2n.ToString();
              cocosApi.patch("system", "taglist", null, null, null, JsonConvert.DeserializeObject(jsonString), _deviceID);
          }
      }
  </code></pre>
  
  <p>Thanks</p>