How to store long var into DS1307 nvram?

Hello!
I am working on an application where I have to perform counts of a sensor's pulse. The readings of this sensor, made by an interrupt, are stored in a long var. I need to record permanently this value (in case of power loss), and I thought of using the nvram of the RTC DS1307 using the RTClib. However, this library gives only the possibility of writing bytes or vectors of bytes. Could anyone help?
Would it be the best solution to convert long into bytes and bytes into long, when reeding? How can I do this conversion? Has anyone changed this lib for the purpose I mentioned?

long cnt_absoluto = 0;


void setup() {
  pinMode(sensor_pulsos, INPUT); 
  attachInterrupt(0,contagemRapida,RISING);
  Serial.begin(9600);
}


void loop() {

}


void contagemRapida(){
  cnt_absoluto ++;
  Serial.print(cnt_absoluto); 
  Serial.println();
}

However, this library gives only the possibility of writing bytes or vectors of bytes.

So? A long is simply 4 bytes. Define a union of a long and a 4 byte array. Populate the long; store the array.

Or have a look at bit-shifting.

But before you get that far, have a read about using Serial in an interrupt, and the use of volatile variables.

As Paul said, you can do what you want with a union. Another way is with a cast of the long into bytes for writing and reading with the wire library functions.

Here's some example code.

#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68
#define location 0x08 //DS 1307 storage registers 0x08 to 0x3F

void setup() {
  Wire.begin();
  Serial.begin(9600);
}

void loop() {
  static long cnt_absoluto_in = 0;
  static long cnt_absoluto_out = 0;

  Serial.println("Writing data to DS1307 nvram.");
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(location); //set storage register to begin
  Wire.write((uint8_t*)&cnt_absoluto_in, sizeof(cnt_absoluto_in));//write 4 bytes
  Wire.endTransmission();

  Serial.println("Reading data from DS1307 nvram.");
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(location); //set storage register to begin
  Wire.endTransmission();

  Wire.requestFrom(DS1307_I2C_ADDRESS, sizeof(cnt_absoluto_out));
  Wire.readBytes((uint8_t*)&cnt_absoluto_out, sizeof(cnt_absoluto_out)); //read 4 bytes
  Wire.endTransmission();

  Serial.println(cnt_absoluto_out);
  cnt_absoluto_in += 5;
  delay(500);

}