implement mass encode/decode