The length operator # can be used to get the Buffer size
Buffer.size read/write property
The Buffer.size property get or set the current Buffer byte size. The property permits to extend or shrink the Buffer.
Example
-- init a Buffer with a size of 4 zero-bytes
local b = sys.Buffer(4)
-- outputs "4"
print(b.size)
-- pack 3 integers (4 bytes each) in the buffer, and resize it automagically
b:pack("I4I4I4", 0x1111, 0x2222, 0x3333)
-- outputs "12"
print(b.size)