code: function serializeInnerMessage(spec, message, buffer, bufferOffset) {
    spec.fields.forEach(function(field) {
      var fieldValue = message[field.name];
  
      if (field.isArray) {
        if (field.arrayLen === null) {
          buffer.writeUInt32LE(fieldValue.length, bufferOffset);
          bufferOffset += 4; // only for variable length arrays
        }
  
        var arrayType = field.baseType;
        fieldValue.forEach(function(value) {
          if (field.isBuiltin) {
            bufferOffset = fieldsUtil.serializePrimitive(
              arrayType, value, buffer, bufferOffset);
          }
          else if (fieldsUtil.isMessage(arrayType)) {
            bufferOffset = serializeInnerMessage(spec.getMsgSpecForType(arrayType), value, buffer, bufferOffset);
          }
        });
      }
      else if (field.isBuiltin) {
        bufferOffset = fieldsUtil.serializePrimitive(
          field.type, fieldValue, buffer, bufferOffset);
      }
      else { // is message
        bufferOffset = serializeInnerMessage(spec.getMsgSpecForType(field.baseType), fieldValue, buffer, bufferOffset);
      }
    });
  
    return bufferOffset;
  }
docs: --------------------------------------------------------- Serialize